summary refs log tree commit diff
path: root/nixos/tests/boot.nix
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2019-07-15 18:56:53 +0300
committerNikolay Amiantov <ab@fmap.me>2019-07-15 19:34:19 +0300
commita2e8be9fc32368a476408d4cb1b073f755b6492c (patch)
treed88aadd02b0901f2e130f6029df6d25fbba3e6a3 /nixos/tests/boot.nix
parent81d35a9d7ea9dab5949af5e8e2d2fcb6315b1b12 (diff)
downloadnixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.tar
nixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.tar.gz
nixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.tar.bz2
nixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.tar.lz
nixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.tar.xz
nixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.tar.zst
nixpkgs-a2e8be9fc32368a476408d4cb1b073f755b6492c.zip
boot tests: add UEFI PXE netboot testing
Generalize netboot testing and add tests for UEFI PXE netboot.
Diffstat (limited to 'nixos/tests/boot.nix')
-rw-r--r--nixos/tests/boot.nix106
1 files changed, 56 insertions, 50 deletions
diff --git a/nixos/tests/boot.nix b/nixos/tests/boot.nix
index c9bb1e77c6d..12a34d4401f 100644
--- a/nixos/tests/boot.nix
+++ b/nixos/tests/boot.nix
@@ -17,46 +17,33 @@ let
         ];
     }).config.system.build.isoImage;
 
-  makeBootTest = name: machineConfig:
-    makeTest {
-      inherit iso;
-      name = "boot-" + name;
-      nodes = { };
-      testScript =
-        ''
-          my $machine = createMachine({ ${machineConfig}, qemuFlags => '-m 768' });
-          $machine->start;
-          $machine->waitForUnit("multi-user.target");
-          $machine->succeed("nix verify -r --no-trust /run/current-system");
+  perlAttrs = params: "{ ${concatStringsSep "," (mapAttrsToList (name: param: "${name} => '${toString param}'") params)} }";
 
-          # Test whether the channel got installed correctly.
-          $machine->succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello");
-          $machine->succeed("nix-env --dry-run -iA nixos.procps");
-
-          $machine->shutdown;
-        '';
-    };
-in {
-
-    biosCdrom = makeBootTest "bios-cdrom" ''
-        cdrom => glob("${iso}/iso/*.iso")
-      '';
-
-    biosUsb = makeBootTest "bios-usb" ''
-        usb => glob("${iso}/iso/*.iso")
-      '';
+  makeBootTest = name: extraConfig:
+    let
+      machineConfig = perlAttrs ({ qemuFlags = "-m 768"; } // extraConfig);
+    in
+      makeTest {
+        inherit iso;
+        name = "boot-" + name;
+        nodes = { };
+        testScript =
+          ''
+            my $machine = createMachine(${machineConfig});
+            $machine->start;
+            $machine->waitForUnit("multi-user.target");
+            $machine->succeed("nix verify -r --no-trust /run/current-system");
 
-    uefiCdrom = makeBootTest "uefi-cdrom" ''
-        cdrom => glob("${iso}/iso/*.iso"),
-        bios => '${pkgs.OVMF.fd}/FV/OVMF.fd'
-      '';
+            # Test whether the channel got installed correctly.
+            $machine->succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello");
+            $machine->succeed("nix-env --dry-run -iA nixos.procps");
 
-    uefiUsb = makeBootTest "uefi-usb" ''
-        usb => glob("${iso}/iso/*.iso"),
-        bios => '${pkgs.OVMF.fd}/FV/OVMF.fd'
-      '';
+            $machine->shutdown;
+          '';
+      };
 
-    netboot = let
+  makeNetbootTest = name: extraConfig:
+    let
       config = (import ../lib/eval-config.nix {
           inherit system;
           modules =
@@ -65,35 +52,54 @@ in {
               { key = "serial"; }
             ];
         }).config;
-      ipxeScriptDir = pkgs.writeTextFile {
-        name = "ipxeScriptDir";
-        text = ''
-          #!ipxe
-          dhcp
-          kernel bzImage init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} console=ttyS0
-          initrd initrd
-          boot
-        '';
-        destination = "/boot.ipxe";
-      };
       ipxeBootDir = pkgs.symlinkJoin {
         name = "ipxeBootDir";
         paths = [
           config.system.build.netbootRamdisk
           config.system.build.kernel
-          ipxeScriptDir
+          config.system.build.netbootIpxeScript
         ];
       };
+      machineConfig = perlAttrs ({
+        qemuFlags = "-boot order=n -netdev user,id=net0,tftp=${ipxeBootDir}/,bootfile=netboot.ipxe -m 2000";
+      } // extraConfig);
     in
       makeTest {
-        name = "boot-netboot";
+        name = "boot-netboot-" + name;
         nodes = { };
         testScript =
           ''
-            my $machine = createMachine({ qemuFlags => '-boot order=n -net nic,model=e1000 -net user,tftp=${ipxeBootDir}/,bootfile=boot.ipxe -m 2000M' });
+            my $machine = createMachine(${machineConfig});
             $machine->start;
             $machine->waitForUnit("multi-user.target");
             $machine->shutdown;
           '';
       };
+in {
+
+    biosCdrom = makeBootTest "bios-cdrom" {
+      cdrom = ''glob("${iso}/iso/*.iso")'';
+    };
+
+    biosUsb = makeBootTest "bios-usb" {
+      usb = ''glob("${iso}/iso/*.iso")'';
+    };
+
+    uefiCdrom = makeBootTest "uefi-cdrom" {
+      cdrom = ''glob("${iso}/iso/*.iso"'';
+      bios = ''"${pkgs.OVMF.fd}/FV/OVMF.fd"'';
+    };
+
+    uefiUsb = makeBootTest "uefi-usb" {
+      usb = ''glob("${iso}/iso/*.iso")'';
+      bios = ''"${pkgs.OVMF.fd}/FV/OVMF.fd"'';
+    };
+
+    biosNetboot = makeNetbootTest "bios" {};
+
+    uefiNetboot = makeNetbootTest "uefi" {
+      bios = ''"${pkgs.OVMF.fd}/FV/OVMF.fd"'';
+      # Custom ROM is needed for EFI PXE boot. I failed to understand exactly why, because QEMU should still use iPXE for EFI.
+      netRomFile = ''"${pkgs.ipxe}/ipxe.efirom"'';
+    };
 }