summaryrefslogtreecommitdiff
path: root/modules/installer.nix
blob: 3e5c6d5b4755ecdc9449e144309ab2630f641542 (plain)
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
54
55
56
{ flake, config, lib, pkgs, ... }:

let
  cfg = config.installer.links;

  installerOutPath = {
    "cd-dvd" = _: installerBuild: "${installerBuild.config.system.build.isoImage}/iso";
    "netboot" = {system, variant}: installerBuild: pkgs.runCommandLocal "${system}-${variant}" {} ''
      mkdir $out
      install -m 0444 -t $out \
        ${installerBuild.config.system.build.netbootRamdisk}/initrd \
        ${installerBuild.config.system.build.kernel}/${config.system.boot.loader.kernelFile} \
        ${installerBuild.config.system.build.netbootIpxeScript}/netboot.ipxe \
        ${pkgs.ipxe.override {
          additionalTargets = {
            "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi";
          };
          additionalOptions = [
            "NSLOOKUP_CMD"
            "PING_CMD"
            "CONSOLE_CMD"
          ];
          embedScript = pkgs.writeText "netboot.ipxe" ''
            #!ipxe

            chain netboot.ipxe
          '';
        }}/{ipxe.efi,i386-ipxe.efi,ipxe.lkrn}
    '';
  };
in {
  options = {
    installer.links = lib.mkOption {
      type = lib.types.listOf (lib.types.submodule {
        options = {
          system = lib.mkOption {
            type = lib.types.str;
          };
          variant = lib.mkOption {
            type = lib.types.str;
          };
        };
      });
      default = [];
    };
  };

  config = lib.mkIf (cfg != []) {
    systemd.tmpfiles.rules = map (installer'@{system, variant}:
      let
        installer = "${system}-${variant}";
        installerBuild = builtins.addErrorContext "while evaluating installer-${installer}" flake.nixosConfigurations.${"installer-${installer}"};
      in "L+ /run/installer-${installer} - - - - ${installerOutPath.${variant} installer' installerBuild}"
    ) cfg;
  };
}