krunkit: add boot regression test

The test boots a nixos efi machine. It requires a aarch64-linux builder
to produce the nixos image, as well as apple-virt feature enabled.

Assisted-By: Codex, gpt-5.5 high
This commit is contained in:
Ihar Hrachyshka 2026-05-28 18:27:34 -04:00
commit 4bfafef8b4
2 changed files with 133 additions and 1 deletions

View file

@ -0,0 +1,126 @@
{
krunkit,
lib,
nixos,
pkgs,
runCommand,
}:
let
linuxPkgs = import pkgs.path {
system = "aarch64-linux";
};
nixosConfig =
(nixos {
nixpkgs.pkgs = linuxPkgs;
imports = [ "${pkgs.path}/nixos/modules/profiles/qemu-guest.nix" ];
boot = {
kernelParams = [ "console=hvc0" ];
loader = {
efi.canTouchEfiVariables = false;
systemd-boot.enable = true;
};
};
documentation.enable = false;
environment.defaultPackages = [ ];
fileSystems = {
"/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
"/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
};
};
systemd.services.krunkit-boot-ok = {
wantedBy = [ "multi-user.target" ];
after = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script = ''
echo krunkit-boot-ok >/dev/hvc0
'';
};
system.stateVersion = lib.trivial.release;
}).config;
image = import "${pkgs.path}/nixos/lib/make-disk-image.nix" {
inherit lib;
config = nixosConfig;
pkgs = linuxPkgs;
additionalSpace = "64M";
baseName = "krunkit-nixos";
bootSize = "128M";
copyChannel = false;
format = "raw";
partitionTableType = "efi";
};
in
runCommand "krunkit-nixos-boot-test"
{
requiredSystemFeatures = [ "apple-virt" ];
meta.platforms = [ "aarch64-darwin" ];
}
''
image=${image}/krunkit-nixos.img
disk=$TMPDIR/disk.img
console=$TMPDIR/console.log
log=$TMPDIR/krunkit.log
cp "$image" "$disk"
chmod u+w "$disk"
touch "$console" "$log"
cleanup() {
set +e
if [ -n "''${pid:-}" ]; then
kill "$pid" >/dev/null 2>&1
for _ in $(seq 1 20); do
kill -0 "$pid" >/dev/null 2>&1 || break
sleep 1
done
kill -KILL "$pid" >/dev/null 2>&1
fi
}
trap cleanup EXIT
${krunkit}/bin/krunkit \
--cpus 1 \
--memory 1024 \
--log-file "$log" \
--device "virtio-blk,path=$disk,format=raw" \
--device "virtio-serial,logFilePath=$console" &
pid=$!
for _ in $(seq 1 120); do
if grep -q krunkit-boot-ok "$console"; then
touch "$out"
exit 0
fi
if ! kill -0 "$pid" >/dev/null 2>&1; then
echo "krunkit exited before the guest reached multi-user.target"
wait "$pid"
cat "$log"
cat "$console"
exit 1
fi
sleep 1
done
echo "timed out waiting for krunkit guest boot marker"
cat "$log"
cat "$console"
exit 1
''

View file

@ -1,4 +1,5 @@
{
callPackage,
cargo,
darwin,
pkg-config,
@ -50,7 +51,12 @@ stdenv.mkDerivation (finalAttrs: {
# This is necessary in order for the binary to keep its entitlements
dontStrip = true;
passthru.updateScript = nix-update-script { };
passthru = {
tests.boot = callPackage ./boot-test.nix {
krunkit = finalAttrs.finalPackage;
};
updateScript = nix-update-script { };
};
meta = {
description = "Launch configurable virtual machines with libkrun";