Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iso-image: Fix GRUB graphical menu on AArch64 #119974

Merged
merged 5 commits into from May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 42 additions & 11 deletions nixos/modules/installer/cd-dvd/iso-image.nix
Expand Up @@ -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;
samueldr marked this conversation as resolved.
Show resolved Hide resolved

# 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}"
Expand All @@ -186,7 +188,10 @@ 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
set with_fonts=true
fi
if [ "\$textmode" != "true" -a "\$with_fonts" == "true" ]; then
samueldr marked this conversation as resolved.
Show resolved Hide resolved
# 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.
Expand All @@ -207,11 +212,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
Expand Down Expand Up @@ -264,6 +269,8 @@ let

cat <<EOF > $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
Expand All @@ -273,8 +280,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
Expand Down Expand Up @@ -337,11 +364,15 @@ let
}
}

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
}
${lib.optionalString (refindBinary != null) ''
# 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
clear
Expand Down
8 changes: 8 additions & 0 deletions pkgs/tools/misc/grub/2.0x.nix
@@ -1,6 +1,8 @@
{ lib, stdenv, fetchgit, flex, bison, python3, autoconf, automake, gnulib, libtool
, gettext, ncurses, libusb-compat-0_1, freetype, qemu, lvm2, unifont, pkg-config
, buildPackages
, fetchpatch
, pkgsBuildBuild
, nixosTests
, fuse # only needed for grub-mount
, runtimeShell
Expand Down Expand Up @@ -55,6 +57,12 @@ stdenv.mkDerivation rec {

patches = [
./fix-bash-completion.patch
(fetchpatch {
name = "Add-hidden-menu-entries.patch";
# https://lists.gnu.org/archive/html/grub-devel/2016-04/msg00089.html
url = "https://marc.info/?l=grub-devel&m=146193404929072&q=mbox";
sha256 = "00wa1q5adiass6i0x7p98vynj9vsz1w0gn1g4dgz89v35mpyw2bi";
})
];

postPatch = if kbdcompSupport then ''
Expand Down