1{ lib, ... }:
2{
3 name = "grub";
4
5 meta = with lib.maintainers; {
6 maintainers = [ rnhmjoj ];
7 };
8
9 nodes.machine =
10 { ... }:
11 {
12 virtualisation.useBootLoader = true;
13
14 boot.loader.timeout = null;
15 boot.loader.grub = {
16 enable = true;
17 users.alice.password = "supersecret";
18
19 # OCR is not accurate enough
20 extraConfig = "serial; terminal_output serial";
21 };
22 };
23
24 testScript = ''
25 def grub_login_as(user, password):
26 """
27 Enters user and password to log into GRUB
28 """
29 machine.wait_for_console_text("Enter username:")
30 machine.send_chars(user + "\n")
31 machine.wait_for_console_text("Enter password:")
32 machine.send_chars(password + "\n")
33
34
35 def grub_select_all_configurations():
36 """
37 Selects "All configurations" from the GRUB menu
38 to trigger a login request.
39 """
40 machine.send_monitor_command("sendkey down")
41 machine.send_monitor_command("sendkey ret")
42
43
44 machine.start()
45
46 # wait for grub screen
47 machine.wait_for_console_text("GNU GRUB")
48
49 grub_select_all_configurations()
50 with subtest("Invalid credentials are rejected"):
51 grub_login_as("wronguser", "wrongsecret")
52 machine.wait_for_console_text("error: access denied.")
53
54 grub_select_all_configurations()
55 with subtest("Valid credentials are accepted"):
56 grub_login_as("alice", "supersecret")
57 machine.send_chars("\n") # press enter to boot
58 machine.wait_for_console_text("Linux version")
59
60 with subtest("Machine boots correctly"):
61 machine.wait_for_unit("multi-user.target")
62 '';
63}