diff --git a/flake.nix b/flake.nix index 7359ba9..c06d595 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,7 @@ inherit pkgs; makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix"); + qemu-common = import (pkgs.path + "/nixos/lib/qemu-common.nix"); } ); diff --git a/lib/default.nix b/lib/default.nix index 061898c..d4ba865 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -3,11 +3,22 @@ rootMountPoint ? "/mnt", makeTest ? import , eval-config ? import , + qemu-common ? import , }: let + # qemu-common is a function that takes { lib, pkgs } and returns QEMU utilities + qemu-common-lib = pkgs: qemu-common { inherit lib pkgs; }; + outputs = import ../default.nix { inherit lib diskoLib; }; diskoLib = { - testLib = import ./tests.nix { inherit lib makeTest eval-config; }; + testLib = import ./tests.nix { + inherit + lib + makeTest + eval-config + qemu-common-lib + ; + }; # like lib.types.oneOf but instead of a list takes an attrset # uses the field "type" to find the correct type in the attrset subType = diff --git a/lib/tests.nix b/lib/tests.nix index f140ed6..1cfe536 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -2,6 +2,7 @@ lib, makeTest, eval-config, + qemu-common-lib, ... }: @@ -91,6 +92,12 @@ let inherit pkgs; system = pkgs.stdenv.hostPlatform.system; }; + + # Get qemu-common library functions for this pkgs + qemu-common = qemu-common-lib pkgs; + # qemuBinary returns a string like: "/nix/store/.../qemu-system-x86_64 -machine accel=kvm:tcg -cpu max" + qemuBinaryString = qemu-common.qemuBinary pkgs.qemu_test; + # for installation we skip /dev/vda because it is the test runner disk importedDiskoConfig = if builtins.isPath disko-config then import disko-config else disko-config; @@ -291,6 +298,8 @@ let testScript = { nodes, ... }: '' + import shlex + def disks(oldmachine, num_disks): disk_flags = [] for i in range(num_disks): @@ -305,10 +314,9 @@ let def create_test_machine( oldmachine=None, **kwargs ): # taken from - start_command = [ - "${pkgs.qemu_test}/bin/qemu-kvm", - "-cpu", - "max", + # Use qemu-common from nixpkgs to get the proper QEMU binary with correct machine type and flags + # shlex.split properly handles the command string with options like "-machine virt,gic-version=max" + start_command = shlex.split("${qemuBinaryString}") + [ "-m", "1024", "-virtfs", diff --git a/tests/default.nix b/tests/default.nix index 0bb5e46..39bc518 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,11 +1,19 @@ { makeTest ? import , eval-config ? import , + qemu-common ? import , pkgs ? import { }, }: let lib = pkgs.lib; - diskoLib = import ../lib { inherit lib makeTest eval-config; }; + diskoLib = import ../lib { + inherit + lib + makeTest + eval-config + qemu-common + ; + }; allTestFilenames = builtins.map (lib.removeSuffix ".nix") ( builtins.filter (x: lib.hasSuffix ".nix" x && x != "default.nix") (