nixos/boot-media: soft-force entire fs layout

https://github.com/NixOS/nixpkgs/pull/131760 was made to avo
a speicific configuration conflict that errored out for multiple definitions of "/" when the installer where overlayed
on any existing host configuration.

---

Problem 1: It turns out that in also other mountpoints can coflict.

Solution 1: use `mkOverride 60` for all mountpoints (even for the ones unlikely causing confilct for consistency sake)

---

Problem 2: It turns out that on an installation media for a fresh machine (before formatting), we usually don't have any devices yet formatted. However defining for example `fileSystems.<nme>.device = "/dev/disk/by-label/...", in newer versions of nixos, seems to make the system startup fail. Similarily waiting for a non-existent swap device does not make the startup fail, but has a 1:30 min timeout.

Solution 2: For an installation medium, soft-override ("unless users know what they are doing") the entire `fileSystems` and `swapDevices` definitions.
This commit is contained in:
David Arnold 2021-08-03 14:36:07 -05:00
parent 8ff76e34e0
commit 2af2d3146d
No known key found for this signature in database
GPG Key ID: AB15A6AF1101390D
3 changed files with 68 additions and 57 deletions

View File

@ -30,6 +30,12 @@ with lib;
# Add Memtest86+ to the CD. # Add Memtest86+ to the CD.
boot.loader.grub.memtest86.enable = true; boot.loader.grub.memtest86.enable = true;
# On a fresh machine, before formatting, an installation
# media cannot assume an existing file system layout such
# as might be defined by the encapsulated host config.
swapDevices = mkOverride 60 [ ];
fileSystems = mkOverride 60 config.lib.isoFileSystems;
boot.postBootCommands = '' boot.postBootCommands = ''
for o in $(</proc/cmdline); do for o in $(</proc/cmdline); do
case "$o" in case "$o" in

View File

@ -614,6 +614,58 @@ in
}; };
}; };
# store them in lib so we can set the same fileSystems with a
# higher prio on installation media
# This module is often over-layed onto an existing host config
# that defines `fileSystems`. We use mkOverride 60 to override
# standard values, but at the same time leave room for mkForce
# values targeted at the image build.
config.lib.isoFileSystems = {
"/" = mkOverride 60
{
fsType = "tmpfs";
options = [ "mode=0755" ];
};
# Note that /dev/root is a symlink to the actual root device
# specified on the kernel command line, created in the stage 1
# init script.
"/iso" = mkOverride 60
{ device = "/dev/root";
neededForBoot = true;
noCheck = true;
};
# In stage 1, mount a tmpfs on top of /nix/store (the squashfs
# image) to make this a live CD.
"/nix/.ro-store" = mkOverride 60
{ fsType = "squashfs";
device = "/iso/nix-store.squashfs";
options = [ "loop" ];
neededForBoot = true;
};
"/nix/.rw-store" = mkOverride 60
{ fsType = "tmpfs";
options = [ "mode=0755" ];
neededForBoot = true;
};
"/nix/store" = mkOverride 60
{ fsType = "overlay";
device = "overlay";
options = [
"lowerdir=/nix/.ro-store"
"upperdir=/nix/.rw-store/store"
"workdir=/nix/.rw-store/work"
];
depends = [
"/nix/.ro-store"
"/nix/.rw-store/store"
"/nix/.rw-store/work"
];
};
};
config = { config = {
assertions = [ assertions = [
@ -653,54 +705,7 @@ in
"boot.shell_on_fail" "boot.shell_on_fail"
]; ];
fileSystems."/" = fileSystems = config.lib.isoFileSystems;
# This module is often over-layed onto an existing host config
# that defines `/`. We use mkOverride 60 to override standard
# values, but at the same time leave room for mkForce values
# targeted at the image build.
{ fsType = mkOverride 60 "tmpfs";
options = [ "mode=0755" ];
};
# Note that /dev/root is a symlink to the actual root device
# specified on the kernel command line, created in the stage 1
# init script.
fileSystems."/iso" =
{ device = "/dev/root";
neededForBoot = true;
noCheck = true;
};
# In stage 1, mount a tmpfs on top of /nix/store (the squashfs
# image) to make this a live CD.
fileSystems."/nix/.ro-store" =
{ fsType = "squashfs";
device = "/iso/nix-store.squashfs";
options = [ "loop" ];
neededForBoot = true;
};
fileSystems."/nix/.rw-store" =
{ fsType = "tmpfs";
options = [ "mode=0755" ];
neededForBoot = true;
};
fileSystems."/nix/store" =
{ fsType = "overlay";
device = "overlay";
options = [
"lowerdir=/nix/.ro-store"
"upperdir=/nix/.rw-store/store"
"workdir=/nix/.rw-store/work"
];
depends = [
"/nix/.ro-store"
"/nix/.rw-store/store"
"/nix/.rw-store/work"
];
};
boot.initrd.availableKernelModules = [ "squashfs" "iso9660" "uas" "overlay" ]; boot.initrd.availableKernelModules = [ "squashfs" "iso9660" "uas" "overlay" ];

View File

@ -29,31 +29,31 @@ with lib;
then [] then []
else [ pkgs.grub2 pkgs.syslinux ]); else [ pkgs.grub2 pkgs.syslinux ]);
fileSystems."/" = # This module is often over-layed onto an existing host config
# This module is often over-layed onto an existing host config # that defines `fileSystems`. We use mkOverride 60 to override
# that defines `/`. We use mkOverride 60 to override standard # standard values, but at the same time leave room for mkForce
# values, but at the same time leave room for mkForce values # values targeted at the image build.
# targeted at the image build. fileSystems."/" = mkOverride 60
{ fsType = mkOverride 60 "tmpfs"; { fsType = "tmpfs";
options = [ "mode=0755" ]; options = [ "mode=0755" ];
}; };
# In stage 1, mount a tmpfs on top of /nix/store (the squashfs # In stage 1, mount a tmpfs on top of /nix/store (the squashfs
# image) to make this a live CD. # image) to make this a live CD.
fileSystems."/nix/.ro-store" = fileSystems."/nix/.ro-store" = mkOverride 60
{ fsType = "squashfs"; { fsType = "squashfs";
device = "../nix-store.squashfs"; device = "../nix-store.squashfs";
options = [ "loop" ]; options = [ "loop" ];
neededForBoot = true; neededForBoot = true;
}; };
fileSystems."/nix/.rw-store" = fileSystems."/nix/.rw-store" = mkOverride 60
{ fsType = "tmpfs"; { fsType = "tmpfs";
options = [ "mode=0755" ]; options = [ "mode=0755" ];
neededForBoot = true; neededForBoot = true;
}; };
fileSystems."/nix/store" = fileSystems."/nix/store" = mkOverride 60
{ fsType = "overlay"; { fsType = "overlay";
device = "overlay"; device = "overlay";
options = [ options = [