2018-11-11 08:41:11 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
2014-11-19 22:18:44 +00:00
|
|
|
|
2019-10-27 12:22:46 +00:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2014-11-19 22:18:44 +00:00
|
|
|
|
|
|
|
let
|
2024-02-26 08:32:32 +00:00
|
|
|
lib = pkgs.lib;
|
|
|
|
qemu-common = import ../lib/qemu-common.nix { inherit lib pkgs; };
|
|
|
|
|
|
|
|
mkStartCommand = {
|
|
|
|
memory ? 2048,
|
|
|
|
cdrom ? null,
|
|
|
|
usb ? null,
|
|
|
|
pxe ? null,
|
|
|
|
uboot ? false,
|
|
|
|
uefi ? false,
|
|
|
|
extraFlags ? [],
|
|
|
|
}: let
|
|
|
|
qemu = qemu-common.qemuBinary pkgs.qemu_test;
|
|
|
|
|
|
|
|
flags = [
|
|
|
|
"-m" (toString memory)
|
|
|
|
"-netdev" ("user,id=net0" + (lib.optionalString (pxe != null) ",tftp=${pxe},bootfile=netboot.ipxe"))
|
|
|
|
"-device" ("virtio-net-pci,netdev=net0" + (lib.optionalString (pxe != null && uefi) ",romfile=${pkgs.ipxe}/ipxe.efirom"))
|
|
|
|
] ++ lib.optionals (cdrom != null) [
|
|
|
|
"-cdrom" cdrom
|
|
|
|
] ++ lib.optionals (usb != null) [
|
|
|
|
"-device" "usb-ehci"
|
|
|
|
"-drive" "id=usbdisk,file=${usb},if=none,readonly"
|
|
|
|
"-device" "usb-storage,drive=usbdisk"
|
|
|
|
] ++ lib.optionals (pxe != null) [
|
|
|
|
"-boot" "order=n"
|
|
|
|
] ++ lib.optionals uefi [
|
|
|
|
"-drive" "if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}"
|
|
|
|
"-drive" "if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}"
|
|
|
|
] ++ extraFlags;
|
|
|
|
|
|
|
|
flagsStr = lib.concatStringsSep " " flags;
|
|
|
|
in "${qemu} ${flagsStr}";
|
2014-11-19 22:18:44 +00:00
|
|
|
|
|
|
|
iso =
|
|
|
|
(import ../lib/eval-config.nix {
|
|
|
|
inherit system;
|
2021-10-16 15:58:04 +00:00
|
|
|
modules = [
|
|
|
|
../modules/installer/cd-dvd/installation-cd-minimal.nix
|
|
|
|
../modules/testing/test-instrumentation.nix
|
|
|
|
];
|
2014-11-19 22:18:44 +00:00
|
|
|
}).config.system.build.isoImage;
|
|
|
|
|
2021-10-16 15:58:04 +00:00
|
|
|
sd =
|
|
|
|
(import ../lib/eval-config.nix {
|
|
|
|
inherit system;
|
|
|
|
modules = [
|
|
|
|
../modules/installer/sd-card/sd-image-x86_64.nix
|
|
|
|
../modules/testing/test-instrumentation.nix
|
|
|
|
{ sdImage.compressImage = false; }
|
|
|
|
];
|
|
|
|
}).config.system.build.sdImage;
|
|
|
|
|
2024-02-26 08:32:32 +00:00
|
|
|
makeBootTest = name: config:
|
2019-07-15 15:56:53 +00:00
|
|
|
let
|
2024-02-26 08:32:32 +00:00
|
|
|
startCommand = mkStartCommand config;
|
2019-07-15 15:56:53 +00:00
|
|
|
in
|
|
|
|
makeTest {
|
|
|
|
name = "boot-" + name;
|
|
|
|
nodes = { };
|
|
|
|
testScript =
|
|
|
|
''
|
2024-02-26 10:30:43 +00:00
|
|
|
machine = create_machine("${startCommand}")
|
2019-10-27 12:22:46 +00:00
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
2021-11-10 23:57:00 +00:00
|
|
|
machine.succeed("nix store verify --no-trust -r --option experimental-features nix-command /run/current-system")
|
2016-05-25 08:21:14 +00:00
|
|
|
|
2019-10-27 12:22:46 +00:00
|
|
|
with subtest("Check whether the channel got installed correctly"):
|
|
|
|
machine.succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello")
|
|
|
|
machine.succeed("nix-env --dry-run -iA nixos.procps")
|
2016-05-25 08:21:14 +00:00
|
|
|
|
2019-10-27 12:22:46 +00:00
|
|
|
machine.shutdown()
|
2019-07-15 15:56:53 +00:00
|
|
|
'';
|
|
|
|
};
|
2016-05-25 08:21:14 +00:00
|
|
|
|
2019-07-15 15:56:53 +00:00
|
|
|
makeNetbootTest = name: extraConfig:
|
|
|
|
let
|
2016-04-08 13:53:27 +00:00
|
|
|
config = (import ../lib/eval-config.nix {
|
|
|
|
inherit system;
|
2024-11-28 12:47:45 +00:00
|
|
|
modules = [
|
|
|
|
../modules/installer/netboot/netboot.nix
|
|
|
|
../modules/testing/test-instrumentation.nix
|
|
|
|
{
|
|
|
|
boot.kernelParams = [
|
|
|
|
"serial"
|
|
|
|
"live.nixos.passwordHash=$6$jnwR50SkbLYEq/Vp$wmggwioAkfmwuYqd5hIfatZWS/bO6hewzNIwIrWcgdh7k/fhUzZT29Vil3ioMo94sdji/nipbzwEpxecLZw0d0" # "password"
|
|
|
|
];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
key = "serial";
|
|
|
|
}
|
|
|
|
];
|
2016-04-08 13:53:27 +00:00
|
|
|
}).config;
|
2016-05-03 20:05:11 +00:00
|
|
|
ipxeBootDir = pkgs.symlinkJoin {
|
|
|
|
name = "ipxeBootDir";
|
|
|
|
paths = [
|
|
|
|
config.system.build.netbootRamdisk
|
|
|
|
config.system.build.kernel
|
2019-07-15 15:56:53 +00:00
|
|
|
config.system.build.netbootIpxeScript
|
2016-05-03 20:05:11 +00:00
|
|
|
];
|
|
|
|
};
|
2024-02-26 08:32:32 +00:00
|
|
|
startCommand = mkStartCommand ({
|
|
|
|
pxe = ipxeBootDir;
|
2019-07-15 15:56:53 +00:00
|
|
|
} // extraConfig);
|
2016-04-08 13:53:27 +00:00
|
|
|
in
|
2024-11-28 12:50:44 +00:00
|
|
|
makeTest {
|
|
|
|
name = "boot-netboot-" + name;
|
|
|
|
nodes = { };
|
|
|
|
testScript = ''
|
|
|
|
machine = create_machine("${startCommand}")
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.succeed("grep 'serial' /proc/cmdline")
|
|
|
|
machine.succeed("grep 'live.nixos.passwordHash' /proc/cmdline")
|
|
|
|
machine.succeed("grep '$6$jnwR50SkbLYEq/Vp$wmggwioAkfmwuYqd5hIfatZWS/bO6hewzNIwIrWcgdh7k/fhUzZT29Vil3ioMo94sdji/nipbzwEpxecLZw0d0' /etc/shadow")
|
|
|
|
machine.shutdown()
|
|
|
|
'';
|
2019-07-15 15:56:53 +00:00
|
|
|
};
|
2024-11-28 12:50:44 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
uefiCdrom = makeBootTest "uefi-cdrom" {
|
|
|
|
uefi = true;
|
|
|
|
cdrom = "${iso}/iso/${iso.isoName}";
|
|
|
|
};
|
|
|
|
|
|
|
|
uefiUsb = makeBootTest "uefi-usb" {
|
|
|
|
uefi = true;
|
|
|
|
usb = "${iso}/iso/${iso.isoName}";
|
|
|
|
};
|
|
|
|
|
|
|
|
uefiNetboot = makeNetbootTest "uefi" {
|
|
|
|
uefi = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (pkgs.stdenv.hostPlatform.system == "x86_64-linux") {
|
|
|
|
biosCdrom = makeBootTest "bios-cdrom" {
|
|
|
|
cdrom = "${iso}/iso/${iso.isoName}";
|
|
|
|
};
|
2019-07-15 15:56:53 +00:00
|
|
|
|
2021-05-25 18:13:29 +00:00
|
|
|
biosUsb = makeBootTest "bios-usb" {
|
2019-07-22 10:21:33 +00:00
|
|
|
usb = "${iso}/iso/${iso.isoName}";
|
2019-07-15 15:56:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
biosNetboot = makeNetbootTest "bios" {};
|
2021-10-16 15:58:04 +00:00
|
|
|
|
|
|
|
ubootExtlinux = let
|
|
|
|
sdImage = "${sd}/sd-image/${sd.imageName}";
|
|
|
|
mutableImage = "/tmp/linked-image.qcow2";
|
|
|
|
|
2024-02-26 08:32:32 +00:00
|
|
|
startCommand = mkStartCommand {
|
|
|
|
extraFlags = [
|
|
|
|
"-bios" "${pkgs.ubootQemuX86}/u-boot.rom"
|
|
|
|
"-machine" "type=pc,accel=tcg"
|
|
|
|
"-drive" "file=${mutableImage},if=virtio"
|
|
|
|
];
|
2021-10-16 15:58:04 +00:00
|
|
|
};
|
|
|
|
in makeTest {
|
|
|
|
name = "boot-uboot-extlinux";
|
|
|
|
nodes = { };
|
|
|
|
testScript = ''
|
|
|
|
import os
|
|
|
|
|
|
|
|
# Create a mutable linked image backed by the read-only SD image
|
|
|
|
if os.system("qemu-img create -f qcow2 -F raw -b ${sdImage} ${mutableImage}") != 0:
|
|
|
|
raise RuntimeError("Could not create mutable linked image")
|
|
|
|
|
2024-02-26 10:30:43 +00:00
|
|
|
machine = create_machine("${startCommand}")
|
2021-10-16 15:58:04 +00:00
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.succeed("nix store verify -r --no-trust --option experimental-features nix-command /run/current-system")
|
|
|
|
machine.shutdown()
|
|
|
|
'';
|
2024-02-26 10:16:36 +00:00
|
|
|
|
|
|
|
# kernel can't find rootfs after boot - investigate?
|
|
|
|
meta.broken = true;
|
2021-10-16 15:58:04 +00:00
|
|
|
};
|
2016-05-03 20:05:11 +00:00
|
|
|
}
|