nixos/systemd: allow using writeShellApplication for systemd unit scripts
This commit is contained in:
@@ -386,18 +386,27 @@ in rec {
|
||||
''}
|
||||
''; # */
|
||||
|
||||
makeJobScript = name: text:
|
||||
makeJobScript = { name, text, enableStrictShellChecks }:
|
||||
let
|
||||
scriptName = replaceStrings [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
|
||||
out = (pkgs.writeShellScriptBin scriptName ''
|
||||
set -e
|
||||
${text}
|
||||
'').overrideAttrs (_: {
|
||||
out = (
|
||||
if ! enableStrictShellChecks then
|
||||
pkgs.writeShellScriptBin scriptName ''
|
||||
set -e
|
||||
|
||||
${text}
|
||||
''
|
||||
else
|
||||
pkgs.writeShellApplication {
|
||||
name = scriptName;
|
||||
inherit text;
|
||||
}
|
||||
).overrideAttrs (_: {
|
||||
# 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}";
|
||||
});
|
||||
in "${out}/bin/${scriptName}";
|
||||
in lib.getExe out;
|
||||
|
||||
unitConfig = { config, name, options, ... }: {
|
||||
config = {
|
||||
@@ -448,10 +457,16 @@ in rec {
|
||||
};
|
||||
};
|
||||
|
||||
serviceConfig = { name, config, ... }: {
|
||||
serviceConfig =
|
||||
let
|
||||
nixosConfig = config;
|
||||
in
|
||||
{ name, lib, config, ... }: {
|
||||
config = {
|
||||
name = "${name}.service";
|
||||
environment.PATH = mkIf (config.path != []) "${makeBinPath config.path}:${makeSearchPathOutput "bin" "sbin" config.path}";
|
||||
|
||||
enableStrictShellChecks = lib.mkOptionDefault nixosConfig.systemd.enableStrictShellChecks;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user