summary refs log tree commit diff
path: root/nixos/tests/installer.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-30 11:24:46 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-30 11:26:39 +0200
commite9be441b62418783a1ea051588772889a7ac71d4 (patch)
tree9bc7066aa8ca30a8c71625071bff210c755cbb96 /nixos/tests/installer.nix
parent8c75ae38386a659f5e5a5dfbada9b5b614faacde (diff)
downloadnixlib-e9be441b62418783a1ea051588772889a7ac71d4.tar
nixlib-e9be441b62418783a1ea051588772889a7ac71d4.tar.gz
nixlib-e9be441b62418783a1ea051588772889a7ac71d4.tar.bz2
nixlib-e9be441b62418783a1ea051588772889a7ac71d4.tar.lz
nixlib-e9be441b62418783a1ea051588772889a7ac71d4.tar.xz
nixlib-e9be441b62418783a1ea051588772889a7ac71d4.tar.zst
nixlib-e9be441b62418783a1ea051588772889a7ac71d4.zip
Merge the EFI test into tests/installer.nix
Diffstat (limited to 'nixos/tests/installer.nix')
-rw-r--r--nixos/tests/installer.nix82
1 files changed, 64 insertions, 18 deletions
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix
index ca8974c168cd..d453633bed0e 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;