~aasg/nixexprs

ref: 6b7331427bedf0458d000ea35c39a5289c45ae19 nixexprs/pkgs/build-support/make-job-script/default.nix -rw-r--r-- 623 bytes
6b733142 — Aluísio Augusto Silva Gonçalves make-job-script: Extract systemd service script builder from Nixpkgs 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{ lib, writeTextFile, stdenv, runtimeShell }:
let
  inherit (lib) replaceChars;

  # Taken from <nixpkgs/nixos/modules/system/boot/systemd.nix>.
  makeJobScript = name: text:
    let
      scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] name;
      out = writeTextFile {
        name = "unit-script-${scriptName}";
        executable = true;
        destination = "/bin/${scriptName}";
        text = ''
          #!${runtimeShell} -e
          ${text}
        '';
        checkPhase = ''
          ${stdenv.shell} -n "$out/bin/${scriptName}"
        '';
      };
    in
    "${out}/bin/${scriptName}";
in
makeJobScript