systemd: Add prefix to unit script derivations

Add a distinctive `unit-script` prefix to systemd unit scripts to make
them easier to find in the store directory. Do not add this prefix to
actual script file name as it clutters logs.
This commit is contained in:
Kirill Elagin 2020-04-17 13:55:48 +03:00
parent f1a78e1b5e
commit a9e9d37fc8

View File

@ -203,10 +203,20 @@ let
makeJobScript = name: text:
let
scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
out = pkgs.writeShellScriptBin scriptName ''
set -e
${text}
'';
out = pkgs.writeTextFile {
# The derivation name is different from the script file name
# to keep the script file name short to avoid cluttering logs.
name = "unit-script-${scriptName}";
executable = true;
destination = "/bin/${scriptName}";
text = ''
#!${pkgs.runtimeShell} -e
${text}
'';
checkPhase = ''
${pkgs.stdenv.shell} -n "$out/bin/${scriptName}"
'';
};
in "${out}/bin/${scriptName}";
unitConfig = { config, options, ... }: {