Unverified Commit 7e6d6f77 authored by rnhmjoj's avatar rnhmjoj
Browse files

nixos/tests/grub: check boot loader entries

parent 435a72e4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -463,7 +463,7 @@ in {
  greetd-no-shadow = handleTest ./greetd-no-shadow.nix {};
  grocy = handleTest ./grocy.nix {};
  grow-partition = runTest ./grow-partition.nix;
  grub = handleTest ./grub.nix {};
  grub = import ./grub.nix { inherit pkgs runTest; };
  guacamole-server = handleTest ./guacamole-server.nix {};
  guix = handleTest ./guix {};
  gvisor = handleTest ./gvisor.nix {};
+116 −53
Original line number Diff line number Diff line
import ./make-test-python.nix ({ lib, ... }: {
  name = "grub";
{ pkgs, runTest }:

  meta = with lib.maintainers; {
    maintainers = [ rnhmjoj ];
  };
{
  # Basic GRUB setup with BIOS and a password
  basic = runTest {
    name = "grub-basic";
    meta.maintainers = with pkgs.lib.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";
      };
@@ -57,4 +56,68 @@ import ./make-test-python.nix ({ lib, ... }: {
      with subtest("Machine boots correctly"):
          machine.wait_for_unit("multi-user.target")
    '';
})
    };

  # Test boot loader entries on EFI
  bls-efi = runTest {
    name = "grub-bls-efi";
    meta.maintainers = with pkgs.lib.maintainers; [ rnhmjoj ];

    nodes.machine = { pkgs, ... }: {
      virtualisation.useBootLoader = true;
      virtualisation.useEFIBoot = true;
      boot.loader.efi.canTouchEfiVariables = true;
      boot.loader.grub.enable = true;
      boot.loader.grub.efiSupport = true;
    };

    testScript = ''
      with subtest("Machine boots correctly"):
          machine.wait_for_unit("multi-user.target")

      with subtest("Boot entries are installed"):
          entries = machine.succeed("bootctl list")
          print(entries)
          error = "NixOS boot entry not found in bootctl list."
          assert "version: Generation 1" in entries, error

      with subtest("systemctl kexec can detect the kernel"):
          machine.succeed("systemctl kexec --dry-run")

      with subtest("systemctl kexec really works"):
          machine.execute("systemctl kexec", check_return=False)
          machine.connected = False
          machine.connect()
          machine.wait_for_unit("multi-user.target")
    '';
  };

  # Test boot loader entries on BIOS
  bls-bios = runTest {
    name = "grub-bls-bios";
    meta.maintainers = with pkgs.lib.maintainers; [ rnhmjoj ];

    nodes.machine = { pkgs, ... }: {
      virtualisation.useBootLoader = true;
      boot.loader.grub.enable = true;
    };

    testScript = ''
      with subtest("Machine boots correctly"):
          machine.wait_for_unit("multi-user.target")

      with subtest("Boot entries are installed"):
          machine.succeed("test -f /boot/loader/entries/nixos-generation-1.conf")

      with subtest("systemctl kexec can detect the kernel"):
          machine.succeed("systemctl kexec --dry-run")

      with subtest("systemctl kexec really works"):
          machine.execute("systemctl kexec", check_return=False)
          machine.connected = False
          machine.connect()
          machine.wait_for_unit("multi-user.target")
    '';
  };

}