diff options
Diffstat (limited to 'installer-profiles/nfsroot.nix')
-rw-r--r-- | installer-profiles/nfsroot.nix | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/installer-profiles/nfsroot.nix b/installer-profiles/nfsroot.nix new file mode 100644 index 00000000..9db415a8 --- /dev/null +++ b/installer-profiles/nfsroot.nix | |||
@@ -0,0 +1,95 @@ | |||
1 | { config, pkgs, lib, flakeInputs, ... }: | ||
2 | |||
3 | with lib; | ||
4 | |||
5 | let | ||
6 | cfg = config.nfsroot; | ||
7 | in { | ||
8 | imports = [ | ||
9 | "${flakeInputs.nixpkgs.outPath}/nixos/modules/profiles/minimal.nix" | ||
10 | "${flakeInputs.nixpkgs.outPath}/nixos/modules/profiles/all-hardware.nix" | ||
11 | "${flakeInputs.nixpkgs.outPath}/nixos/modules/profiles/base.nix" | ||
12 | "${flakeInputs.nixpkgs.outPath}/nixos/modules/profiles/installation-device.nix" | ||
13 | ]; | ||
14 | |||
15 | options = { | ||
16 | nfsroot = { | ||
17 | storeDevice = mkOption { | ||
18 | type = types.str; | ||
19 | }; | ||
20 | }; | ||
21 | }; | ||
22 | |||
23 | config = { | ||
24 | # Don't build the GRUB menu builder script, since we don't need it | ||
25 | # here and it causes a cyclic dependency. | ||
26 | boot.loader.grub.enable = false; | ||
27 | |||
28 | # !!! Hack - attributes expected by other modules. | ||
29 | environment.systemPackages = [ pkgs.grub2_efi ] | ||
30 | ++ (if pkgs.stdenv.hostPlatform.system == "aarch64-linux" | ||
31 | then [] | ||
32 | else [ pkgs.grub2 pkgs.syslinux ]); | ||
33 | |||
34 | fileSystems."/" = mkImageMediaOverride | ||
35 | { fsType = "tmpfs"; | ||
36 | options = [ "mode=0755" ]; | ||
37 | }; | ||
38 | |||
39 | # In stage 1, mount a tmpfs on top of /nix/store (the squashfs | ||
40 | # image) to make this a live CD. | ||
41 | fileSystems."/nix/.ro-store" = mkImageMediaOverride | ||
42 | { fsType = "nfs4"; | ||
43 | device = cfg.storeDevice; | ||
44 | options = [ "ro" ]; | ||
45 | neededForBoot = true; | ||
46 | }; | ||
47 | |||
48 | fileSystems."/nix/.rw-store" = mkImageMediaOverride | ||
49 | { fsType = "tmpfs"; | ||
50 | options = [ "mode=0755" ]; | ||
51 | neededForBoot = true; | ||
52 | }; | ||
53 | |||
54 | fileSystems."/nix/store" = mkImageMediaOverride | ||
55 | { fsType = "overlay"; | ||
56 | device = "overlay"; | ||
57 | options = [ | ||
58 | "lowerdir=/nix/.ro-store" | ||
59 | "upperdir=/nix/.rw-store/store" | ||
60 | "workdir=/nix/.rw-store/work" | ||
61 | ]; | ||
62 | |||
63 | depends = [ | ||
64 | "/nix/.ro-store" | ||
65 | "/nix/.rw-store/store" | ||
66 | "/nix/.rw-store/work" | ||
67 | ]; | ||
68 | }; | ||
69 | |||
70 | boot.initrd.availableKernelModules = [ "nfs" "nfsv4" "overlay" ]; | ||
71 | boot.initrd.supportedFilesystems = [ "nfs" "nfsv4" "overlay" ]; | ||
72 | |||
73 | boot.initrd.network.enable = true; | ||
74 | boot.initrd.network.flushBeforeStage2 = false; # otherwise nfs dosen't work | ||
75 | networking.useDHCP = true; | ||
76 | |||
77 | |||
78 | system.build.netbootIpxeScript = pkgs.writeTextDir "netboot.ipxe" '' | ||
79 | #!ipxe | ||
80 | # Use the cmdline variable to allow the user to specify custom kernel params | ||
81 | # when chainloading this script from other iPXE scripts like netboot.xyz | ||
82 | kernel ${pkgs.stdenv.hostPlatform.linux-kernel.target} init=${config.system.build.toplevel}/init initrd=initrd ${toString config.boot.kernelParams} ''${cmdline} | ||
83 | initrd initrd | ||
84 | boot | ||
85 | ''; | ||
86 | |||
87 | boot.postBootCommands = | ||
88 | '' | ||
89 | # nixos-rebuild also requires a "system" profile and an | ||
90 | # /etc/NIXOS tag. | ||
91 | touch /etc/NIXOS | ||
92 | ${config.nix.package}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system | ||
93 | ''; | ||
94 | }; | ||
95 | } | ||