fs: avoid creating a new script for every fs entry

This commit is contained in:
2023-07-08 09:00:49 +00:00
parent 43aadef3b3
commit f18d624fd9

View File

@@ -183,13 +183,19 @@ let
mkGeneratedConfig = path: opt: let mkGeneratedConfig = path: opt: let
gen-opt = opt.generated; gen-opt = opt.generated;
wrapper = generateWrapperScript path gen-opt; wrapper = generateWrapperScript path gen-opt;
ty =
if (opt.dir != null) then "dir"
else if (opt.symlink != null) then "symlink"
else "custom";
wrapperPath = pkgs.writeShellScript "sane-fs-ensure-${ty}" wrapper.script;
in { in {
systemd.services."${serviceNameFor path}" = { systemd.services."${serviceNameFor path}" = {
description = "prepare ${path}"; description = "prepare ${path}";
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
script = wrapper.script; serviceConfig.ExecStart = escapeShellArgs (
scriptArgs = escapeShellArgs wrapper.scriptArgs; [ "${wrapperPath}" ] ++ wrapper.scriptArgs
);
after = gen-opt.depends; after = gen-opt.depends;
wants = gen-opt.depends; wants = gen-opt.depends;
@@ -242,6 +248,8 @@ let
generateWrapperScript = path: gen-opt: { generateWrapperScript = path: gen-opt: {
script = '' script = ''
set -e
fspath="$1" fspath="$1"
acluser="$2" acluser="$2"
aclgroup="$3" aclgroup="$3"