diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-10-03 17:15:36 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-10-03 17:15:36 +0200 |
commit | 9248259708bd6ade5e334a2cdfb29d2a20acb0dd (patch) | |
tree | 976a140d547557c8cdf98856510030fd35b83d1a /installer-profiles/nfsroot.nix | |
parent | 59e54bd97f70711573d321f2d2aeee5da46bf95d (diff) | |
download | nixos-9248259708bd6ade5e334a2cdfb29d2a20acb0dd.tar nixos-9248259708bd6ade5e334a2cdfb29d2a20acb0dd.tar.gz nixos-9248259708bd6ade5e334a2cdfb29d2a20acb0dd.tar.bz2 nixos-9248259708bd6ade5e334a2cdfb29d2a20acb0dd.tar.xz nixos-9248259708bd6ade5e334a2cdfb29d2a20acb0dd.zip |
...
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 | } | ||