mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-08-26 18:24:53 +00:00
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
64 lines
1.6 KiB
Nix
64 lines
1.6 KiB
Nix
{ lib, ... }:
|
|
{
|
|
name = "grub";
|
|
|
|
meta = with lib.maintainers; {
|
|
maintainers = [ rnhmjoj ];
|
|
};
|
|
|
|
nodes.machine =
|
|
{ ... }:
|
|
{
|
|
virtualisation.useBootLoader = true;
|
|
|
|
boot.loader.timeout = null;
|
|
boot.loader.grub = {
|
|
enable = true;
|
|
users.alice.password = "supersecret";
|
|
|
|
# OCR is not accurate enough
|
|
extraConfig = "serial; terminal_output serial";
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
def grub_login_as(user, password):
|
|
"""
|
|
Enters user and password to log into GRUB
|
|
"""
|
|
machine.wait_for_console_text("Enter username:")
|
|
machine.send_chars(user + "\n")
|
|
machine.wait_for_console_text("Enter password:")
|
|
machine.send_chars(password + "\n")
|
|
|
|
|
|
def grub_select_all_configurations():
|
|
"""
|
|
Selects "All configurations" from the GRUB menu
|
|
to trigger a login request.
|
|
"""
|
|
machine.send_monitor_command("sendkey down")
|
|
machine.send_monitor_command("sendkey ret")
|
|
|
|
|
|
machine.start()
|
|
|
|
# wait for grub screen
|
|
machine.wait_for_console_text("GNU GRUB")
|
|
|
|
grub_select_all_configurations()
|
|
with subtest("Invalid credentials are rejected"):
|
|
grub_login_as("wronguser", "wrongsecret")
|
|
machine.wait_for_console_text("error: access denied.")
|
|
|
|
grub_select_all_configurations()
|
|
with subtest("Valid credentials are accepted"):
|
|
grub_login_as("alice", "supersecret")
|
|
machine.send_chars("\n") # press enter to boot
|
|
machine.wait_for_console_text("Linux version")
|
|
|
|
with subtest("Machine boots correctly"):
|
|
machine.wait_for_unit("multi-user.target")
|
|
'';
|
|
}
|