diff --git a/nixos/modules/testing/test-instrumentation.nix b/nixos/modules/testing/test-instrumentation.nix
index 41dec2af9ed..98da55ed68a 100644
--- a/nixos/modules/testing/test-instrumentation.nix
+++ b/nixos/modules/testing/test-instrumentation.nix
@@ -58,6 +58,9 @@ in
systemd.services."serial-getty@${qemuSerialDevice}".enable = false;
systemd.services."serial-getty@hvc0".enable = false;
+ # Only use a serial console, no TTY.
+ virtualisation.qemu.consoles = [ qemuSerialDevice ];
+
boot.initrd.preDeviceCommands =
''
echo 600 > /proc/sys/kernel/hung_task_timeout_secs
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix
index d271144af48..0abf7b11703 100644
--- a/nixos/modules/virtualisation/qemu-vm.nix
+++ b/nixos/modules/virtualisation/qemu-vm.nix
@@ -25,10 +25,7 @@ let
qemuGraphics = lib.optionalString (!cfg.graphics) "-nographic";
- # enable both serial console and tty0. select preferred console (last one) based on cfg.graphics
- kernelConsoles = let
- consoles = [ "console=${qemuSerialDevice},115200n8" "console=tty0" ];
- in lib.concatStringsSep " " (if cfg.graphics then consoles else reverseList consoles);
+ consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
# XXX: This is very ugly and in the future we really should use attribute
# sets to build ALL of the QEMU flags instead of this mixed mess of Nix
@@ -111,7 +108,7 @@ let
${mkDiskIfaceDriveFlag "0" "file=$NIX_DISK_IMAGE,cache=writeback,werror=report"} \
-kernel ${config.system.build.toplevel}/kernel \
-initrd ${config.system.build.toplevel}/initrd \
- -append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${kernelConsoles} $QEMU_KERNEL_PARAMS" \
+ -append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS" \
''} \
$extraDisks \
${qemuGraphics} \
@@ -336,6 +333,23 @@ in
description = "Options passed to QEMU.";
};
+ consoles = mkOption {
+ type = types.listOf types.str;
+ default = let
+ consoles = [ "${qemuSerialDevice},115200n8" "tty0" ];
+ in if cfg.graphics then consoles else reverseList consoles;
+ example = [ "console=tty1" ];
+ description = ''
+ The output console devices to pass to the kernel command line via the
+ console parameter, the primary console is the last
+ item of this list.
+
+ By default it enables both serial console and
+ tty0. The preferred console (last one) is based on
+ the value of .
+ '';
+ };
+
networkingOptions =
mkOption {
default = [