about summary refs log tree commit diff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorKirill Elagin <kirelagin@gmail.com>2020-04-17 13:55:48 +0300
committerKirill Elagin <kirelagin@gmail.com>2020-04-17 13:55:48 +0300
commita9e9d37fc8b7df73d68f9ed78f25da15a40a1c83 (patch)
treea7788e4f4f9037df3113e29db3c1221bd0ecf7a8 /nixos/modules/system
parentf1a78e1b5ea83d4875490d823e2ea5903edd282b (diff)
downloadnixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.tar
nixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.tar.gz
nixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.tar.bz2
nixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.tar.lz
nixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.tar.xz
nixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.tar.zst
nixlib-a9e9d37fc8b7df73d68f9ed78f25da15a40a1c83.zip
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.
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/systemd.nix18
1 files changed, 14 insertions, 4 deletions
diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix
index caa3435cfcda..516f8ed75411 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, ... }: {