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