at 25.11-pre 6.2 kB view raw
1{ 2 system ? builtins.currentSystem, 3 config ? { }, 4 pkgs ? import ../.. { inherit system config; }, 5}: 6 7with import ../lib/testing-python.nix { inherit system pkgs; }; 8 9let 10 lib = pkgs.lib; 11 qemu-common = import ../lib/qemu-common.nix { inherit lib pkgs; }; 12 13 mkStartCommand = 14 { 15 memory ? 2048, 16 cdrom ? null, 17 usb ? null, 18 pxe ? null, 19 uboot ? false, 20 uefi ? false, 21 extraFlags ? [ ], 22 }: 23 let 24 qemu = qemu-common.qemuBinary pkgs.qemu_test; 25 26 flags = 27 [ 28 "-m" 29 (toString memory) 30 "-netdev" 31 ("user,id=net0" + (lib.optionalString (pxe != null) ",tftp=${pxe},bootfile=netboot.ipxe")) 32 "-device" 33 ( 34 "virtio-net-pci,netdev=net0" 35 + (lib.optionalString (pxe != null && uefi) ",romfile=${pkgs.ipxe}/ipxe.efirom") 36 ) 37 ] 38 ++ lib.optionals (cdrom != null) [ 39 "-cdrom" 40 cdrom 41 ] 42 ++ lib.optionals (usb != null) [ 43 "-device" 44 "usb-ehci" 45 "-drive" 46 "id=usbdisk,file=${usb},if=none,readonly" 47 "-device" 48 "usb-storage,drive=usbdisk" 49 ] 50 ++ lib.optionals (pxe != null) [ 51 "-boot" 52 "order=n" 53 ] 54 ++ lib.optionals uefi [ 55 "-drive" 56 "if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}" 57 "-drive" 58 "if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}" 59 ] 60 ++ extraFlags; 61 62 flagsStr = lib.concatStringsSep " " flags; 63 in 64 "${qemu} ${flagsStr}"; 65 66 iso = 67 (import ../lib/eval-config.nix { 68 system = null; 69 modules = [ 70 ../modules/installer/cd-dvd/installation-cd-minimal.nix 71 ../modules/testing/test-instrumentation.nix 72 { nixpkgs.pkgs = pkgs; } 73 ]; 74 }).config.system.build.isoImage; 75 76 sd = 77 (import ../lib/eval-config.nix { 78 system = null; 79 modules = [ 80 ../modules/installer/sd-card/sd-image-x86_64.nix 81 ../modules/testing/test-instrumentation.nix 82 { 83 sdImage.compressImage = false; 84 nixpkgs.pkgs = pkgs; 85 } 86 ]; 87 }).config.system.build.sdImage; 88 89 makeBootTest = 90 name: config: 91 let 92 startCommand = mkStartCommand config; 93 in 94 makeTest { 95 name = "boot-" + name; 96 nodes = { }; 97 testScript = '' 98 machine = create_machine("${startCommand}") 99 machine.start() 100 machine.wait_for_unit("multi-user.target") 101 machine.succeed("nix store verify --no-trust -r --option experimental-features nix-command /run/current-system") 102 103 with subtest("Check whether the channel got installed correctly"): 104 machine.succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello") 105 machine.succeed("nix-env --dry-run -iA nixos.procps") 106 107 machine.shutdown() 108 ''; 109 }; 110 111 makeNetbootTest = 112 name: extraConfig: 113 let 114 config = 115 (import ../lib/eval-config.nix { 116 system = null; 117 modules = [ 118 ../modules/installer/netboot/netboot.nix 119 ../modules/testing/test-instrumentation.nix 120 { 121 boot.kernelParams = [ 122 "serial" 123 "live.nixos.passwordHash=$6$jnwR50SkbLYEq/Vp$wmggwioAkfmwuYqd5hIfatZWS/bO6hewzNIwIrWcgdh7k/fhUzZT29Vil3ioMo94sdji/nipbzwEpxecLZw0d0" # "password" 124 ]; 125 126 nixpkgs.pkgs = pkgs; 127 } 128 { 129 key = "serial"; 130 } 131 ]; 132 }).config; 133 ipxeBootDir = pkgs.symlinkJoin { 134 name = "ipxeBootDir"; 135 paths = [ 136 config.system.build.netbootRamdisk 137 config.system.build.kernel 138 config.system.build.netbootIpxeScript 139 ]; 140 }; 141 startCommand = mkStartCommand ( 142 { 143 pxe = ipxeBootDir; 144 } 145 // extraConfig 146 ); 147 in 148 makeTest { 149 name = "boot-netboot-" + name; 150 nodes = { }; 151 testScript = '' 152 machine = create_machine("${startCommand}") 153 machine.start() 154 machine.wait_for_unit("multi-user.target") 155 machine.succeed("grep 'serial' /proc/cmdline") 156 machine.succeed("grep 'live.nixos.passwordHash' /proc/cmdline") 157 machine.succeed("grep '$6$jnwR50SkbLYEq/Vp$wmggwioAkfmwuYqd5hIfatZWS/bO6hewzNIwIrWcgdh7k/fhUzZT29Vil3ioMo94sdji/nipbzwEpxecLZw0d0' /etc/shadow") 158 machine.shutdown() 159 ''; 160 }; 161in 162{ 163 uefiCdrom = makeBootTest "uefi-cdrom" { 164 uefi = true; 165 cdrom = "${iso}/iso/${iso.isoName}"; 166 }; 167 168 uefiUsb = makeBootTest "uefi-usb" { 169 uefi = true; 170 usb = "${iso}/iso/${iso.isoName}"; 171 }; 172 173 uefiNetboot = makeNetbootTest "uefi" { 174 uefi = true; 175 }; 176} 177// lib.optionalAttrs (pkgs.stdenv.hostPlatform.system == "x86_64-linux") { 178 biosCdrom = makeBootTest "bios-cdrom" { 179 cdrom = "${iso}/iso/${iso.isoName}"; 180 }; 181 182 biosUsb = makeBootTest "bios-usb" { 183 usb = "${iso}/iso/${iso.isoName}"; 184 }; 185 186 biosNetboot = makeNetbootTest "bios" { }; 187 188 ubootExtlinux = 189 let 190 sdImage = "${sd}/sd-image/${sd.imageName}"; 191 mutableImage = "/tmp/linked-image.qcow2"; 192 193 startCommand = mkStartCommand { 194 extraFlags = [ 195 "-bios" 196 "${pkgs.ubootQemuX86}/u-boot.rom" 197 "-machine" 198 "type=pc,accel=tcg" 199 "-drive" 200 "file=${mutableImage},if=virtio" 201 ]; 202 }; 203 in 204 makeTest { 205 name = "boot-uboot-extlinux"; 206 nodes = { }; 207 testScript = '' 208 import os 209 210 # Create a mutable linked image backed by the read-only SD image 211 if os.system("qemu-img create -f qcow2 -F raw -b ${sdImage} ${mutableImage}") != 0: 212 raise RuntimeError("Could not create mutable linked image") 213 214 machine = create_machine("${startCommand}") 215 machine.start() 216 machine.wait_for_unit("multi-user.target") 217 machine.succeed("nix store verify -r --no-trust --option experimental-features nix-command /run/current-system") 218 machine.shutdown() 219 ''; 220 221 # kernel can't find rootfs after boot - investigate? 222 meta.broken = true; 223 }; 224}