summaryrefslogtreecommitdiff
path: root/system-profiles/nfsroot.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2024-08-08 10:45:09 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2024-08-08 10:45:09 +0200
commit63adb41f1a060c21a68143eb9e86c2790ef66f36 (patch)
tree3902b85e7659fd396ded1d2e42ea318153d08a13 /system-profiles/nfsroot.nix
parent73b08cbd76d4471c9a6fddd05265d7d7fc4c45ff (diff)
downloadnixos-63adb41f1a060c21a68143eb9e86c2790ef66f36.tar
nixos-63adb41f1a060c21a68143eb9e86c2790ef66f36.tar.gz
nixos-63adb41f1a060c21a68143eb9e86c2790ef66f36.tar.bz2
nixos-63adb41f1a060c21a68143eb9e86c2790ef66f36.tar.xz
nixos-63adb41f1a060c21a68143eb9e86c2790ef66f36.zip
...
Diffstat (limited to 'system-profiles/nfsroot.nix')
-rw-r--r--system-profiles/nfsroot.nix172
1 files changed, 92 insertions, 80 deletions
diff --git a/system-profiles/nfsroot.nix b/system-profiles/nfsroot.nix
index 4323765b..1cd930d9 100644
--- a/system-profiles/nfsroot.nix
+++ b/system-profiles/nfsroot.nix
@@ -1,4 +1,4 @@
1{ config, pkgs, lib, flake, flakeInputs, ... }: 1{ config, options, pkgs, lib, flake, flakeInputs, ... }:
2 2
3with lib; 3with lib;
4 4
@@ -14,99 +14,111 @@ in {
14 storeDevice = mkOption { 14 storeDevice = mkOption {
15 type = types.str; 15 type = types.str;
16 default = "nfsroot:nix-store"; 16 default = "nfsroot:nix-store";
17 description = "Nix store device";
17 }; 18 };
18 19
19 registrationUrl = mkOption { 20 registrationUrl = mkOption {
20 type = types.str; 21 type = types.str;
21 default = "http://nfsroot/nix-registration"; 22 default = "http://nfsroot/nix-registration";
23 description = "Url of nix store registrations";
22 }; 24 };
23 }; 25 };
24 26
25 system.build = { 27 system.build = {
26 storeContents = mkOption {}; 28 storeContents = mkOption {
29 description = "Contents of nix store";
30 };
27 }; 31 };
28 }; 32 };
29 33
30 config = { 34 config = foldr recursiveUpdate {} ([
31 # Don't build the GRUB menu builder script, since we don't need it 35 {
32 # here and it causes a cyclic dependency. 36 # Don't build the GRUB menu builder script, since we don't need it
33 boot.loader.grub.enable = false; 37 # here and it causes a cyclic dependency.
34 38 boot.loader.grub.enable = false;
35 # !!! Hack - attributes expected by other modules. 39
36 environment.systemPackages = [ pkgs.grub2_efi ] 40 # !!! Hack - attributes expected by other modules.
37 ++ (if pkgs.stdenv.hostPlatform.system == "aarch64-linux" 41 environment.systemPackages = [ pkgs.grub2_efi ]
38 then [] 42 ++ (if pkgs.stdenv.hostPlatform.system == "aarch64-linux"
39 else [ pkgs.grub2 pkgs.syslinux ]); 43 then []
40 44 else [ pkgs.grub2 pkgs.syslinux ]);
41 # In stage 1, mount a tmpfs on top of /nix/store (the squashfs 45
42 # image) to make this a live CD. 46 # In stage 1, mount a tmpfs on top of /nix/store (the squashfs
43 fileSystems."/nix/.ro-store" = mkImageMediaOverride 47 # image) to make this a live CD.
44 { fsType = "nfs4"; 48 fileSystems."/nix/.ro-store" = mkImageMediaOverride
45 device = cfg.storeDevice; 49 { fsType = "nfs4";
46 options = [ "ro" ]; 50 device = cfg.storeDevice;
47 neededForBoot = true; 51 options = [ "ro" ];
48 }; 52 neededForBoot = true;
53 };
54
55 fileSystems."/nix/.rw-store" = mkImageMediaOverride
56 { fsType = "tmpfs";
57 options = [ "mode=0755" ];
58 neededForBoot = true;
59 };
60
61 fileSystems."/nix/store" = mkImageMediaOverride
62 { fsType = "overlay";
63 device = "overlay";
64 options = [
65 "lowerdir=/nix/.ro-store"
66 "upperdir=/nix/.rw-store/store"
67 "workdir=/nix/.rw-store/work"
68 ];
69
70 depends = [
71 "/nix/.ro-store"
72 "/nix/.rw-store/store"
73 "/nix/.rw-store/work"
74 ];
75 };
76
77 nix.settings.use-sqlite-wal = false;
78
79 boot.initrd.availableKernelModules = [ "nfs" "nfsv4" "overlay" ];
80 boot.initrd.supportedFilesystems = [ "nfs" "nfsv4" "overlay" ];
81 services.rpcbind.enable = mkImageMediaOverride false;
82
83 boot.initrd.network.enable = true;
84 boot.initrd.network.flushBeforeStage2 = false; # otherwise nfs doesn't work
85 boot.initrd.postMountCommands = ''
86 mkdir -p /mnt-root/etc/
87 cp /etc/resolv.conf /mnt-root/etc/resolv.conf
88 '';
89 networking.useDHCP = true;
90 networking.resolvconf.enable = false;
91 networking.dhcpcd.persistent = true;
49 92
50 fileSystems."/nix/.rw-store" = mkImageMediaOverride
51 { fsType = "tmpfs";
52 options = [ "mode=0755" ];
53 neededForBoot = true;
54 };
55 93
56 fileSystems."/nix/store" = mkImageMediaOverride 94 system.build.storeContents = [config.system.build.toplevel];
57 { fsType = "overlay";
58 device = "overlay";
59 options = [
60 "lowerdir=/nix/.ro-store"
61 "upperdir=/nix/.rw-store/store"
62 "workdir=/nix/.rw-store/work"
63 ];
64
65 depends = [
66 "/nix/.ro-store"
67 "/nix/.rw-store/store"
68 "/nix/.rw-store/work"
69 ];
70 };
71 95
72 nix.settings.use-sqlite-wal = false; 96 system.build.netbootIpxeScript = pkgs.writeTextDir "netboot.ipxe" ''
73 97 #!ipxe
74 boot.initrd.availableKernelModules = [ "nfs" "nfsv4" "overlay" ]; 98 # Use the cmdline variable to allow the user to specify custom kernel params
75 boot.initrd.supportedFilesystems = [ "nfs" "nfsv4" "overlay" ]; 99 # when chainloading this script from other iPXE scripts like netboot.xyz
76 services.rpcbind.enable = mkImageMediaOverride false; 100 kernel ${pkgs.stdenv.hostPlatform.linux-kernel.target} init=${config.system.build.toplevel}/init initrd=initrd ${toString config.boot.kernelParams} ''${cmdline}
77 101 initrd initrd
78 boot.initrd.network.enable = true; 102 boot
79 boot.initrd.network.flushBeforeStage2 = false; # otherwise nfs doesn't work
80 boot.initrd.postMountCommands = ''
81 mkdir -p /mnt-root/etc/
82 cp /etc/resolv.conf /mnt-root/etc/resolv.conf
83 '';
84 networking.useDHCP = true;
85 networking.resolvconf.enable = false;
86 networking.dhcpcd.persistent = true;
87
88
89 system.build.storeContents = [config.system.build.toplevel];
90
91 system.build.netbootIpxeScript = pkgs.writeTextDir "netboot.ipxe" ''
92 #!ipxe
93 # Use the cmdline variable to allow the user to specify custom kernel params
94 # when chainloading this script from other iPXE scripts like netboot.xyz
95 kernel ${pkgs.stdenv.hostPlatform.linux-kernel.target} init=${config.system.build.toplevel}/init initrd=initrd ${toString config.boot.kernelParams} ''${cmdline}
96 initrd initrd
97 boot
98 '';
99
100 boot.postBootCommands =
101 ''
102 # After booting, register the contents of the Nix store on NFS
103 # in the Nix database in the tmpfs.
104 ${pkgs.curl}/bin/curl ${escapeShellArg cfg.registrationUrl} | ${config.nix.package.out}/bin/nix-store --load-db
105
106 # nixos-rebuild also requires a "system" profile and an
107 # /etc/NIXOS tag.
108 touch /etc/NIXOS
109 ${config.nix.package}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
110 ''; 103 '';
111 }; 104
105 boot.postBootCommands =
106 ''
107 # After booting, register the contents of the Nix store on NFS
108 # in the Nix database in the tmpfs.
109 ${pkgs.curl}/bin/curl ${escapeShellArg cfg.registrationUrl} | ${config.nix.package.out}/bin/nix-store --load-db
110
111 # nixos-rebuild also requires a "system" profile and an
112 # /etc/NIXOS tag.
113 touch /etc/NIXOS
114 ${config.nix.package}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
115 '';
116
117 boot.initrd.systemd.enable = false;
118 }
119 ] ++ (optional (options ? system.etc) {
120 system.etc.overlay.enable = false;
121 }) ++ (optional (options ? system.sysusers) {
122 systemd.sysusers.enable = false;
123 }));
112} 124}