From e9be441b62418783a1ea051588772889a7ac71d4 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Wed, 30 Apr 2014 11:24:46 +0200
Subject: [PATCH] Merge the EFI test into tests/installer.nix
---
nixos/release-combined.nix | 1 +
nixos/release.nix | 1 +
nixos/tests/efi-installer.nix | 126 ----------------------------------
nixos/tests/installer.nix | 82 +++++++++++++++++-----
4 files changed, 66 insertions(+), 144 deletions(-)
delete mode 100644 nixos/tests/efi-installer.nix
diff --git a/nixos/release-combined.nix b/nixos/release-combined.nix
index 8a62bce80a2..05664e068f8 100644
--- a/nixos/release-combined.nix
+++ b/nixos/release-combined.nix
@@ -48,6 +48,7 @@ in rec {
(all nixos.tests.firefox)
(all nixos.tests.firewall)
(all nixos.tests.gnome3)
+ (all nixos.tests.installer.efi)
(all nixos.tests.installer.grub1)
(all nixos.tests.installer.lvm)
(all nixos.tests.installer.separateBoot)
diff --git a/nixos/release.nix b/nixos/release.nix
index 81a5f06f403..0ce39dff24f 100644
--- a/nixos/release.nix
+++ b/nixos/release.nix
@@ -217,6 +217,7 @@ in rec {
tests.firefox = callTest tests/firefox.nix {};
tests.firewall = callTest tests/firewall.nix {};
tests.gnome3 = callTest tests/gnome3.nix {};
+ tests.installer.efi = forAllSystems (system: (import tests/installer.nix { inherit system; }).efi.test);
tests.installer.grub1 = forAllSystems (system: (import tests/installer.nix { inherit system; }).grub1.test);
tests.installer.lvm = forAllSystems (system: (import tests/installer.nix { inherit system; }).lvm.test);
tests.installer.rebuildCD = forAllSystems (system: (import tests/installer.nix { inherit system; }).rebuildCD.test);
diff --git a/nixos/tests/efi-installer.nix b/nixos/tests/efi-installer.nix
deleted file mode 100644
index 990f2b84a6c..00000000000
--- a/nixos/tests/efi-installer.nix
+++ /dev/null
@@ -1,126 +0,0 @@
-# !!! Merge into normal install tests once all livecds are EFIable
-{ pkgs, system, ... }:
-
-with pkgs.lib;
-with import ../lib/qemu-flags.nix;
-
-let
-
- # Build the ISO. This is the regular installation CD but with test
- # instrumentation.
- iso =
- (import ../lib/eval-config.nix {
- inherit system;
- modules =
- [ ../modules/installer/cd-dvd/installation-cd-minimal.nix
- ../modules/testing/test-instrumentation.nix
- { key = "serial";
-
- # The test cannot access the network, so any sources we
- # need must be included in the ISO.
- isoImage.storeContents =
- [ pkgs.glibcLocales
- pkgs.sudo
- pkgs.docbook5
- pkgs.docbook5_xsl
- pkgs.grub
- pkgs.perlPackages.XMLLibXML
- pkgs.unionfs-fuse
- pkgs.gummiboot
- pkgs.libxslt
- ];
- }
- ];
- }).config.system.build.isoImage;
-
-
- # The config to install
- config = builtins.toFile "configuration.nix" ''
- { pkgs, ... }: {
- imports = [ ./hardware-configuration.nix <nixos/modules/testing/test-instrumentation.nix> ];
- boot.loader.grub.enable = false;
- boot.loader.efi.canTouchEfiVariables = true;
- boot.loader.gummiboot.enable = true;
- fonts.enableFontConfig = false;
- }
- '';
-
- biosDir = pkgs.runCommand "ovmf-bios" {} ''
- mkdir $out
- ln -s ${pkgs.OVMF}/FV/OVMF.fd $out/bios.bin
- '';
-
-in {
- simple = {
- inherit iso;
- nodes = {};
- testScript = ''
- createDisk("harddisk", 4 * 1024);
-
- my $machine = createMachine({ hda => "harddisk",
- hdaInterface => "scsi",
- cdrom => glob("${iso}/iso/*.iso"),
- qemuFlags => '-L ${biosDir} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"}'});
- $machine->start;
-
- # Make sure that we get a login prompt etc.
- $machine->succeed("echo hello");
- $machine->waitForUnit("rogue");
- $machine->waitForUnit("nixos-manual");
-
- # Partition the disk.
- $machine->succeed(
- "sgdisk -Z /dev/sda",
- "sgdisk -n 1:0:+256M -N 2 -t 1:ef00 -t 2:8300 -c 1:boot -c 2:root /dev/sda",
- "mkfs.vfat -n BOOT /dev/sda1",
- "mkfs.ext3 -L nixos /dev/sda2",
- "mount LABEL=nixos /mnt",
- "mkdir /mnt/boot",
- "mount LABEL=BOOT /mnt/boot",
- );
-
- # Create the NixOS configuration.
- $machine->succeed(
- "nixos-generate-config --root /mnt",
- );
-
- $machine->succeed("cat /mnt/etc/nixos/hardware-configuration.nix >&2");
-
- $machine->copyFileFromHost(
- "${config}",
- "/mnt/etc/nixos/configuration.nix");
-
- # Perform the installation.
- $machine->succeed("nixos-install >&2");
-
- # Do it again to make sure it's idempotent.
- $machine->succeed("nixos-install >&2");
-
- $machine->shutdown;
-
- # Now see if we can boot the installation.
- my $machine = createMachine({ #hda => "harddisk",
-# hdaInterface => "virtio",
-# !!! OVMF doesn't boot from virtio http://www.mail-archive.com/edk2-devel@lists.sourceforge.net/msg01501.html
- qemuFlags => '-L ${biosDir} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"} -m 512 -hda ' . Cwd::abs_path('harddisk')});
-
- # Did /boot get mounted, if appropriate?
- $machine->waitForUnit("local-fs.target");
- $machine->succeed("test -e /boot/efi");
-
- $machine->succeed("nix-env -i coreutils >&2");
- $machine->succeed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/
- or die "nix-env failed";
-
- $machine->succeed("nixos-rebuild switch >&2");
-
- $machine->shutdown;
-
- my $machine = createMachine({ #hda => "harddisk",
-# hdaInterface => "virtio",
- qemuFlags => '-L ${biosDir} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"} -hda ' . Cwd::abs_path('harddisk')});
- $machine->waitForUnit("network.target");
- $machine->shutdown;
- '';
- };
-}
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix
index ca8974c168c..d453633bed0 100644
--- a/nixos/tests/installer.nix
+++ b/nixos/tests/installer.nix
@@ -27,6 +27,7 @@ let
pkgs.grub
pkgs.perlPackages.XMLLibXML
pkgs.unionfs-fuse
+ pkgs.gummiboot
];
}
];
@@ -34,7 +35,7 @@ let
# The configuration to install.
- config = { testChannel, grubVersion, grubDevice }: pkgs.writeText "configuration.nix"
+ makeConfig = { testChannel, useEFI, grubVersion, grubDevice }: pkgs.writeText "configuration.nix"
''
{ config, pkgs, modulesPath, ... }:
@@ -43,12 +44,18 @@ let
<nixpkgs/nixos/modules/testing/test-instrumentation.nix>
];
- boot.loader.grub.version = ${toString grubVersion};
- ${optionalString (grubVersion == 1) ''
- boot.loader.grub.splashImage = null;
+ ${if useEFI then ''
+ boot.loader.grub.enable = false;
+ boot.loader.efi.canTouchEfiVariables = true;
+ boot.loader.gummiboot.enable = true;
+ '' else ''
+ boot.loader.grub.version = ${toString grubVersion};
+ ${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.extraConfig = "serial; terminal_output.serial";
environment.systemPackages = [ ${optionalString testChannel "pkgs.rlwrap"} ];
}
@@ -77,19 +84,32 @@ let
channelContents = [ pkgs.rlwrap ];
+ efiBios = pkgs.runCommand "ovmf-bios" {} ''
+ mkdir $out
+ ln -s ${pkgs.OVMF}/FV/OVMF.fd $out/bios.bin
+ '';
+
+
# The test script boots the CD, installs NixOS on an empty hard
# disk, and then reboot from the hard disk. It's parameterized with
# a test script fragment `createPartitions', which must create
# partitions and filesystems.
- testScriptFun = { createPartitions, testChannel, grubVersion, grubDevice }:
- let iface = if grubVersion == 1 then "scsi" else "virtio"; in
+ testScriptFun = { createPartitions, testChannel, useEFI, grubVersion, grubDevice }:
+ let
+ # FIXME: OVMF doesn't boot from virtio http://www.mail-archive.com/edk2-devel@lists.sourceforge.net/msg01501.html
+ iface = if useEFI || grubVersion == 1 then "scsi" else "virtio";
+ qemuFlags =
+ (optionalString (iso.system == "x86_64-linux") "-cpu kvm64 ") +
+ (optionalString useEFI ''-L ${efiBios} -hda ''${\(Cwd::abs_path('harddisk'))} '');
+ hdFlags = optionalString (!useEFI)
+ ''hda => "harddisk", hdaInterface => "${iface}", '';
+ in
''
createDisk("harddisk", 4 * 1024);
- my $machine = createMachine({ hda => "harddisk",
- hdaInterface => "${iface}",
+ my $machine = createMachine({ ${hdFlags}
cdrom => glob("${iso}/iso/*.iso"),
- qemuFlags => '${optionalString testChannel (toString (qemuNICFlags 1 1 2))} ${optionalString (iso.system == "x86_64-linux") "-cpu kvm64"}'});
+ qemuFlags => "${qemuFlags} ${optionalString testChannel (toString (qemuNICFlags 1 1 2))}" });
$machine->start;
${optionalString testChannel ''
@@ -137,7 +157,7 @@ let
$machine->succeed("cat /mnt/etc/nixos/hardware-configuration.nix >&2");
$machine->copyFileFromHost(
- "${ config { inherit testChannel grubVersion grubDevice; } }",
+ "${ makeConfig { inherit testChannel useEFI grubVersion grubDevice; } }",
"/mnt/etc/nixos/configuration.nix");
# Perform the installation.
@@ -149,20 +169,27 @@ let
$machine->shutdown;
# Now see if we can boot the installation.
- my $machine = createMachine({ hda => "harddisk", hdaInterface => "${iface}" });
+ my $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}" });
- # Did /boot get mounted, if appropriate?
+ # Did /boot get mounted?
$machine->waitForUnit("local-fs.target");
- $machine->succeed("test -e /boot/grub");
+
+ ${if useEFI then ''
+ $machine->succeed("test -e /boot/efi");
+ '' else ''
+ $machine->succeed("test -e /boot/grub");
+ ''}
# Did the swap device get activated?
$machine->waitForUnit("swap.target");
$machine->succeed("cat /proc/swaps | grep -q /dev");
+ # Check whether the channel works.
$machine->succeed("nix-env -i coreutils >&2");
$machine->succeed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/
or die "nix-env failed";
+ # Check whether nixos-rebuild works.
$machine->succeed("nixos-rebuild switch >&2");
# Test nixos-option.
@@ -174,19 +201,19 @@ let
# And just to be sure, check that the machine still boots after
# "nixos-rebuild switch".
- my $machine = createMachine({ hda => "harddisk", hdaInterface => "${iface}" });
+ my $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}" });
$machine->waitForUnit("network.target");
$machine->shutdown;
'';
makeInstallerTest =
- { createPartitions, testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda" }:
+ { createPartitions, testChannel ? false, useEFI ? false, grubVersion ? 2, grubDevice ? "/dev/vda" }:
makeTest {
inherit iso;
nodes = if testChannel then { inherit webserver; } else { };
testScript = testScriptFun {
- inherit createPartitions testChannel grubVersion grubDevice;
+ inherit createPartitions testChannel useEFI grubVersion grubDevice;
};
};
@@ -312,6 +339,25 @@ in {
grubDevice = "/dev/sda";
};
+ # Test an EFI install.
+ efi = makeInstallerTest
+ { createPartitions =
+ ''
+ $machine->succeed(
+ "sgdisk -Z /dev/sda",
+ "sgdisk -n 1:0:+256M -n 2:0:+1024M -N 3 -t 1:ef00 -t 2:8200 -t 3:8300 -c 1:boot -c 2:swap -c 3:root /dev/sda",
+ "mkfs.vfat -n BOOT /dev/sda1",
+ "mkswap /dev/sda2 -L swap",
+ "swapon -L swap",
+ "mkfs.ext3 -L nixos /dev/sda3",
+ "mount LABEL=nixos /mnt",
+ "mkdir /mnt/boot",
+ "mount LABEL=BOOT /mnt/boot",
+ );
+ '';
+ useEFI = true;
+ };
+
# Rebuild the CD configuration with a little modification.
rebuildCD = makeTest
{ inherit iso;