From fad94acaa895bc702e6920579b86c8d9bd9bb42f Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 16:49:47 -0400 Subject: [PATCH 01/10] nixos/iso-image: Make modules list easier to manage With a bash array. This change is morally a no-op. --- nixos/modules/installer/cd-dvd/iso-image.nix | 73 ++++++++++++++++---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index c430048d6598..7f56421ba139 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -250,18 +250,61 @@ let touch $out/EFI/nixos-installer-image # ALWAYS required modules. - MODULES="fat iso9660 part_gpt part_msdos \ - normal boot linux configfile loopback chain halt \ - efifwsetup efi_gop \ - ls search search_label search_fs_uuid search_fs_file \ - gfxmenu gfxterm gfxterm_background gfxterm_menu test all_video loadenv \ - exfat ext2 ntfs btrfs hfsplus udf \ - videoinfo png \ - echo serial \ - " + MODULES=( + # Basic modules for filesystems and partition schemes + "fat" + "iso9660" + "part_gpt" + "part_msdos" + "exfat" + "ext2" + "ntfs" + "btrfs" + "hfsplus" + "udf" + + # Basic stuff + "normal" + "boot" + "linux" + "configfile" + "loopback" + "chain" + "halt" + + # Allows rebooting into firmware setup interface + "efifwsetup" + + # EFI Graphics Output Protocol + "efi_gop" + + # User commands + "ls" + + # System commands + "search" + "search_label" + "search_fs_uuid" + "search_fs_file" + "echo" + "serial" + + # Graphical mode stuff + "gfxmenu" + "gfxterm" + "gfxterm_background" + "gfxterm_menu" + "test" + "loadenv" + "all_video" + "videoinfo" + + # File types for graphical mode + "png" + ) echo "Building GRUB with modules:" - for mod in $MODULES; do + for mod in ''${MODULES[@]}; do echo " - $mod" done @@ -270,14 +313,18 @@ let for mod in efi_uga; do if [ -f ${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget}/$mod.mod ]; then echo " - $mod" - MODULES+=" $mod" + MODULES+=("$mod") fi done # Make our own efi program, we can't rely on "grub-install" since it seems to # probe for devices, even with --skip-fs-probe. - 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 + 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/ cat < $out/EFI/boot/grub.cfg From 080bff8159de296aada63205a64d5b08d309b345 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:00:34 -0400 Subject: [PATCH 02/10] nixos/iso-image: Use intrinsic UEFI console for serial output in GRUB The `serial` console hangs on some systems. Unknown why. Anyway, the way this worked right now relied on it telling the user on the UEFI console how to enable it. So if I understand it correctly, it will not cause any regression there. --- nixos/modules/installer/cd-dvd/iso-image.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 7f56421ba139..99c3779119f4 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -201,11 +201,11 @@ let 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. # Otherwise the failure mode is to not even enable gfxterm. + # Note that "with_serial" relies on the EFI console. if test "\$with_serial" == "yes"; then - terminal_output gfxterm serial - terminal_input console serial + terminal_output console + terminal_input console else terminal_output gfxterm terminal_input console @@ -336,12 +336,11 @@ let # → serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 # This uses the defaults, and makes the serial terminal available. set with_serial=no - if serial; then set with_serial=yes ;fi export with_serial clear set timeout=${toString grubEfiTimeout} - # This message will only be viewable when "gfxterm" is not used. + # This message will only be viewable on the default (UEFI) console. echo "" echo "Loading graphical boot menu..." echo "" @@ -352,12 +351,14 @@ let hiddenentry 'Text mode' --hotkey 't' { loadfont (\$root)/EFI/boot/unicode.pf2 + set with_serial=yes set textmode=true - terminal_output gfxterm console + terminal_output console } hiddenentry 'GUI mode' --hotkey 'g' { $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n") set textmode=false + set with_serial=no terminal_output gfxterm } From 8623ac4656488548da1d1ecaed3c386b1bfcb24d Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:01:40 -0400 Subject: [PATCH 03/10] nixos/iso-image: Add common display resolutions Hey, look at that, grub is the correct way around on a Steam Deck! --- nixos/modules/installer/cd-dvd/iso-image.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 99c3779119f4..326b133dbae7 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -185,10 +185,14 @@ let # So instead we'll list a lot of possibly valid modes :/ #"3840x2160" #"2560x1440" + "1920x1200" "1920x1080" "1366x768" + "1280x800" "1280x720" + "1200x1920" "1024x768" + "800x1280" "800x600" "auto" ]} From dd936c21d78298e9e693847d522d404f412f9e0b Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:02:23 -0400 Subject: [PATCH 04/10] nixos/iso-image: Check GRUB config on build --- nixos/modules/installer/cd-dvd/iso-image.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 326b133dbae7..38e0f1755e70 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -452,6 +452,8 @@ let } EOF + grub-script-check $out/EFI/boot/grub.cfg + ${refind} ''; From d64b03a339138394917e9ce224895077560918ff Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:02:43 -0400 Subject: [PATCH 05/10] nixos/iso-image: Re-enable graphics mode Which ***anyway*** was not disabled correctly. Following changes will actually disable it. What this did was disable the "themed" menu driver, but still continued relying on the gfxterm infra, which in itself is why things were ugly and weird. --- nixos/modules/installer/cd-dvd/iso-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 38e0f1755e70..2be7020cb8b2 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -713,7 +713,7 @@ in }; isoImage.graphicalGrub = mkOption { - default = false; + default = true; type = types.bool; example = true; description = lib.mdDoc '' From 47ae07a23fdea96595a50033d6a8bff9341ff9e4 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:04:52 -0400 Subject: [PATCH 06/10] nixos/iso-image: Drop all unneeded FS modules It's not like the iso-image will be anything else than isohybrid FAT+iso9660... --- nixos/modules/installer/cd-dvd/iso-image.nix | 6 ------ 1 file changed, 6 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 2be7020cb8b2..ee38d41982a4 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -260,12 +260,6 @@ let "iso9660" "part_gpt" "part_msdos" - "exfat" - "ext2" - "ntfs" - "btrfs" - "hfsplus" - "udf" # Basic stuff "normal" From 07fb2f4a973765b5890b79316daf3ca4a4671862 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:35:47 -0400 Subject: [PATCH 07/10] nixos/iso-image: Tear down GOP and rely on console for Linux boot This solves an issue where *some systems* (tested on Steam Deck) the EFI GOP may be broken during stage-1. --- nixos/modules/installer/cd-dvd/iso-image.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index ee38d41982a4..1c38e29aefa4 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -24,6 +24,9 @@ let # Name appended to menuentry defaults to params if no specific name given. option.name or (optionalString (option ? params) "(${option.params})") }' ${optionalString (option ? class) " --class ${option.class}"} { + # Fallback to UEFI console for boot, efifb sometimes has difficulties. + terminal_output console + linux ${defaults.image} \''${isoboot} ${defaults.params} ${ option.params or "" } From 16d640c81044ca439b6356156516a7885c1864af Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 17:46:57 -0400 Subject: [PATCH 08/10] CODEOWNERS: Add myself for installer images --- .github/CODEOWNERS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9a3543bb80d7..f316678cd023 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -101,6 +101,10 @@ /nixos/lib/systemd-*.nix @NixOS/systemd /pkgs/os-specific/linux/systemd @NixOS/systemd +# Images and installer media +/nixos/modules/installer/cd-dvd/ @samueldr +/nixos/modules/installer/sd-card/ @samueldr + # Updaters ## update.nix /maintainers/scripts/update.nix @jtojnar From 7fa7158c600e419d8f4ed47d6bc989d2a56e4932 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 18:11:31 -0400 Subject: [PATCH 09/10] nixos/iso-image: graphicalGrub -> forceTextMode This helps keep logic simpler, as what we do is forcing text mode, which means the non-default case is `truthy`, making things easier to digest in the config file. Also renaming this option is considered "internal", since it lives only within the `iso-image` namespace, and also not a breaking change since it was not part of a stable release. --- nixos/modules/installer/cd-dvd/iso-image.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 1c38e29aefa4..2b70b75d7ccd 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -331,7 +331,7 @@ let cat < $out/EFI/boot/grub.cfg set with_fonts=false - set textmode=${boolToString (!config.isoImage.graphicalGrub)} + set textmode=${boolToString (config.isoImage.forceTextMode)} # 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 @@ -709,13 +709,17 @@ in ''; }; - isoImage.graphicalGrub = mkOption { - default = true; + isoImage.forceTextMode = mkOption { + default = false; type = types.bool; example = true; description = lib.mdDoc '' - Whether to use textmode or graphical grub. - false means we use textmode grub. + Whether to use text mode instead of graphical grub. + A value of `true` means graphical mode is not tried to be used. + + This is useful for validating that graphics mode usage is not at the root cause of a problem with the iso image. + + If text mode is required off-handedly (e.g. for serial use) you can use the `T` key, after being prompted, to use text mode for the current boot. ''; }; From 2de1bd778ccc90cef078970106bf7fc67fb23c54 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 14 Aug 2023 19:43:20 -0400 Subject: [PATCH 10/10] nixos/iso-image: Remove leftover false dichotomy between console/serial Relying on the built-in UEFI console here was already necessary, so we are losing nothing by removing the needless `serial` call, which hung some systems. This also makes the implementation much easier to understand. Also, no ugly-font menu anymore! --- nixos/modules/installer/cd-dvd/iso-image.nix | 38 ++++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 2b70b75d7ccd..0b5135c088ea 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -200,25 +200,13 @@ let "auto" ]} - # Fonts can be loaded? - # (This font is assumed to always be provided as a fallback by NixOS) - if loadfont (\$root)/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". - # Otherwise the failure mode is to not even enable gfxterm. - # Note that "with_serial" relies on the EFI console. - if test "\$with_serial" == "yes"; then - terminal_output console - terminal_input console - else - terminal_output gfxterm - terminal_input console - fi + if [ "\$textmode" == "false" ]; then + terminal_output gfxterm + terminal_input console else - # Sets colors for the non-graphical term. + terminal_output console + terminal_input console + # Sets colors for console term. set menu_color_normal=cyan/blue set menu_color_highlight=white/blue fi @@ -288,6 +276,9 @@ let "search_fs_uuid" "search_fs_file" "echo" + + # We're not using it anymore, but we'll leave it in so it can be used + # by user, with the console using "C" "serial" # Graphical mode stuff @@ -330,17 +321,10 @@ let cat < $out/EFI/boot/grub.cfg - set with_fonts=false set textmode=${boolToString (config.isoImage.forceTextMode)} - # 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 - # This uses the defaults, and makes the serial terminal available. - set with_serial=no - export with_serial - clear set timeout=${toString grubEfiTimeout} + clear # This message will only be viewable on the default (UEFI) console. echo "" echo "Loading graphical boot menu..." @@ -352,14 +336,12 @@ let hiddenentry 'Text mode' --hotkey 't' { loadfont (\$root)/EFI/boot/unicode.pf2 - set with_serial=yes set textmode=true terminal_output console } hiddenentry 'GUI mode' --hotkey 'g' { $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n") set textmode=false - set with_serial=no terminal_output gfxterm }