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