mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
Merge pull request #85428 from serokell/kirelagin/unit-script-name
systemd: Simplify unit script names
This commit is contained in:
commit
90c0191735
1 changed files with 29 additions and 26 deletions
|
@ -201,8 +201,23 @@ let
|
||||||
];
|
];
|
||||||
|
|
||||||
makeJobScript = name: text:
|
makeJobScript = name: text:
|
||||||
let mkScriptName = s: "unit-script-" + (replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape s) );
|
let
|
||||||
in pkgs.writeTextFile { name = mkScriptName name; executable = true; inherit text; };
|
scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
|
||||||
|
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, ... }: {
|
unitConfig = { config, options, ... }: {
|
||||||
config = {
|
config = {
|
||||||
|
@ -250,40 +265,28 @@ let
|
||||||
environment.PATH = config.path;
|
environment.PATH = config.path;
|
||||||
}
|
}
|
||||||
(mkIf (config.preStart != "")
|
(mkIf (config.preStart != "")
|
||||||
{ serviceConfig.ExecStartPre = makeJobScript "${name}-pre-start" ''
|
{ serviceConfig.ExecStartPre =
|
||||||
#! ${pkgs.runtimeShell} -e
|
makeJobScript "${name}-pre-start" config.preStart;
|
||||||
${config.preStart}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
(mkIf (config.script != "")
|
(mkIf (config.script != "")
|
||||||
{ serviceConfig.ExecStart = makeJobScript "${name}-start" ''
|
{ serviceConfig.ExecStart =
|
||||||
#! ${pkgs.runtimeShell} -e
|
makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
|
||||||
${config.script}
|
|
||||||
'' + " " + config.scriptArgs;
|
|
||||||
})
|
})
|
||||||
(mkIf (config.postStart != "")
|
(mkIf (config.postStart != "")
|
||||||
{ serviceConfig.ExecStartPost = makeJobScript "${name}-post-start" ''
|
{ serviceConfig.ExecStartPost =
|
||||||
#! ${pkgs.runtimeShell} -e
|
makeJobScript "${name}-post-start" config.postStart;
|
||||||
${config.postStart}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
(mkIf (config.reload != "")
|
(mkIf (config.reload != "")
|
||||||
{ serviceConfig.ExecReload = makeJobScript "${name}-reload" ''
|
{ serviceConfig.ExecReload =
|
||||||
#! ${pkgs.runtimeShell} -e
|
makeJobScript "${name}-reload" config.reload;
|
||||||
${config.reload}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
(mkIf (config.preStop != "")
|
(mkIf (config.preStop != "")
|
||||||
{ serviceConfig.ExecStop = makeJobScript "${name}-pre-stop" ''
|
{ serviceConfig.ExecStop =
|
||||||
#! ${pkgs.runtimeShell} -e
|
makeJobScript "${name}-pre-stop" config.preStop;
|
||||||
${config.preStop}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
(mkIf (config.postStop != "")
|
(mkIf (config.postStop != "")
|
||||||
{ serviceConfig.ExecStopPost = makeJobScript "${name}-post-stop" ''
|
{ serviceConfig.ExecStopPost =
|
||||||
#! ${pkgs.runtimeShell} -e
|
makeJobScript "${name}-post-stop" config.postStop;
|
||||||
${config.postStop}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue