zaphyra's git: nixfiles

zaphyra's nixfiles

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
{
  systemConfig ? null,
  lib,
  buildEnv,
  writeTextFile,
  writeScriptBin,
  runtimeShell,
  deploy-rs,
}:

if systemConfig != null then
  buildEnv {
    name = "activatable-${systemConfig.system.build.toplevel.name}";
    paths = [
      systemConfig.system.build.toplevel
      (writeTextFile {
        name = "${systemConfig.system.build.toplevel.name}-activate-path";
        text = ''
          #!${runtimeShell}
          set -euo pipefail

          if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
          then
              $PROFILE/bin/switch-to-configuration dry-activate
          elif [[ "''${BOOT:-}" == "1" ]]
          then
              $PROFILE/bin/switch-to-configuration boot
          else
            # work around https://github.com/NixOS/nixpkgs/issues/73404
            cd /tmp

            $PROFILE/bin/switch-to-configuration switch

            # https://github.com/serokell/deploy-rs/issues/31
            ${lib.optionalString systemConfig.boot.loader.systemd-boot.enable "sed -i '/^default /d' ${systemConfig.boot.loader.efi.efiSysMountPoint}/loader/loader.conf"}
          fi
        '';
        executable = true;
        destination = "/deploy-rs-activate";
      })
      (writeTextFile {
        name = "${systemConfig.system.build.toplevel.name}-activate-rs";
        destination = "/activate-rs";
        executable = true;
        text = ''
          #!${runtimeShell}
          exec ${deploy-rs}/bin/activate "$@"
        '';
      })
    ];
  }
else
  writeScriptBin "activate" "echo 'No system config given!'"