@@ -201,8 +201,23 @@ let
201201 ];
202202
203203 makeJobScript = name: text:
204− let mkScriptName = s: "unit-script-" + (replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape s) );
205− in pkgs.writeTextFile { name = mkScriptName name; executable = true; inherit text; };
204+ let
205+ scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
206+ out = pkgs.writeTextFile {
207+ # The derivation name is different from the script file name
208+ # to keep the script file name short to avoid cluttering logs.
209+ name = "unit-script-${scriptName}";
210+ executable = true;
211+ destination = "/bin/${scriptName}";
212+ text = ''
213+ #!${pkgs.runtimeShell} -e
214+ ${text}
215+ '';
216+ checkPhase = ''
217+ ${pkgs.stdenv.shell} -n "$out/bin/${scriptName}"
218+ '';
219+ };
220+ in "${out}/bin/${scriptName}";
206221
207222 unitConfig = { config, options, ... }: {
208223 config = {
@@ -250,40 +265,28 @@ let
250265 environment.PATH = config.path;
251266 }
252267 (mkIf (config.preStart != "")
253− { serviceConfig.ExecStartPre = makeJobScript "${name}-pre-start" ''
254− #! ${pkgs.runtimeShell} -e
255− ${config.preStart}
256− '';
268+ { serviceConfig.ExecStartPre =
269+ makeJobScript "${name}-pre-start" config.preStart;
257270 })
258271 (mkIf (config.script != "")
259− { serviceConfig.ExecStart = makeJobScript "${name}-start" ''
260− #! ${pkgs.runtimeShell} -e
261− ${config.script}
262− '' + " " + config.scriptArgs;
272+ { serviceConfig.ExecStart =
273+ makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
263274 })
264275 (mkIf (config.postStart != "")
265− { serviceConfig.ExecStartPost = makeJobScript "${name}-post-start" ''
266− #! ${pkgs.runtimeShell} -e
267− ${config.postStart}
268− '';
276+ { serviceConfig.ExecStartPost =
277+ makeJobScript "${name}-post-start" config.postStart;
269278 })
270279 (mkIf (config.reload != "")
271− { serviceConfig.ExecReload = makeJobScript "${name}-reload" ''
272− #! ${pkgs.runtimeShell} -e
273− ${config.reload}
274− '';
280+ { serviceConfig.ExecReload =
281+ makeJobScript "${name}-reload" config.reload;
275282 })
276283 (mkIf (config.preStop != "")
277− { serviceConfig.ExecStop = makeJobScript "${name}-pre-stop" ''
278− #! ${pkgs.runtimeShell} -e
279− ${config.preStop}
280− '';
284+ { serviceConfig.ExecStop =
285+ makeJobScript "${name}-pre-stop" config.preStop;
281286 })
282287 (mkIf (config.postStop != "")
283− { serviceConfig.ExecStopPost = makeJobScript "${name}-post-stop" ''
284− #! ${pkgs.runtimeShell} -e
285− ${config.postStop}
286− '';
288+ { serviceConfig.ExecStopPost =
289+ makeJobScript "${name}-post-stop" config.postStop;
287290 })
288291 ];
289292 };