From 6f61d2d19adab87e0ce4773545f70bc06a6437ef Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 7 Jun 2020 20:09:58 -0400 Subject: [PATCH] Add a test. Broken because unmounts don't work with the squashes? --- quickly.nix | 20 ++++++++++++++++---- test.nix | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 test.nix diff --git a/quickly.nix b/quickly.nix index 250de8a..54dbe82 100644 --- a/quickly.nix +++ b/quickly.nix @@ -3,7 +3,10 @@ { config, lib, pkgs, ... }: -with lib; +let + inherit (lib) mkOption literalExample; + netbootpkgs = pkgs.callPackage ./pkgs {}; +in { options = { @@ -81,20 +84,20 @@ with lib; [ config.system.build.toplevel ]; # Create the squashfs image that contains the Nix store. - system.build.squashfsStore = pkgs.makeSquashes { + system.build.squashfsStore = netbootpkgs.makeSquashfsManifest { name = "iso-manifeiist"; storeContents = config.netboot.storeContents; }; - # Create the initrd system.build.netbootRamdisk = pkgs.makeInitrd { inherit (config.boot.initrd) compressor; prepend = [ "${config.system.build.initialRamdisk}/initrd" "${( - pkgs.makeBetterInitrd { + netbootpkgs.makeCpioRecursive { name = "better-initrd"; + inherit (config.boot.initrd) compressor; root = config.system.build.squashfsStore; } )}/initrd" @@ -118,6 +121,15 @@ with lib; boot ''; + system.build.ipxeBootDir = pkgs.symlinkJoin { + name = "ipxeBootDir"; + paths = [ + config.system.build.netbootRamdisk + config.system.build.kernel + config.system.build.netbootIpxeScript + ]; + }; + boot.loader.timeout = 10; boot.postBootCommands = diff --git a/test.nix b/test.nix new file mode 100644 index 0000000..fb06253 --- /dev/null +++ b/test.nix @@ -0,0 +1,49 @@ +{ pkgs ? import {} +, system ? "x86_64-linux" +}: +let + inherit (pkgs.lib) concatStringsSep mapAttrsToList; + testlib = import "${pkgs.path}/nixos/lib/testing-python.nix" { inherit system pkgs; }; + + pythonDict = params: "\n {\n ${concatStringsSep ",\n " (mapAttrsToList (name: param: "\"${name}\": \"${param}\"") params)},\n }\n"; + + makeNetbootTest = name: extraConfig: + let + config = ( + import "${pkgs.path}/nixos/lib/eval-config.nix" { + inherit system; + modules = [ + ./quickly.nix + "${pkgs.path}/nixos/modules/testing/test-instrumentation.nix" + { key = "serial"; } + ]; + } + ).config; + + machineConfig = pythonDict ( + { + qemuFlags = "-boot order=n -m 2000"; + netBackendArgs = "tftp=${config.system.build.ipxeBootDir},bootfile=netboot.ipxe"; + } // extraConfig + ); + in + testlib.makeTest { + name = "boot-netboot-" + name; + nodes = {}; + testScript = '' + machine = create_machine(${machineConfig}) + machine.start() + machine.wait_for_unit("multi-user.target") + machine.shutdown() + ''; + }; +in +{ + 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. + netFrontendArgs = "romfile=${pkgs.ipxe}/ipxe.efirom"; + }; +}