1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-26 23:52:33 +00:00

Merge the EFI test into tests/installer.nix

This commit is contained in:
Eelco Dolstra 2014-04-30 11:24:46 +02:00
parent 8c75ae3838
commit e9be441b62
4 changed files with 66 additions and 144 deletions

View file

@ -48,6 +48,7 @@ in rec {
(all nixos.tests.firefox) (all nixos.tests.firefox)
(all nixos.tests.firewall) (all nixos.tests.firewall)
(all nixos.tests.gnome3) (all nixos.tests.gnome3)
(all nixos.tests.installer.efi)
(all nixos.tests.installer.grub1) (all nixos.tests.installer.grub1)
(all nixos.tests.installer.lvm) (all nixos.tests.installer.lvm)
(all nixos.tests.installer.separateBoot) (all nixos.tests.installer.separateBoot)

View file

@ -217,6 +217,7 @@ in rec {
tests.firefox = callTest tests/firefox.nix {}; tests.firefox = callTest tests/firefox.nix {};
tests.firewall = callTest tests/firewall.nix {}; tests.firewall = callTest tests/firewall.nix {};
tests.gnome3 = callTest tests/gnome3.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.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.lvm = forAllSystems (system: (import tests/installer.nix { inherit system; }).lvm.test);
tests.installer.rebuildCD = forAllSystems (system: (import tests/installer.nix { inherit system; }).rebuildCD.test); tests.installer.rebuildCD = forAllSystems (system: (import tests/installer.nix { inherit system; }).rebuildCD.test);

View file

@ -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;
'';
};
}

View file

@ -27,6 +27,7 @@ let
pkgs.grub pkgs.grub
pkgs.perlPackages.XMLLibXML pkgs.perlPackages.XMLLibXML
pkgs.unionfs-fuse pkgs.unionfs-fuse
pkgs.gummiboot
]; ];
} }
]; ];
@ -34,7 +35,7 @@ let
# The configuration to install. # The configuration to install.
config = { testChannel, grubVersion, grubDevice }: pkgs.writeText "configuration.nix" makeConfig = { testChannel, useEFI, grubVersion, grubDevice }: pkgs.writeText "configuration.nix"
'' ''
{ config, pkgs, modulesPath, ... }: { config, pkgs, modulesPath, ... }:
@ -43,12 +44,18 @@ let
<nixpkgs/nixos/modules/testing/test-instrumentation.nix> <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
]; ];
boot.loader.grub.version = ${toString grubVersion}; ${if useEFI then ''
${optionalString (grubVersion == 1) '' boot.loader.grub.enable = false;
boot.loader.grub.splashImage = null; 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"} ]; environment.systemPackages = [ ${optionalString testChannel "pkgs.rlwrap"} ];
} }
@ -77,19 +84,32 @@ let
channelContents = [ pkgs.rlwrap ]; 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 # The test script boots the CD, installs NixOS on an empty hard
# 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, testChannel, grubVersion, grubDevice }: testScriptFun = { createPartitions, testChannel, useEFI, grubVersion, grubDevice }:
let iface = if grubVersion == 1 then "scsi" else "virtio"; in 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); createDisk("harddisk", 4 * 1024);
my $machine = createMachine({ hda => "harddisk", my $machine = createMachine({ ${hdFlags}
hdaInterface => "${iface}",
cdrom => glob("${iso}/iso/*.iso"), 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; $machine->start;
${optionalString testChannel '' ${optionalString testChannel ''
@ -137,7 +157,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(
"${ config { inherit testChannel grubVersion grubDevice; } }", "${ makeConfig { inherit testChannel useEFI grubVersion grubDevice; } }",
"/mnt/etc/nixos/configuration.nix"); "/mnt/etc/nixos/configuration.nix");
# Perform the installation. # Perform the installation.
@ -149,20 +169,27 @@ let
$machine->shutdown; $machine->shutdown;
# Now see if we can boot the installation. # 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->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? # Did the swap device get activated?
$machine->waitForUnit("swap.target"); $machine->waitForUnit("swap.target");
$machine->succeed("cat /proc/swaps | grep -q /dev"); $machine->succeed("cat /proc/swaps | grep -q /dev");
# Check whether the channel works.
$machine->succeed("nix-env -i coreutils >&2"); $machine->succeed("nix-env -i coreutils >&2");
$machine->succeed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/ $machine->succeed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/
or die "nix-env failed"; or die "nix-env failed";
# Check whether nixos-rebuild works.
$machine->succeed("nixos-rebuild switch >&2"); $machine->succeed("nixos-rebuild switch >&2");
# Test nixos-option. # Test nixos-option.
@ -174,19 +201,19 @@ let
# And just to be sure, check that the machine still boots after # And just to be sure, check that the machine still boots after
# "nixos-rebuild switch". # "nixos-rebuild switch".
my $machine = createMachine({ hda => "harddisk", hdaInterface => "${iface}" }); my $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}" });
$machine->waitForUnit("network.target"); $machine->waitForUnit("network.target");
$machine->shutdown; $machine->shutdown;
''; '';
makeInstallerTest = makeInstallerTest =
{ createPartitions, testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda" }: { createPartitions, testChannel ? false, useEFI ? false, grubVersion ? 2, grubDevice ? "/dev/vda" }:
makeTest { makeTest {
inherit iso; inherit iso;
nodes = if testChannel then { inherit webserver; } else { }; nodes = if testChannel then { inherit webserver; } else { };
testScript = testScriptFun { testScript = testScriptFun {
inherit createPartitions testChannel grubVersion grubDevice; inherit createPartitions testChannel useEFI grubVersion grubDevice;
}; };
}; };
@ -312,6 +339,25 @@ in {
grubDevice = "/dev/sda"; 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. # Rebuild the CD configuration with a little modification.
rebuildCD = makeTest rebuildCD = makeTest
{ inherit iso; { inherit iso;