fs: generated.script.scriptArgs -> generated.command

This commit is contained in:
2023-07-08 11:14:55 +00:00
parent 8753e5e0c6
commit db72f5e11f
6 changed files with 18 additions and 39 deletions

View File

@@ -10,7 +10,7 @@ in
sane.user.persist.private = [ ".local/share/keyrings" ];
sane.user.fs."private/.local/share/keyrings/default" = {
generated.script.scriptArgs = [ "${init-keyring}/bin/init-keyring" ];
generated.command = [ "${init-keyring}/bin/init-keyring" ];
# TODO: is this `wantedBy` needed? can we inherit it?
wantedBy = [ config.sane.fs."/home/colin/private".unit ];
wantedBeforeBy = [ ]; # don't created this as part of `multi-user.target`

View File

@@ -37,7 +37,7 @@ in
config = {
sane.fs = mapAttrs (path: c: {
generated.script.scriptArgs = [
generated.command = [
"${hash-path-with-salt}/bin/hash-path-with-salt"
path
];

View File

@@ -15,7 +15,7 @@ in
sane.fs."/var/lib/bluetooth".generated.acl.mode = "0700";
sane.fs."/var/lib/bluetooth/.secrets.stamp" = {
wantedBeforeBy = [ "bluetooth.service" ];
generated.script.scriptArgs = [
generated.command = [
"${install-bluetooth}/bin/install-bluetooth"
"/run/secrets/bt"
""

View File

@@ -12,7 +12,7 @@ in
sane.fs."/var/lib/iwd/.secrets.psk.stamp" = {
wantedBeforeBy = [ "iwd.service" ];
generated.acl.mode = "0600";
generated.script.scriptArgs = [
generated.command = [
"${install-iwd}/bin/install-iwd"
"/run/secrets/net"
"/var/lib/iwd"

View File

@@ -86,9 +86,9 @@ let
];
# actually generate the item
generated.script = lib.mkMerge [
(lib.mkIf (config.dir != null) (ensureDirScript name config.dir))
(lib.mkIf (config.symlink != null) (ensureSymlinkScript name config.symlink))
generated.command = lib.mkMerge [
(lib.mkIf (config.dir != null) [ "${ensure-dir}/bin/ensure-dir" name ])
(lib.mkIf (config.symlink != null) [ "${ensure-symlink}/bin/ensure-symlink" name config.symlink.target ])
];
# make the unit file which generates the underlying thing available so that `mount` can use it.
@@ -156,7 +156,7 @@ let
'';
default = [];
};
script.scriptArgs = mkOption {
command = mkOption {
type = types.listOf types.str;
default = [];
};
@@ -192,7 +192,13 @@ let
mkGeneratedConfig = path: opt: let
gen-opt = opt.generated;
wrapper = generateWrapperScript path gen-opt;
wrappedCommand = [
"${ensure-perms}/bin/ensure-perms"
path
gen-opt.acl.user
gen-opt.acl.group
gen-opt.acl.mode
] ++ gen-opt.command;
in {
systemd.services."${serviceNameFor path}" = {
description = "prepare ${path}";
@@ -200,7 +206,7 @@ let
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true; # makes `systemctl start ensure-blah` a noop if already completed, instead of a restart
ExecStart = escapeShellArgs wrapper.scriptArgs;
ExecStart = escapeShellArgs wrappedCommand;
};
after = gen-opt.depends;
@@ -252,33 +258,6 @@ let
(lib.mkIf (opt.mount != null) (mkMountConfig path opt))
];
generateWrapperScript = path: gen-opt: {
scriptArgs = [
"${ensure-perms}/bin/ensure-perms"
path
gen-opt.acl.user
gen-opt.acl.group
gen-opt.acl.mode
] ++ gen-opt.script.scriptArgs;
};
# systemd/shell script used to create and set perms for a specific dir
ensureDirScript = path: dir-cfg: {
scriptArgs = [
"${ensure-dir}/bin/ensure-dir"
path
];
};
# systemd/shell script used to create a symlink
ensureSymlinkScript = path: link-cfg: {
scriptArgs = [
"${ensure-symlink}/bin/ensure-symlink"
path
link-cfg.target
];
};
# return all ancestors of this path.
# e.g. ancestorsOf "/foo/bar/baz" => [ "/" "/foo" "/foo/bar" ]
ancestorsOf = path: lib.init (path-lib.walk "/" path);

View File

@@ -51,7 +51,7 @@ lib.mkIf config.sane.persist.enable
${pkgs.gocryptfs}/bin/gocryptfs -quiet -passfile "$passfile" -init "$backing"
'';
in {
script.scriptArgs = [ "${script}" underlying key ];
command = [ "${script}" underlying key ];
# we need the key in order to initialize the store
depends = [ config.sane.fs."${key}".unit ];
};
@@ -62,7 +62,7 @@ lib.mkIf config.sane.persist.enable
dd if=/dev/random bs=128 count=1 | base64 --wrap=0 > "$1"
'';
in {
script.scriptArgs = [ "${script}" key ];
command = [ "${script}" key ];
# no need for anyone else to be able to read the key
acl.mode = "0400";
};