fs: rename "service" option to "unit" option

This commit is contained in:
2022-12-31 11:31:16 +00:00
parent be19985440
commit 6ffae00e17
3 changed files with 22 additions and 23 deletions

View File

@@ -3,6 +3,8 @@ with lib;
let
cfg = config.sane.fs;
serviceNameFor = path: "ensure-${utils.escapeSystemdPath path}";
# sane.fs."<path>" top-level options
fsEntry = types.submodule ({ name, ...}: let
parent = parentDir name;
@@ -19,19 +21,21 @@ let
};
depends = mkOption {
type = types.listOf types.str;
description = "list of systemd services needed to be run before this service";
description = "list of systemd units needed to be run before this service";
default = [];
};
service = mkOption {
unit = mkOption {
type = types.str;
description = "name of the systemd service which ensures this entry";
default = "ensure-${utils.escapeSystemdPath name}";
description = "name of the systemd unit which ensures this entry";
};
};
config = {
# we put this here instead of as a `default` to ensure that users who specify additional
# dependencies still get a dep on the parent (unless they assign with `mkForce`).
depends = if has-parent then [ "${parent-cfg.service}.service" ] else [];
depends = if has-parent then [ parent-cfg.unit ] else [];
# this option for the benefit of being read by users (for now).
# making it read-only simplifies our impl.
unit = (serviceNameFor name) + ".service";
};
});
# sane.fs."<path>".dir sub-options
@@ -52,7 +56,7 @@ let
# given a fsEntry definition, output the `config` attrs it generates.
mkFsConfig = path: opt: {
systemd.services."${opt.service}" = {
systemd.services."${serviceNameFor path}" = {
description = "prepare ${path}";
script = ensure-dir-script;
scriptArgs = "${path} ${opt.dir.user} ${opt.dir.group} ${opt.dir.mode}";

View File

@@ -30,11 +30,6 @@ let
};
in lib.mkIf config.sane.impermanence.enable
{
# the crypt store requires keys before being mounted
sane.fs."${store.device}".depends = [
"prepareEncryptedClearedOnBoot.service"
];
# declare our backing storage
sane.fs."${store.underlying.path}".dir = {};
@@ -52,9 +47,9 @@ in lib.mkIf config.sane.impermanence.enable
# we need the key directory to be created, and the backing directory to exist
after = [
(config.sane.fs."${store.underlying.path}".service + ".service")
config.sane.fs."${store.underlying.path}".unit
# TODO: "${parentDir store.device}"
(config.sane.fs."/mnt/impermanence/crypt".service + ".service")
config.sane.fs."/mnt/impermanence/crypt".unit
];
wants = after;
@@ -63,7 +58,6 @@ in lib.mkIf config.sane.impermanence.enable
wantedBy = before;
};
fileSystems."${store.device}" = {
device = store.underlying.path;
fsType = "fuse.gocryptfs";

View File

@@ -124,11 +124,11 @@ in
let
# systemd creates <path>.mount services for every fileSystems entry.
# <path> gets escaped as part of that: this code tries to guess that escaped name here.
mount-service = utils.escapeSystemdPath opt.directory;
mount-unit = "${utils.escapeSystemdPath opt.directory}.mount";
backing-path = concatPaths [ opt.store opt.directory ];
dir-service = config.sane.fs."${opt.directory}".service;
backing-service = config.sane.fs."${backing-path}".service;
dir-unit = config.sane.fs."${opt.directory}".unit;
backing-unit = config.sane.fs."${backing-path}".unit;
# pass through the perm/mode overrides
dir-opts = {
user = lib.mkIf (opt.user != null) opt.user;
@@ -145,17 +145,18 @@ in
options = [
"bind"
# "x-systemd.requires=${backing-mount}.mount" # this should be implicit
"x-systemd.after=${backing-service}.service"
"x-systemd.after=${dir-service}.service"
"x-systemd.after=${backing-unit}"
"x-systemd.after=${dir-unit}"
# `wants` doesn't seem to make it to the service file here :-(
# "x-systemd.wants=${backing-service}"
# "x-systemd.wants=${dir-service}"
# "x-systemd.wants=${backing-unit}"
# "x-systemd.wants=${dir-unit}"
];
# fsType = "bind";
noCheck = true;
};
systemd.services."${backing-service}".wantedBy = [ "${mount-service}.mount" ];
systemd.services."${dir-service}".wantedBy = [ "${mount-service}.mount" ];
# mounting <opt.directory> must happen after the backing directory is created *and* the mountpt directory is created.
systemd.units."${backing-unit}".wantedBy = [ mount-unit ];
systemd.units."${dir-unit}".wantedBy = [ mount-unit ];
};
cfgs = builtins.map cfgFor ingested-dirs;