Files
nixpkgs/nixos/tests/grub/graphical.nix
Tom Fitzhenry 889571cf97 nixos/tests/grub: split into a directory and expand coverage
Move nixos/tests/grub.nix to nixos/tests/grub/basic.nix unchanged, and add
new GRUB boot tests under nixos/tests/grub/:

- hashed-password: GRUB user authentication with a
  users.<name>.hashedPasswordFile (a grub-mkpasswd-pbkdf2 hash). The hash is
  generated in a derivation and passed by store path (via toString) rather
  than read at evaluation time, to avoid import-from-derivation. Kept separate
  from basic so each login is exercised on its own VM boot rather than
  multiplexed onto one menu.
- efi: boot through GRUB's EFI support.
- graphical: verify GRUB renders its menu in graphical (gfxterm) mode. A
  marker string is baked into the splash image (which GRUB only draws in
  gfxterm) and read back via OCR, so a silent fallback to text mode would
  fail the test rather than pass it.
- mirrored-boots: verify GRUB is installed and configured on every path
  in boot.loader.grub.mirroredBoots.

Assisted-by: Claude Opus 4.8
2026-07-22 11:34:12 +00:00

58 lines
1.9 KiB
Nix

{ lib, ... }:
{
name = "grub-graphical";
meta = with lib.maintainers; {
maintainers = [
tomfitzhenry
rnhmjoj
];
};
nodes.machine =
{ pkgs, ... }:
let
# GRUB only draws a background image when it is in graphical gfxterm
# mode. Bake a marker string into the splash so the OCR check below can
# only succeed when gfxterm actually rendered it; a silent fallback to
# text mode would show the plain menu without this image (and its text).
#
# The image must be an 8-bit sRGB PNG, otherwise GRUB's png module fails
# to load it and silently falls back to its default (non-graphical) menu.
splash = pkgs.runCommand "grub-gfxterm-splash.png" { nativeBuildInputs = [ pkgs.imagemagick ]; } ''
magick -size 1024x768 xc:'#2d2d2d' \
-font ${pkgs.dejavu_fonts.minimal}/share/fonts/truetype/DejaVuSans.ttf \
-gravity south -pointsize 48 -fill white \
-annotate +0+150 'GFXTERMOK' \
-depth 8 -type TrueColor PNG24:$out
'';
in
{
virtualisation.useBootLoader = true;
# Leave the menu up long enough for OCR to catch it; we boot early with a
# keypress once it has, so this does not slow the test down.
boot.loader.timeout = 30;
boot.loader.grub = {
enable = true;
splashImage = splash;
};
};
enableOCR = true;
testScript = ''
machine.start()
with subtest("GRUB renders its menu graphically (gfxterm), showing the splash"):
# The marker text lives inside the background image, so reading it back
# proves GRUB displayed the image rather than falling back to text mode.
machine.wait_for_text("GFXTERMOK")
machine.screenshot("grub_gfxterm")
with subtest("Machine boots into NixOS from GRUB"):
machine.send_key("ret")
machine.wait_for_unit("multi-user.target")
'';
}