Merge pull request #119974 from samueldr/feature/grub-gfx-aarch64

iso-image: Fix GRUB graphical menu on AArch64

authored by

Samuel Dionne-Riel and committed by
GitHub
385dc32f 54d0d2b4

+50 -11
+42 -11
nixos/modules/installer/cd-dvd/iso-image.nix
··· 162 162 isolinuxCfg = concatStringsSep "\n" 163 163 ([ baseIsolinuxCfg ] ++ optional config.boot.loader.grub.memtest86.enable isolinuxMemtest86Entry); 164 164 165 + refindBinary = if targetArch == "x64" || targetArch == "aa64" then "refind_${targetArch}.efi" else null; 166 + 165 167 # Setup instructions for rEFInd. 166 168 refind = 167 - if targetArch == "x64" then 169 + if refindBinary != null then 168 170 '' 169 171 # Adds rEFInd to the ISO. 170 - cp -v ${pkgs.refind}/share/refind/refind_x64.efi $out/EFI/boot/ 172 + cp -v ${pkgs.refind}/share/refind/${refindBinary} $out/EFI/boot/ 171 173 '' 172 174 else 173 175 "# No refind for ${targetArch}" ··· 186 188 187 189 # Fonts can be loaded? 188 190 # (This font is assumed to always be provided as a fallback by NixOS) 189 - if loadfont (hd0)/EFI/boot/unicode.pf2; then 191 + if loadfont /EFI/boot/unicode.pf2; then 192 + set with_fonts=true 193 + fi 194 + if [ "\$textmode" != "true" -a "\$with_fonts" == "true" ]; then 190 195 # Use graphical term, it can be either with background image or a theme. 191 196 # input is "console", while output is "gfxterm". 192 197 # This enables "serial" input and output only when possible. ··· 207 212 ${ # When there is a theme configured, use it, otherwise use the background image. 208 213 if config.isoImage.grubTheme != null then '' 209 214 # Sets theme. 210 - set theme=(hd0)/EFI/boot/grub-theme/theme.txt 215 + set theme=/EFI/boot/grub-theme/theme.txt 211 216 # Load theme fonts 212 - $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (hd0)/EFI/boot/grub-theme/%P\n") 217 + $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont /EFI/boot/grub-theme/%P\n") 213 218 '' else '' 214 - if background_image (hd0)/EFI/boot/efi-background.png; then 219 + if background_image /EFI/boot/efi-background.png; then 215 220 # Black background means transparent background when there 216 221 # is a background image set... This seems undocumented :( 217 222 set color_normal=black/black ··· 264 269 265 270 cat <<EOF > $out/EFI/boot/grub.cfg 266 271 272 + set with_fonts=false 273 + set textmode=false 267 274 # If you want to use serial for "terminal_*" commands, you need to set one up: 268 275 # Example manual configuration: 269 276 # → serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 ··· 273 280 export with_serial 274 281 clear 275 282 set timeout=10 283 + 284 + # This message will only be viewable when "gfxterm" is not used. 285 + echo "" 286 + echo "Loading graphical boot menu..." 287 + echo "" 288 + echo "Press 't' to use the text boot menu on this console..." 289 + echo "" 290 + 276 291 ${grubMenuCfg} 277 292 293 + hiddenentry 'Text mode' --hotkey 't' { 294 + loadfont /EFI/boot/unicode.pf2 295 + set textmode=true 296 + terminal_output gfxterm console 297 + } 298 + hiddenentry 'GUI mode' --hotkey 'g' { 299 + $(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont /EFI/boot/grub-theme/%P\n") 300 + set textmode=false 301 + terminal_output gfxterm 302 + } 303 + 304 + 278 305 # If the parameter iso_path is set, append the findiso parameter to the kernel 279 306 # line. We need this to allow the nixos iso to be booted from grub directly. 280 307 if [ \''${iso_path} ] ; then ··· 337 364 } 338 365 } 339 366 340 - menuentry 'rEFInd' --class refind { 341 - # UUID is hard-coded in the derivation. 342 - search --set=root --no-floppy --fs-uuid 1234-5678 343 - chainloader (\$root)/EFI/boot/refind_x64.efi 344 - } 367 + ${lib.optionalString (refindBinary != null) '' 368 + # GRUB apparently cannot do "chainloader" operations on "CD". 369 + if [ "\$root" != "cd0" ]; then 370 + menuentry 'rEFInd' --class refind { 371 + # \$root defaults to the drive the EFI is found on. 372 + chainloader (\$root)/EFI/boot/${refindBinary} 373 + } 374 + fi 375 + ''} 345 376 menuentry 'Firmware Setup' --class settings { 346 377 fwsetup 347 378 clear
+8
pkgs/tools/misc/grub/2.0x.nix
··· 1 1 { lib, stdenv, fetchgit, flex, bison, python3, autoconf, automake, gnulib, libtool 2 2 , gettext, ncurses, libusb-compat-0_1, freetype, qemu, lvm2, unifont, pkg-config 3 3 , buildPackages 4 + , fetchpatch 5 + , pkgsBuildBuild 4 6 , nixosTests 5 7 , fuse # only needed for grub-mount 6 8 , runtimeShell ··· 55 57 56 58 patches = [ 57 59 ./fix-bash-completion.patch 60 + (fetchpatch { 61 + name = "Add-hidden-menu-entries.patch"; 62 + # https://lists.gnu.org/archive/html/grub-devel/2016-04/msg00089.html 63 + url = "https://marc.info/?l=grub-devel&m=146193404929072&q=mbox"; 64 + sha256 = "00wa1q5adiass6i0x7p98vynj9vsz1w0gn1g4dgz89v35mpyw2bi"; 65 + }) 58 66 ]; 59 67 60 68 postPatch = if kbdcompSupport then ''