1{ system ? builtins.currentSystem,
2 config ? {},
3 pkgs ? import ../.. { inherit system config; }
4}:
5
6with import ../lib/testing-python.nix { inherit system pkgs; };
7with pkgs.lib;
8
9let
10 qemu-common = import ../lib/qemu-common.nix { inherit (pkgs) lib pkgs; };
11
12 iso =
13 (import ../lib/eval-config.nix {
14 inherit system;
15 modules =
16 [ ../modules/installer/cd-dvd/installation-cd-minimal.nix
17 ../modules/testing/test-instrumentation.nix
18 ];
19 }).config.system.build.isoImage;
20
21 pythonDict = params: "\n {\n ${concatStringsSep ",\n " (mapAttrsToList (name: param: "\"${name}\": \"${param}\"") params)},\n }\n";
22
23 makeBootTest = name: extraConfig:
24 let
25 machineConfig = pythonDict ({
26 qemuBinary = qemu-common.qemuBinary pkgs.qemu_test;
27 qemuFlags = "-m 768";
28 } // extraConfig);
29 in
30 makeTest {
31 inherit iso;
32 name = "boot-" + name;
33 nodes = { };
34 testScript =
35 ''
36 machine = create_machine(${machineConfig})
37 machine.start()
38 machine.wait_for_unit("multi-user.target")
39 machine.succeed("nix store verify --no-trust -r --option experimental-features nix-command /run/current-system")
40
41 with subtest("Check whether the channel got installed correctly"):
42 machine.succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello")
43 machine.succeed("nix-env --dry-run -iA nixos.procps")
44
45 machine.shutdown()
46 '';
47 };
48
49 makeNetbootTest = name: extraConfig:
50 let
51 config = (import ../lib/eval-config.nix {
52 inherit system;
53 modules =
54 [ ../modules/installer/netboot/netboot.nix
55 ../modules/testing/test-instrumentation.nix
56 { key = "serial"; }
57 ];
58 }).config;
59 ipxeBootDir = pkgs.symlinkJoin {
60 name = "ipxeBootDir";
61 paths = [
62 config.system.build.netbootRamdisk
63 config.system.build.kernel
64 config.system.build.netbootIpxeScript
65 ];
66 };
67 machineConfig = pythonDict ({
68 qemuBinary = qemu-common.qemuBinary pkgs.qemu_test;
69 qemuFlags = "-boot order=n -m 2000";
70 netBackendArgs = "tftp=${ipxeBootDir},bootfile=netboot.ipxe";
71 } // extraConfig);
72 in
73 makeTest {
74 name = "boot-netboot-" + name;
75 nodes = { };
76 testScript = ''
77 machine = create_machine(${machineConfig})
78 machine.start()
79 machine.wait_for_unit("multi-user.target")
80 machine.shutdown()
81 '';
82 };
83 uefiBinary = {
84 x86_64-linux = "${pkgs.OVMF.fd}/FV/OVMF.fd";
85 aarch64-linux = "${pkgs.OVMF.fd}/FV/QEMU_EFI.fd";
86 }.${pkgs.stdenv.hostPlatform.system};
87in {
88 uefiCdrom = makeBootTest "uefi-cdrom" {
89 cdrom = "${iso}/iso/${iso.isoName}";
90 bios = uefiBinary;
91 };
92
93 uefiUsb = makeBootTest "uefi-usb" {
94 usb = "${iso}/iso/${iso.isoName}";
95 bios = uefiBinary;
96 };
97
98 uefiNetboot = makeNetbootTest "uefi" {
99 bios = uefiBinary;
100 # Custom ROM is needed for EFI PXE boot. I failed to understand exactly why, because QEMU should still use iPXE for EFI.
101 netFrontendArgs = "romfile=${pkgs.ipxe}/ipxe.efirom";
102 };
103} // optionalAttrs (pkgs.stdenv.hostPlatform.system == "x86_64-linux") {
104 biosCdrom = makeBootTest "bios-cdrom" {
105 cdrom = "${iso}/iso/${iso.isoName}";
106 };
107
108 biosUsb = makeBootTest "bios-usb" {
109 usb = "${iso}/iso/${iso.isoName}";
110 };
111
112 biosNetboot = makeNetbootTest "bios" {};
113}