From 9d92c9d0a797b19662968b250919d075317d7379 Mon Sep 17 00:00:00 2001 From: Tom Fitzhenry Date: Fri, 19 Jun 2020 17:57:04 +1000 Subject: iso-image: add 'serial console' boot entry Prior to this commit, installation over serial console would requiring manually having to modify the kernel modeline, as described in https://github.com/NixOS/nixpkgs/issues/58198 . This is unnecessarily fiddly, so this commit adds a syslinux boot entry that has serial enabled. GRUB already has a serial console entry: https://github.com/NixOS/nixpkgs/blob/2c07a0800a76be01a3c255f39e21877a9a389f84/nixos/modules/installer/cd-dvd/iso-image.nix#L311-L317 Why 115200 bps? This is already used in other places, e.g. https://github.com/NixOS/nixpkgs/pull/58196 I tested this change by building the image, booting the image, and observing the boot process over serial: $ cd nixos/ $ nix-build -A config.system.build.isoImage -I nixos-config=modules/installer/cd-dvd/installation-cd-minimal.nix default.nix $ sudo cp /nix/store/arcl702c3z8xlndlvnfplq9yhixjvs9k-nixos-20.09pre-git-x86_64-linux.iso/iso/nixos-20.09pre-git-x86_64-linux.iso /dev/sdb $ picocom -b 115200 /dev/ttyUSB0 --- nixos/modules/installer/cd-dvd/iso-image.nix | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 405fbfa10db..43d20a556f8 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -143,6 +143,13 @@ let LINUX /boot/${config.system.boot.loader.kernelFile} APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} loglevel=7 INITRD /boot/${config.system.boot.loader.initrdFile} + + # A variant to boot with a serial console enabled + LABEL boot-serial + MENU LABEL NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (serial console=ttyS0,115200n8) + LINUX /boot/${config.system.boot.loader.kernelFile} + APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} console=ttyS0,115200n8 + INITRD /boot/${config.system.boot.loader.initrdFile} ''; isolinuxMemtest86Entry = '' -- cgit 1.4.1 From 2fcab516c4cae0bc50455abd356f60e576fec5d9 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sun, 10 Jan 2021 10:03:50 +0100 Subject: iso-image: enable XZ compress filter Minimal ISO: 1m21 -> 2m25 625M -> 617M Plasma5 ISO: 2m45 -> 5m18 1.4G -> 1.3G Decompression speed stays about the same. It's just a few seconds for the whole image anyways and, with that kind of speed, you're going to be bottlenecked by IO long before the CPU. --- nixos/modules/installer/cd-dvd/iso-image.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 43d20a556f8..1418420afcd 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -425,7 +425,12 @@ in }; isoImage.squashfsCompression = mkOption { - default = "xz -Xdict-size 100%"; + default = with pkgs.stdenv.targetPlatform; "xz -Xdict-size 100% " + + lib.optionalString (isx86_32 || isx86_64) "-Xbcj x86" + # Untested but should also reduce size for these platforms + + lib.optionalString (isAarch32 || isAarch64) "-Xbcj arm" + + lib.optionalString (isPowerPC) "-Xbcj powerpc" + + lib.optionalString (isSparc) "-Xbcj sparc"; description = '' Compression settings to use for the squashfs nix store. ''; -- cgit 1.4.1 From 20d0824b150492d4b484954c64aad9f24656c130 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Tue, 20 Apr 2021 01:32:42 -0400 Subject: iso-image: Fix grub file load location With U-Boot UEFI, (hd0) is not the USB drive, it is (cd0). Though, it turns out we never needed to prefix the path! --- nixos/modules/installer/cd-dvd/iso-image.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 1418420afcd..e73bb883df5 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -186,7 +186,7 @@ let # Fonts can be loaded? # (This font is assumed to always be provided as a fallback by NixOS) - if loadfont (hd0)/EFI/boot/unicode.pf2; then + if loadfont /EFI/boot/unicode.pf2; then # Use graphical term, it can be either with background image or a theme. # input is "console", while output is "gfxterm". # This enables "serial" input and output only when possible. @@ -207,11 +207,11 @@ let ${ # When there is a theme configured, use it, otherwise use the background image. if config.isoImage.grubTheme != null then '' # Sets theme. - set theme=(hd0)/EFI/boot/grub-theme/theme.txt + set theme=/EFI/boot/grub-theme/theme.txt # Load theme fonts - $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (hd0)/EFI/boot/grub-theme/%P\n") + $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont /EFI/boot/grub-theme/%P\n") '' else '' - if background_image (hd0)/EFI/boot/efi-background.png; then + if background_image /EFI/boot/efi-background.png; then # Black background means transparent background when there # is a background image set... This seems undocumented :( set color_normal=black/black -- cgit 1.4.1 From 189507a35d4fd5c88e1172aee0a410229e60ba86 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Tue, 20 Apr 2021 01:34:15 -0400 Subject: iso-image: Make graphical output work properly on AArch64 The serial output (but it's named console, not serial actually) causes issues on U-Boot's EFI, at the very least. This is inspired by OpenSUSE's approach: * https://build.opensuse.org/package/view_file/Base:System/grub2/grub2-SUSE-Add-the-t-hotkey.patch Where they add a hidden menu entry, which can be used to force the console output. The `echo` will be visible on the serial terminal (grub "console"), while the graphical interface is shown. Note that input in the serial terminal (grub "console") will continue controlling the graphical interface. Useful if you have an SBC connectedinto an HDMI monitor, but no keyboard connected to it. --- nixos/modules/installer/cd-dvd/iso-image.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index e73bb883df5..b876e83e237 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -187,6 +187,9 @@ let # Fonts can be loaded? # (This font is assumed to always be provided as a fallback by NixOS) if loadfont /EFI/boot/unicode.pf2; then + set with_fonts=true + fi + if [ "\$textmode" != "true" -a "\$with_fonts" == "true" ]; then # Use graphical term, it can be either with background image or a theme. # input is "console", while output is "gfxterm". # This enables "serial" input and output only when possible. @@ -264,6 +267,8 @@ let cat < $out/EFI/boot/grub.cfg + set with_fonts=false + set textmode=false # If you want to use serial for "terminal_*" commands, you need to set one up: # Example manual configuration: # → serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 @@ -273,8 +278,28 @@ let export with_serial clear set timeout=10 + + # This message will only be viewable when "gfxterm" is not used. + echo "" + echo "Loading graphical boot menu..." + echo "" + echo "Press 't' to use the text boot menu on this console..." + echo "" + ${grubMenuCfg} + hiddenentry 'Text mode' --hotkey 't' { + loadfont /EFI/boot/unicode.pf2 + set textmode=true + terminal_output gfxterm console + } + hiddenentry 'GUI mode' --hotkey 'g' { + $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont /EFI/boot/grub-theme/%P\n") + set textmode=false + terminal_output gfxterm + } + + # If the parameter iso_path is set, append the findiso parameter to the kernel # line. We need this to allow the nixos iso to be booted from grub directly. if [ \''${iso_path} ] ; then -- cgit 1.4.1 From 9413da26fd3364d81bb744578f95512a4c2c7863 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Tue, 20 Apr 2021 17:03:15 -0400 Subject: iso-image: Provide the right rEFInd binary --- nixos/modules/installer/cd-dvd/iso-image.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index b876e83e237..7dd3bf23933 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -162,12 +162,14 @@ let isolinuxCfg = concatStringsSep "\n" ([ baseIsolinuxCfg ] ++ optional config.boot.loader.grub.memtest86.enable isolinuxMemtest86Entry); + refindBinary = if targetArch == "x64" || targetArch == "aa64" then "refind_${targetArch}.efi" else null; + # Setup instructions for rEFInd. refind = - if targetArch == "x64" then + if refindBinary != null then '' # Adds rEFInd to the ISO. - cp -v ${pkgs.refind}/share/refind/refind_x64.efi $out/EFI/boot/ + cp -v ${pkgs.refind}/share/refind/${refindBinary} $out/EFI/boot/ '' else "# No refind for ${targetArch}" @@ -362,11 +364,13 @@ let } } + ${lib.optionalString (refindBinary != null) '' menuentry 'rEFInd' --class refind { # UUID is hard-coded in the derivation. search --set=root --no-floppy --fs-uuid 1234-5678 - chainloader (\$root)/EFI/boot/refind_x64.efi + chainloader (\$root)/EFI/boot/${refindBinary} } + ''} menuentry 'Firmware Setup' --class settings { fwsetup clear -- cgit 1.4.1 From cb5c4fcd3c5d4070f040d591b2dd1da580f234d1 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Tue, 20 Apr 2021 17:11:21 -0400 Subject: iso-image: Hide rEFInd from menu in known non-working situations Looks like GRUB has issues loading EFI binaries from (cd0), which is what would be used in e.g. qemu with OVMF with `-cdrom`. Apparently also what is used with AArch64 + U-Boot USB. --- nixos/modules/installer/cd-dvd/iso-image.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 7dd3bf23933..7a4738599b0 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -365,11 +365,13 @@ let } ${lib.optionalString (refindBinary != null) '' - menuentry 'rEFInd' --class refind { - # UUID is hard-coded in the derivation. - search --set=root --no-floppy --fs-uuid 1234-5678 - chainloader (\$root)/EFI/boot/${refindBinary} - } + # GRUB apparently cannot do "chainloader" operations on "CD". + if [ "\$root" != "cd0" ]; then + menuentry 'rEFInd' --class refind { + # \$root defaults to the drive the EFI is found on. + chainloader (\$root)/EFI/boot/${refindBinary} + } + fi ''} menuentry 'Firmware Setup' --class settings { fwsetup -- cgit 1.4.1 From d053c05d19aef8f1295dcdc1e81de9103892d8db Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 22 Apr 2021 15:55:44 -0400 Subject: iso-image: Fixes for cross-compilation Note that here, since it's not a in a callPackage call, splicing won't work on nativeBuildInputs. --- nixos/modules/installer/cd-dvd/iso-image.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 7a4738599b0..e25c96d5778 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -263,7 +263,7 @@ let # Make our own efi program, we can't rely on "grub-install" since it seems to # probe for devices, even with --skip-fs-probe. - ${grubPkgs.grub2_efi}/bin/grub-mkimage -o $out/EFI/boot/boot${targetArch}.efi -p /EFI/boot -O ${grubPkgs.grub2_efi.grubTarget} \ + ${pkgs.buildPackages.grub2_efi}/bin/grub-mkimage --directory=${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget} -o $out/EFI/boot/boot${targetArch}.efi -p /EFI/boot -O ${grubPkgs.grub2_efi.grubTarget} \ $MODULES cp ${grubPkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/ @@ -388,7 +388,7 @@ let ${refind} ''; - efiImg = pkgs.runCommand "efi-image_eltorito" { buildInputs = [ pkgs.mtools pkgs.libfaketime ]; } + efiImg = pkgs.runCommand "efi-image_eltorito" { nativeBuildInputs = [ pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools ]; } # Be careful about determinism: du --apparent-size, # dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i) '' @@ -408,10 +408,10 @@ let echo "Usage size: $usage_size" echo "Image size: $image_size" truncate --size=$image_size "$out" - ${pkgs.libfaketime}/bin/faketime "2000-01-01 00:00:00" ${pkgs.dosfstools}/sbin/mkfs.vfat -i 12345678 -n EFIBOOT "$out" + faketime "2000-01-01 00:00:00" mkfs.vfat -i 12345678 -n EFIBOOT "$out" mcopy -psvm -i "$out" ./EFI ./boot :: # Verify the FAT partition. - ${pkgs.dosfstools}/sbin/fsck.vfat -vn "$out" + fsck.vfat -vn "$out" ''; # */ # Name used by UEFI for architectures. -- cgit 1.4.1 From f1100e15066c7f1eeff66e0e9dcdaf29131f876b Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sat, 1 May 2021 16:59:24 -0400 Subject: iso-image: Add support for armv7l-linux --- nixos/modules/installer/cd-dvd/iso-image.nix | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index e25c96d5778..d421e3ea428 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -420,6 +420,8 @@ let "ia32" else if pkgs.stdenv.isx86_64 then "x64" + else if pkgs.stdenv.isAarch32 then + "arm" else if pkgs.stdenv.isAarch64 then "aa64" else -- cgit 1.4.1 From 556fc32d699e2ee3b1e7fbf3bb35eb80b966e7fc Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 3 May 2021 15:52:22 -0400 Subject: iso-image: Build using strictDeps --- nixos/modules/installer/cd-dvd/iso-image.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index d421e3ea428..324b38070e4 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -233,7 +233,10 @@ let # Notes about grub: # * Yes, the grubMenuCfg has to be repeated in all submenus. Otherwise you # will get white-on-black console-like text on sub-menus. *sigh* - efiDir = pkgs.runCommand "efi-directory" {} '' + efiDir = pkgs.runCommand "efi-directory" { + nativeBuildInputs = [ pkgs.buildPackages.grub2_efi ]; + strictDeps = true; + } '' mkdir -p $out/EFI/boot/ # ALWAYS required modules. @@ -263,7 +266,7 @@ let # Make our own efi program, we can't rely on "grub-install" since it seems to # probe for devices, even with --skip-fs-probe. - ${pkgs.buildPackages.grub2_efi}/bin/grub-mkimage --directory=${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget} -o $out/EFI/boot/boot${targetArch}.efi -p /EFI/boot -O ${grubPkgs.grub2_efi.grubTarget} \ + grub-mkimage --directory=${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget} -o $out/EFI/boot/boot${targetArch}.efi -p /EFI/boot -O ${grubPkgs.grub2_efi.grubTarget} \ $MODULES cp ${grubPkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/ @@ -388,7 +391,10 @@ let ${refind} ''; - efiImg = pkgs.runCommand "efi-image_eltorito" { nativeBuildInputs = [ pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools ]; } + efiImg = pkgs.runCommand "efi-image_eltorito" { + nativeBuildInputs = [ pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools ]; + strictDeps = true; + } # Be careful about determinism: du --apparent-size, # dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i) '' -- cgit 1.4.1 From e3cd6444584dc2d018a39ad7f94769caf043e621 Mon Sep 17 00:00:00 2001 From: Ning Shang Date: Fri, 16 Apr 2021 10:15:25 -0700 Subject: iso-image: Use fixed-order mcopy instead of file globbing mcopy file globbing is non-deterministic with respect to the underlying file system. As a result, the current mcopy approach is less likely to reproduce efi.img on different machines. We replace mcopy file globbing with fixed-order mmd and mcopy operations for better determinism. We also use faketime on mmd for the same reason. We use faketime, mmd, and mcopy directly, becase they are already in PATH. Thank misuzu@ for the feedback. --- nixos/modules/installer/cd-dvd/iso-image.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 324b38070e4..5910bfc05ac 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -415,7 +415,24 @@ let echo "Image size: $image_size" truncate --size=$image_size "$out" faketime "2000-01-01 00:00:00" mkfs.vfat -i 12345678 -n EFIBOOT "$out" - mcopy -psvm -i "$out" ./EFI ./boot :: + + # Force a fixed order in mcopy for better determinism, and avoid file globbing + for d in $(find EFI -type d | sort); do + faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d" + done + + for d in $(find boot -type d | sort); do + faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d" + done + + for f in $(find EFI -type f | sort); do + mcopy -pvm -i "$out" "$f" "::/$f" + done + + for f in $(find boot -type f | sort); do + mcopy -pvm -i "$out" "$f" "::/$f" + done + # Verify the FAT partition. fsck.vfat -vn "$out" ''; # */ -- cgit 1.4.1 From 4db7eb476f30a819eacd1459d78bf8fe5b3bccb3 Mon Sep 17 00:00:00 2001 From: Ning Shang Date: Thu, 20 May 2021 11:01:17 -0700 Subject: iso-image: Workaround for better determinism in du output The value of du output depends on the underlying file system, and thus is not fully deterministic. This workaround rounds up the disk usage size to the nearest multiple of 1MB, to increase the probability that two du output values on two different file systems fall within the same 1MB window. Note that this workaround won't make du output 100% reproducible, but will increase the probability of getting deterministic builds across different file systems. --- nixos/modules/installer/cd-dvd/iso-image.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 5910bfc05ac..c3d12bda28d 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -405,7 +405,8 @@ let "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}" ./boot/ touch --date=@0 ./EFI ./boot - usage_size=$(du -sb --apparent-size . | tr -cd '[:digit:]') + # Round up to the nearest multiple of 1MB, for more deterministic du output + usage_size=$(( $(du -s --block-size=1M --apparent-size . | tr -cd '[:digit:]') * 1024 * 1024 )) # Make the image 110% as big as the files need to make up for FAT overhead image_size=$(( ($usage_size * 110) / 100 )) # Make the image fit blocks of 1M -- cgit 1.4.1 From 657e924ad853e099cbc36be50478e9877aa05a25 Mon Sep 17 00:00:00 2001 From: Ning Shang Date: Thu, 20 May 2021 12:17:04 -0700 Subject: iso-image: More concise code for fixed order mmd and mcopy operations Thanks @misuzu for the suggestions. --- nixos/modules/installer/cd-dvd/iso-image.nix | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index c3d12bda28d..62fc097f9dd 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -418,19 +418,11 @@ let faketime "2000-01-01 00:00:00" mkfs.vfat -i 12345678 -n EFIBOOT "$out" # Force a fixed order in mcopy for better determinism, and avoid file globbing - for d in $(find EFI -type d | sort); do + for d in $(find EFI boot -type d | sort); do faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d" done - for d in $(find boot -type d | sort); do - faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d" - done - - for f in $(find EFI -type f | sort); do - mcopy -pvm -i "$out" "$f" "::/$f" - done - - for f in $(find boot -type f | sort); do + for f in $(find EFI boot -type f | sort); do mcopy -pvm -i "$out" "$f" "::/$f" done -- cgit 1.4.1 From f93f0e72e9ef423ed591951030f08cafd209e637 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sat, 22 May 2021 18:16:42 -0400 Subject: iso-image: Force gfxmode https://www.gnu.org/software/grub/manual/grub/html_node/gfxmode.html --- nixos/modules/installer/cd-dvd/iso-image.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 324b38070e4..3f5ac8a5113 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -185,6 +185,19 @@ let insmod gfxterm insmod png set gfxpayload=keep + set gfxmode=${concatStringsSep "," [ + # GRUB will use the first valid mode listed here. + # `auto` will sometimes choose the smallest valid mode it detects. + # So instead we'll list a lot of possibly valid modes :/ + #"3840x2160" + #"2560x1440" + "1920x1080" + "1366x768" + "1280x720" + "1024x768" + "800x600" + "auto" + ]} # Fonts can be loaded? # (This font is assumed to always be provided as a fallback by NixOS) -- cgit 1.4.1 From 15eaed0718515db3f2fa7d4ed71676e6069d3fb5 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sat, 22 May 2021 18:38:31 -0400 Subject: iso-image: change date on all files It may be that in some conditions dates earlier than 1980 on FAT on GRUB 2.06~ish will cause failures https://github.com/NixOS/nixpkgs/issues/123376#issuecomment-845515035 --- nixos/modules/installer/cd-dvd/iso-image.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 3f5ac8a5113..be5db40e537 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -416,7 +416,9 @@ let mkdir ./boot cp -p "${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}" \ "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}" ./boot/ - touch --date=@0 ./EFI ./boot + + # Rewrite dates for everything in the FS + find . -exec touch --date=2000-01-01 {} + usage_size=$(du -sb --apparent-size . | tr -cd '[:digit:]') # Make the image 110% as big as the files need to make up for FAT overhead -- cgit 1.4.1 From c9bb054dd68964b0eb9a38c51bdf824bfb212fc7 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sat, 22 May 2021 17:07:36 -0400 Subject: iso-image: unqualified root → ($root) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This technically changes nothing. In practice `$root` is always the "CWD", whether searched for automatically or not. But this serves to announce we are relying on `$root`... I guess... --- nixos/modules/installer/cd-dvd/iso-image.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index be5db40e537..321a03a0f0c 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -201,7 +201,7 @@ let # Fonts can be loaded? # (This font is assumed to always be provided as a fallback by NixOS) - if loadfont /EFI/boot/unicode.pf2; then + if loadfont (\$root)/EFI/boot/unicode.pf2; then set with_fonts=true fi if [ "\$textmode" != "true" -a "\$with_fonts" == "true" ]; then @@ -225,11 +225,11 @@ let ${ # When there is a theme configured, use it, otherwise use the background image. if config.isoImage.grubTheme != null then '' # Sets theme. - set theme=/EFI/boot/grub-theme/theme.txt + set theme=(\$root)/EFI/boot/grub-theme/theme.txt # Load theme fonts - $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont /EFI/boot/grub-theme/%P\n") + $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n") '' else '' - if background_image /EFI/boot/efi-background.png; then + if background_image (\$root)/EFI/boot/efi-background.png; then # Black background means transparent background when there # is a background image set... This seems undocumented :( set color_normal=black/black @@ -307,12 +307,12 @@ let ${grubMenuCfg} hiddenentry 'Text mode' --hotkey 't' { - loadfont /EFI/boot/unicode.pf2 + loadfont (\$root)/EFI/boot/unicode.pf2 set textmode=true terminal_output gfxterm console } hiddenentry 'GUI mode' --hotkey 'g' { - $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont /EFI/boot/grub-theme/%P\n") + $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n") set textmode=false terminal_output gfxterm } -- cgit 1.4.1 From 20b023b5ea63a6513a4dce7f162736a00bce5cc8 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sat, 22 May 2021 20:01:07 -0400 Subject: iso-image: Improve disk detection This should help in rare hardware-specific situations where the root is not automatically detected properly. We search using a marker file. This should help some weird UEFI setups where the root is set to `(hd0,msdos2)` by default. Defaulting to `(hd0)` by looking for the ESP **will break themeing**. It is unclear why, but files in `(hd0,msdos2)` are not all present as they should be. This also fixes an issue introduced with cb5c4fcd3c5d4070f040d591b2dd1da580f234d1 where rEFInd stopped booting in many cases. This is because it ended up using (hd0) rather than using the `search` which was happening beforehand, which in turn uses (hd0,msdos2), which is the ESP. Putting back the `search` here fixes that. --- nixos/modules/installer/cd-dvd/iso-image.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 321a03a0f0c..c2836b5a9a1 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -182,6 +182,9 @@ let # Menu configuration # + # Search using a "marker file" + search --set=root --file /EFI/nixos-installer-image + insmod gfxterm insmod png set gfxpayload=keep @@ -252,6 +255,9 @@ let } '' mkdir -p $out/EFI/boot/ + # Add a marker so GRUB can find the filesystem. + touch $out/EFI/nixos-installer-image + # ALWAYS required modules. MODULES="fat iso9660 part_gpt part_msdos \ normal boot linux configfile loopback chain halt \ @@ -383,8 +389,10 @@ let ${lib.optionalString (refindBinary != null) '' # GRUB apparently cannot do "chainloader" operations on "CD". if [ "\$root" != "cd0" ]; then + # Force root to be the FAT partition + # Otherwise it breaks rEFInd's boot + search --set=root --no-floppy --fs-uuid 1234-5678 menuentry 'rEFInd' --class refind { - # \$root defaults to the drive the EFI is found on. chainloader (\$root)/EFI/boot/${refindBinary} } fi -- cgit 1.4.1 From ea34fe21e18f87dc8b333672f23edf2bcee98cd7 Mon Sep 17 00:00:00 2001 From: jakobrs Date: Tue, 8 Jun 2021 18:52:02 +0200 Subject: treewide: Use `fileSystems..depends` option where necessary --- nixos/modules/installer/cd-dvd/iso-image.nix | 6 ++++++ nixos/modules/installer/netboot/netboot.nix | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'nixos/modules/installer/cd-dvd/iso-image.nix') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index c2836b5a9a1..4e5d888c4bb 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -680,6 +680,12 @@ in "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" ]; diff --git a/nixos/modules/installer/netboot/netboot.nix b/nixos/modules/installer/netboot/netboot.nix index fa074fdfcc6..238ab6d0617 100644 --- a/nixos/modules/installer/netboot/netboot.nix +++ b/nixos/modules/installer/netboot/netboot.nix @@ -57,6 +57,12 @@ with lib; "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" "overlay" ]; -- cgit 1.4.1