Merge pull request #14957 from dezgeg/gummiboot-test

NixOS installer tests: Add a test using Gummiboot
This commit is contained in:
zimbatm 2016-05-05 21:14:30 +01:00
commit f076f36f8f

View file

@ -7,7 +7,7 @@ with pkgs.lib;
let let
# The configuration to install. # The configuration to install.
makeConfig = { grubVersion, grubDevice, grubIdentifier makeConfig = { bootLoader, grubVersion, grubDevice, grubIdentifier
, extraConfig, forceGrubReinstallCount ? 0 , extraConfig, forceGrubReinstallCount ? 0
}: }:
pkgs.writeText "configuration.nix" '' pkgs.writeText "configuration.nix" ''
@ -18,15 +18,21 @@ let
<nixpkgs/nixos/modules/testing/test-instrumentation.nix> <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
]; ];
boot.loader.grub.version = ${toString grubVersion}; ${optionalString (bootLoader == "grub") ''
${optionalString (grubVersion == 1) '' boot.loader.grub.version = ${toString grubVersion};
boot.loader.grub.splashImage = null; ${optionalString (grubVersion == 1) ''
''} boot.loader.grub.splashImage = null;
boot.loader.grub.device = "${grubDevice}"; ''}
boot.loader.grub.extraConfig = "serial; terminal_output.serial"; boot.loader.grub.device = "${grubDevice}";
boot.loader.grub.fsIdentifier = "${grubIdentifier}"; boot.loader.grub.extraConfig = "serial; terminal_output.serial";
boot.loader.grub.fsIdentifier = "${grubIdentifier}";
boot.loader.grub.configurationLimit = 100 + ${toString forceGrubReinstallCount}; boot.loader.grub.configurationLimit = 100 + ${toString forceGrubReinstallCount};
''}
${optionalString (bootLoader == "gummiboot") ''
boot.loader.gummiboot.enable = true;
''}
hardware.enableAllFirmware = lib.mkForce false; hardware.enableAllFirmware = lib.mkForce false;
@ -42,7 +48,7 @@ let
# disk, and then reboot from the hard disk. It's parameterized with # disk, and then reboot from the hard disk. It's parameterized with
# a test script fragment `createPartitions', which must create # a test script fragment `createPartitions', which must create
# partitions and filesystems. # partitions and filesystems.
testScriptFun = { createPartitions, grubVersion, grubDevice testScriptFun = { bootLoader, createPartitions, grubVersion, grubDevice
, grubIdentifier, preBootCommands, extraConfig , grubIdentifier, preBootCommands, extraConfig
}: }:
let let
@ -50,7 +56,8 @@ let
qemuFlags = qemuFlags =
(if system == "x86_64-linux" then "-m 768 " else "-m 512 ") + (if system == "x86_64-linux" then "-m 768 " else "-m 512 ") +
(optionalString (system == "x86_64-linux") "-cpu kvm64 "); (optionalString (system == "x86_64-linux") "-cpu kvm64 ");
hdFlags = ''hda => "vm-state-machine/machine.qcow2", hdaInterface => "${iface}", ''; hdFlags = ''hda => "vm-state-machine/machine.qcow2", hdaInterface => "${iface}", ''
+ optionalString (bootLoader == "gummiboot") ''bios => "${pkgs.OVMF}/FV/OVMF.fd", '';
in in
'' ''
$machine->start; $machine->start;
@ -73,7 +80,7 @@ let
$machine->succeed("cat /mnt/etc/nixos/hardware-configuration.nix >&2"); $machine->succeed("cat /mnt/etc/nixos/hardware-configuration.nix >&2");
$machine->copyFileFromHost( $machine->copyFileFromHost(
"${ makeConfig { inherit grubVersion grubDevice grubIdentifier extraConfig; } }", "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier extraConfig; } }",
"/mnt/etc/nixos/configuration.nix"); "/mnt/etc/nixos/configuration.nix");
# Perform the installation. # Perform the installation.
@ -97,7 +104,11 @@ let
# Did /boot get mounted? # Did /boot get mounted?
$machine->waitForUnit("local-fs.target"); $machine->waitForUnit("local-fs.target");
$machine->succeed("test -e /boot/grub"); ${if bootLoader == "grub" then
''$machine->succeed("test -e /boot/grub");''
else
''$machine->succeed("test -e /boot/loader/loader.conf");''
}
# Check whether /root has correct permissions. # Check whether /root has correct permissions.
$machine->succeed("stat -c '%a' /root") =~ /700/ or die; $machine->succeed("stat -c '%a' /root") =~ /700/ or die;
@ -114,7 +125,7 @@ let
# We need to a writable nix-store on next boot. # We need to a writable nix-store on next boot.
$machine->copyFileFromHost( $machine->copyFileFromHost(
"${ makeConfig { inherit grubVersion grubDevice grubIdentifier extraConfig; forceGrubReinstallCount = 1; } }", "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier extraConfig; forceGrubReinstallCount = 1; } }",
"/etc/nixos/configuration.nix"); "/etc/nixos/configuration.nix");
# Check whether nixos-rebuild works. # Check whether nixos-rebuild works.
@ -132,7 +143,7 @@ let
${preBootCommands} ${preBootCommands}
$machine->waitForUnit("multi-user.target"); $machine->waitForUnit("multi-user.target");
$machine->copyFileFromHost( $machine->copyFileFromHost(
"${ makeConfig { inherit grubVersion grubDevice grubIdentifier extraConfig; forceGrubReinstallCount = 2; } }", "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier extraConfig; forceGrubReinstallCount = 2; } }",
"/etc/nixos/configuration.nix"); "/etc/nixos/configuration.nix");
$machine->succeed("nixos-rebuild boot >&2"); $machine->succeed("nixos-rebuild boot >&2");
$machine->shutdown; $machine->shutdown;
@ -148,8 +159,9 @@ let
makeInstallerTest = name: makeInstallerTest = name:
{ createPartitions, preBootCommands ? "", extraConfig ? "" { createPartitions, preBootCommands ? "", extraConfig ? ""
, grubVersion ? 2, grubDevice ? "/dev/vda" , bootLoader ? "grub" # either "grub" or "gummiboot"
, grubIdentifier ? "uuid", enableOCR ? false, meta ? {} , grubVersion ? 2, grubDevice ? "/dev/vda", grubIdentifier ? "uuid"
, enableOCR ? false, meta ? {}
}: }:
makeTest { makeTest {
inherit enableOCR; inherit enableOCR;
@ -183,6 +195,8 @@ let
virtualisation.qemu.diskInterface = virtualisation.qemu.diskInterface =
if grubVersion == 1 then "scsi" else "virtio"; if grubVersion == 1 then "scsi" else "virtio";
boot.loader.gummiboot.enable = mkIf (bootLoader == "gummiboot") true;
hardware.enableAllFirmware = mkForce false; hardware.enableAllFirmware = mkForce false;
# The test cannot access the network, so any packages we # The test cannot access the network, so any packages we
@ -198,8 +212,8 @@ let
pkgs.perlPackages.XMLLibXML pkgs.perlPackages.XMLLibXML
pkgs.perlPackages.ListCompare pkgs.perlPackages.ListCompare
] ]
++ optional (grubVersion == 1) pkgs.grub ++ optional (bootLoader == "grub" && grubVersion == 1) pkgs.grub
++ optionals (grubVersion == 2) [ pkgs.grub2 pkgs.grub2_efi ]; ++ optionals (bootLoader == "grub" && grubVersion == 2) [ pkgs.grub2 pkgs.grub2_efi ];
nix.binaryCaches = mkForce [ ]; nix.binaryCaches = mkForce [ ];
}; };
@ -207,8 +221,8 @@ let
}; };
testScript = testScriptFun { testScript = testScriptFun {
inherit createPartitions preBootCommands grubVersion inherit bootLoader createPartitions preBootCommands
grubDevice grubIdentifier extraConfig; grubVersion grubDevice grubIdentifier extraConfig;
}; };
}; };
@ -236,6 +250,29 @@ in {
''; '';
}; };
# Simple GPT/UEFI configuration using Gummiboot with 3 partitions: ESP, swap & root filesystem
simpleUefiGummiboot = makeInstallerTest "simpleUefiGummiboot"
{ createPartitions =
''
$machine->succeed(
"parted /dev/vda mklabel gpt",
"parted -s /dev/vda -- mkpart ESP fat32 1M 50MiB", # /boot
"parted -s /dev/vda -- set 1 boot on",
"parted -s /dev/vda -- mkpart primary linux-swap 50MiB 1024MiB",
"parted -s /dev/vda -- mkpart primary ext2 1024MiB -1MiB", # /
"udevadm settle",
"mkswap /dev/vda2 -L swap",
"swapon -L swap",
"mkfs.ext3 -L nixos /dev/vda3",
"mount LABEL=nixos /mnt",
"mkfs.vfat -n BOOT /dev/vda1",
"mkdir -p /mnt/boot",
"mount LABEL=BOOT /mnt/boot",
);
'';
bootLoader = "gummiboot";
};
# Same as the previous, but now with a separate /boot partition. # Same as the previous, but now with a separate /boot partition.
separateBoot = makeInstallerTest "separateBoot" separateBoot = makeInstallerTest "separateBoot"
{ createPartitions = { createPartitions =