From a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83 Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Fri, 17 Apr 2020 13:55:48 +0300 Subject: [PATCH] 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. --- nixos/modules/system/boot/systemd.nix | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index caa3435cfcd..516f8ed7541 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -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, ... }: {