WIP: sane.fs: remove wantedBy/wantedBeforeBy options

This commit is contained in:
2024-09-30 09:56:20 +00:00
parent 0c270fe4a3
commit 572dd5854d
2 changed files with 8 additions and 45 deletions

View File

@@ -22,7 +22,6 @@ let
srcRoot = ./.; srcRoot = ./.;
}; };
mountNameFor = path: "${utils.escapeSystemdPath path}.mount";
serviceNameFor = path: "ensure-${utils.escapeSystemdPath path}"; serviceNameFor = path: "ensure-${utils.escapeSystemdPath path}";
# sane.fs."<path>" top-level options # sane.fs."<path>" top-level options
@@ -53,21 +52,6 @@ let
type = types.nullOr (mountEntryFor name); type = types.nullOr (mountEntryFor name);
default = null; default = null;
}; };
wantedBy = mkOption {
type = types.listOf types.str;
default = [];
description = ''
list of units or targets which, when activated, should trigger this fs entry to be created.
'';
};
wantedBeforeBy = mkOption {
type = types.listOf types.str;
default = [];
description = ''
list of units or targets which, when activated, should first start and wait for this fs entry to be created.
if this unit fails, it will not block the targets in this list.
'';
};
}; };
config = let config = let
default-acl = { default-acl = {
@@ -245,9 +229,8 @@ let
# prevent systemd making this unit implicitly dependent on sysinit.target. # prevent systemd making this unit implicitly dependent on sysinit.target.
# see: <https://www.freedesktop.org/software/systemd/man/systemd.special.html> # see: <https://www.freedesktop.org/software/systemd/man/systemd.special.html>
unitConfig.DefaultDependencies = "no"; unitConfig.DefaultDependencies = "no";
# try to create all entries at boot, but don't block on them. blocking can be more targeted, by higher layers, via e.g. `RequiresMountsFor`
before = opt.wantedBeforeBy; wantedBy = [ "default.target" ];
wantedBy = opt.wantedBy ++ opt.wantedBeforeBy;
}; };
}; };
@@ -266,17 +249,16 @@ let
device = ifBind opt.mount.bind; device = ifBind opt.mount.bind;
options = (lib.optionals isBind [ "bind" ]) options = (lib.optionals isBind [ "bind" ])
++ [ ++ [
# disable defaults: don't require this to be mount as part of local-fs.target # noauto: removes implicit `WantedBy=local-fs.target`
# we'll handle that stuff precisely. # nofail: removes implicit `Before=local-fs.target`
"noauto" # because e.g. private data may not be available before local-fs
# "noauto"
"nofail" "nofail"
# x-systemd options documented here: # x-systemd options documented here:
# - <https://www.freedesktop.org/software/systemd/man/systemd.mount.html> # - <https://www.freedesktop.org/software/systemd/man/systemd.mount.html>
] ]
++ (builtins.map (unit: "x-systemd.after=${unit}") requires) ++ (builtins.map (unit: "x-systemd.after=${unit}") requires)
++ (builtins.map (unit: "x-systemd.requires=${unit}") requires) ++ (builtins.map (unit: "x-systemd.requires=${unit}") requires);
++ (builtins.map (unit: "x-systemd.before=${unit}") opt.wantedBeforeBy)
++ (builtins.map (unit: "x-systemd.wanted-by=${unit}") (opt.wantedBy ++ opt.wantedBeforeBy));
noCheck = ifBind true; noCheck = ifBind true;
}; };
systemd.mounts = [{ systemd.mounts = [{
@@ -286,8 +268,6 @@ let
options = lib.concatStringsSep "," fsEntry.options; options = lib.concatStringsSep "," fsEntry.options;
after = requires; after = requires;
requires = requires; requires = requires;
before = opt.wantedBeforeBy;
wantedBy = opt.wantedBeforeBy;
inherit (opt.mount) mountConfig unitConfig; inherit (opt.mount) mountConfig unitConfig;
}]; }];
}; };

View File

@@ -46,21 +46,6 @@ let
preferred way to link items from the store into the fs preferred way to link items from the store into the fs
''; '';
}; };
defaultOrdering.wantedBeforeBy = mkOption {
type = types.listOf types.str;
default = [ "local-fs.target" ];
description = ''
list of units or targets which would prefer that everything in this store
be initialized before they run, but failing to do so should not error the items in this list.
'';
};
defaultOrdering.wantedBy = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
list of units or targets which, upon activation, should activate all units in this store.
'';
};
}; };
}; };
@@ -217,9 +202,7 @@ in
in lib.mkMerge [ in lib.mkMerge [
{ {
# create destination dir, with correct perms # create destination dir, with correct perms
sane.fs."${fspath}" = { sane.fs."${fspath}" = (lib.optionalAttrs (method == "bind") {
inherit (store.defaultOrdering) wantedBy wantedBeforeBy;
} // (lib.optionalAttrs (method == "bind") {
# inherit perms & make sure we don't mount until after the mount point is setup correctly. # inherit perms & make sure we don't mount until after the mount point is setup correctly.
dir.acl = opt.acl; dir.acl = opt.acl;
mount.bind = fsPathToBackingPath fspath; mount.bind = fsPathToBackingPath fspath;