~aasg/nixexprs

6b7331427bedf0458d000ea35c39a5289c45ae19 — Aluísio Augusto Silva Gonçalves 5 months ago 30ebec1
make-job-script: Extract systemd service script builder from Nixpkgs

This can be used when you want to use `preStart`, `postStart`, or
`preStop` but also need to apply one of the special executable prefixes.
4 files changed, 28 insertions(+), 0 deletions(-)

M flake.nix
A pkgs/build-support/make-job-script/default.nix
M pkgs/manifest.nix
M pkgs/overlay.nix
M flake.nix => flake.nix +1 -0
@@ 26,6 26,7 @@
          # Remove packages not compatible with this system.
          (filterAttrs (attr: drv: drv ? meta.platforms -> builtins.elem system drv.meta.platforms))
        ]);
      legacyPackages = genAttrs defaultSystems (system: (import ./. { pkgs = nixpkgs.legacyPackages.${system}; }));
      nixosModules = mapAttrs (name: path: import path) (import ./modules);
      overlays = {
        pkgs = import ./pkgs/overlay.nix;

A pkgs/build-support/make-job-script/default.nix => pkgs/build-support/make-job-script/default.nix +24 -0
@@ 0,0 1,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

M pkgs/manifest.nix => pkgs/manifest.nix +1 -0
@@ 10,6 10,7 @@
  [ "iwgtk" ]
  [ "linuxPackages" "rtl8723bu" ]
  [ "linuxPackages_latest" "rtl8723bu" ]
  [ "makeJobScript" ]
  [ "matrix-appservice-irc" ]
  [ "prometheus-bird-exporter" ]
  [ "python3Packages" "daemonocle" ]

M pkgs/overlay.nix => pkgs/overlay.nix +2 -0
@@ 25,6 25,8 @@ final: prev:
  linuxPackagesFor = kernel:
    (prev.linuxPackagesFor kernel).extend (import ./os-specific/linux/kernel-packages.nix);

  makeJobScript = final.callPackage ./build-support/make-job-script { };

  matrix-appservice-irc = final.callPackage ./servers/matrix-synapse/matrix-appservice-irc {
    nodejs = final.nodejs-12_x;
  };