fs: rename "service" option to "unit" option
This commit is contained in:
@@ -3,6 +3,8 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.sane.fs;
|
cfg = config.sane.fs;
|
||||||
|
|
||||||
|
serviceNameFor = path: "ensure-${utils.escapeSystemdPath path}";
|
||||||
|
|
||||||
# sane.fs."<path>" top-level options
|
# sane.fs."<path>" top-level options
|
||||||
fsEntry = types.submodule ({ name, ...}: let
|
fsEntry = types.submodule ({ name, ...}: let
|
||||||
parent = parentDir name;
|
parent = parentDir name;
|
||||||
@@ -19,19 +21,21 @@ let
|
|||||||
};
|
};
|
||||||
depends = mkOption {
|
depends = mkOption {
|
||||||
type = types.listOf types.str;
|
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 = [];
|
default = [];
|
||||||
};
|
};
|
||||||
service = mkOption {
|
unit = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "name of the systemd service which ensures this entry";
|
description = "name of the systemd unit which ensures this entry";
|
||||||
default = "ensure-${utils.escapeSystemdPath name}";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
# we put this here instead of as a `default` to ensure that users who specify additional
|
# 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`).
|
# 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
|
# sane.fs."<path>".dir sub-options
|
||||||
@@ -52,7 +56,7 @@ let
|
|||||||
|
|
||||||
# given a fsEntry definition, output the `config` attrs it generates.
|
# given a fsEntry definition, output the `config` attrs it generates.
|
||||||
mkFsConfig = path: opt: {
|
mkFsConfig = path: opt: {
|
||||||
systemd.services."${opt.service}" = {
|
systemd.services."${serviceNameFor path}" = {
|
||||||
description = "prepare ${path}";
|
description = "prepare ${path}";
|
||||||
script = ensure-dir-script;
|
script = ensure-dir-script;
|
||||||
scriptArgs = "${path} ${opt.dir.user} ${opt.dir.group} ${opt.dir.mode}";
|
scriptArgs = "${path} ${opt.dir.user} ${opt.dir.group} ${opt.dir.mode}";
|
||||||
|
@@ -30,11 +30,6 @@ let
|
|||||||
};
|
};
|
||||||
in lib.mkIf config.sane.impermanence.enable
|
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
|
# declare our backing storage
|
||||||
sane.fs."${store.underlying.path}".dir = {};
|
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
|
# we need the key directory to be created, and the backing directory to exist
|
||||||
after = [
|
after = [
|
||||||
(config.sane.fs."${store.underlying.path}".service + ".service")
|
config.sane.fs."${store.underlying.path}".unit
|
||||||
# TODO: "${parentDir store.device}"
|
# TODO: "${parentDir store.device}"
|
||||||
(config.sane.fs."/mnt/impermanence/crypt".service + ".service")
|
config.sane.fs."/mnt/impermanence/crypt".unit
|
||||||
];
|
];
|
||||||
wants = after;
|
wants = after;
|
||||||
|
|
||||||
@@ -63,7 +58,6 @@ in lib.mkIf config.sane.impermanence.enable
|
|||||||
wantedBy = before;
|
wantedBy = before;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
fileSystems."${store.device}" = {
|
fileSystems."${store.device}" = {
|
||||||
device = store.underlying.path;
|
device = store.underlying.path;
|
||||||
fsType = "fuse.gocryptfs";
|
fsType = "fuse.gocryptfs";
|
||||||
|
@@ -124,11 +124,11 @@ in
|
|||||||
let
|
let
|
||||||
# systemd creates <path>.mount services for every fileSystems entry.
|
# 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.
|
# <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 ];
|
backing-path = concatPaths [ opt.store opt.directory ];
|
||||||
|
|
||||||
dir-service = config.sane.fs."${opt.directory}".service;
|
dir-unit = config.sane.fs."${opt.directory}".unit;
|
||||||
backing-service = config.sane.fs."${backing-path}".service;
|
backing-unit = config.sane.fs."${backing-path}".unit;
|
||||||
# pass through the perm/mode overrides
|
# pass through the perm/mode overrides
|
||||||
dir-opts = {
|
dir-opts = {
|
||||||
user = lib.mkIf (opt.user != null) opt.user;
|
user = lib.mkIf (opt.user != null) opt.user;
|
||||||
@@ -145,17 +145,18 @@ in
|
|||||||
options = [
|
options = [
|
||||||
"bind"
|
"bind"
|
||||||
# "x-systemd.requires=${backing-mount}.mount" # this should be implicit
|
# "x-systemd.requires=${backing-mount}.mount" # this should be implicit
|
||||||
"x-systemd.after=${backing-service}.service"
|
"x-systemd.after=${backing-unit}"
|
||||||
"x-systemd.after=${dir-service}.service"
|
"x-systemd.after=${dir-unit}"
|
||||||
# `wants` doesn't seem to make it to the service file here :-(
|
# `wants` doesn't seem to make it to the service file here :-(
|
||||||
# "x-systemd.wants=${backing-service}"
|
# "x-systemd.wants=${backing-unit}"
|
||||||
# "x-systemd.wants=${dir-service}"
|
# "x-systemd.wants=${dir-unit}"
|
||||||
];
|
];
|
||||||
# fsType = "bind";
|
# fsType = "bind";
|
||||||
noCheck = true;
|
noCheck = true;
|
||||||
};
|
};
|
||||||
systemd.services."${backing-service}".wantedBy = [ "${mount-service}.mount" ];
|
# mounting <opt.directory> must happen after the backing directory is created *and* the mountpt directory is created.
|
||||||
systemd.services."${dir-service}".wantedBy = [ "${mount-service}.mount" ];
|
systemd.units."${backing-unit}".wantedBy = [ mount-unit ];
|
||||||
|
systemd.units."${dir-unit}".wantedBy = [ mount-unit ];
|
||||||
|
|
||||||
};
|
};
|
||||||
cfgs = builtins.map cfgFor ingested-dirs;
|
cfgs = builtins.map cfgFor ingested-dirs;
|
||||||
|
Reference in New Issue
Block a user