From f4d74931628accc733f9e0e996575b5ca3042d8a Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Sun, 25 Oct 2020 13:19:25 +0100 Subject: [PATCH] nixos/tests: only apply qemu parameters if the options are defined This fixes an eval error that occurred on hydra with the small channel and the `nixos.tests.boot.biosCdrom.x86_64-linux` attribute: > $ nix-instantiate nixos/release-small.nix -A nixos.tests.boot.biosCdrom.x86_64-linux > warning: unknown setting 'experimental-features' > error: The option `virtualisation.qemu' does not exist. Definition values: > - In `/home/andi/dev/nixos/nixpkgs/nixos/modules/testing/test-instrumentation.nix': > { > consoles = [ ]; > package = { > _type = "override"; > content = ; > ... > (use '--show-trace' to show detailed location information) In bc2188b we changed test test-instrumentation to also set the QEMU package that is being used. That change unfortunately caused us to always assing values to the virtualisation.qemu.package option even when the option is not defined. The original code was explicitly testing for the consoles case but the then newly extended version did not adjust the check as the intention was probably not clear. With this commit we are always ensuring the entire virtualisation.qemu section exists and can thus drop the individual tests for each of the sections since the QEMU module always defines both the package and the consoles option when it's root is defined.. --- .../modules/testing/test-instrumentation.nix | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/nixos/modules/testing/test-instrumentation.nix b/nixos/modules/testing/test-instrumentation.nix index 2986bd4c4e31..be5fa88b8ade 100644 --- a/nixos/modules/testing/test-instrumentation.nix +++ b/nixos/modules/testing/test-instrumentation.nix @@ -45,15 +45,21 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; }; systemd.services."serial-getty@${qemuSerialDevice}".enable = false; systemd.services."serial-getty@hvc0".enable = false; - # Only use a serial console, no TTY. - # NOTE: optionalAttrs - # test-instrumentation.nix appears to be used without qemu-vm.nix, so - # we avoid defining consoles if not possible. - # TODO: refactor such that test-instrumentation can import qemu-vm - # or declare virtualisation.qemu.console option in a module that's always imported - virtualisation.qemu = { - consoles = lib.optional (options ? virtualisation.qemu.consoles) qemuSerialDevice; - package = lib.mkDefault pkgs.qemu_test; + # Only set these settings when the options exist. Some tests (e.g. those + # that do not specify any nodes, or an empty attr set as nodes) will not + # have the QEMU module loaded and thuse these options can't and should not + # be set. + virtualisation = lib.optionalAttrs (options ? virtualisation.qemu) { + qemu = { + # Only use a serial console, no TTY. + # NOTE: optionalAttrs + # test-instrumentation.nix appears to be used without qemu-vm.nix, so + # we avoid defining consoles if not possible. + # TODO: refactor such that test-instrumentation can import qemu-vm + # or declare virtualisation.qemu.console option in a module that's always imported + consoles = [ qemuSerialDevice ]; + package = lib.mkDefault pkgs.qemu_test; + }; }; boot.initrd.preDeviceCommands =