summary refs log tree commit diff
path: root/nixos/modules/virtualisation
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2018-05-05 13:51:04 +0200
committerTuomas Tynkkynen <tuomas.tynkkynen@iki.fi>2018-05-07 19:23:47 +0300
commitd4468bedb52bf03ff125d721634f83604bddd589 (patch)
treee613fc9ecff3f6375d50e5cf51c3af2dc79510f4 /nixos/modules/virtualisation
parent70c57fe3638555d3ae1366e26be445d7f67a81e7 (diff)
downloadnixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.tar
nixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.tar.gz
nixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.tar.bz2
nixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.tar.lz
nixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.tar.xz
nixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.tar.zst
nixpkgs-d4468bedb52bf03ff125d721634f83604bddd589.zip
modules/virtualisation/qemu-vm: always enable serial console
Always enable both tty and serial console, but set preferred console
depending on cfg.graphical.
Even in qemu graphical mode, you can switch to the serial console via
Ctrl+Alt+3.

With that being done, you also don't need to specify
`systemd.services."serial-getty@ttyS0".enable = true;` either as described in
https://nixos.wiki/wiki/Cheatsheet#Building_a_service_as_a_VM_.28for_testing.29,
as systemd automatically spawns a getty on consoles passwd via cmdline.

This also means, vms built by 'nixos-rebuild build-vm' can simply be run
properly in nographic mode by appending `-nographic` to `result/bin/run-*-vm`,
without the need to explicitly add platform-specific QEMU_KERNEL_PARAMS.
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r--nixos/modules/virtualisation/qemu-vm.nix15
1 files changed, 10 insertions, 5 deletions
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix
index 5b98f359de0..c788f3ff8ba 100644
--- a/nixos/modules/virtualisation/qemu-vm.nix
+++ b/nixos/modules/virtualisation/qemu-vm.nix
@@ -24,7 +24,11 @@ let
   cfg = config.virtualisation;
 
   qemuGraphics = lib.optionalString (!cfg.graphics) "-nographic";
-  kernelConsole = if cfg.graphics then "" else "console=${qemuSerialDevice}";
+
+  # enable both serial console and tty0. select preferred console (last one) based on cfg.graphics
+  kernelConsoles = let
+    consoles = [ "console=${qemuSerialDevice}" "console=tty0" ];
+    in lib.concatStringsSep " " (if cfg.graphics then consoles else reverseList 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
@@ -107,7 +111,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 ${kernelConsole} $QEMU_KERNEL_PARAMS" \
+            -append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${kernelConsoles} $QEMU_KERNEL_PARAMS" \
           ''} \
           $extraDisks \
           ${qemuGraphics} \
@@ -247,9 +251,10 @@ in
         default = true;
         description =
           ''
-            Whether to run QEMU with a graphics window, or access
-            the guest computer serial port through the host tty.
-          '';
+            Whether to run QEMU with a graphics window, or in nographic mode.
+            Serial console will be enabled on both settings, but this will
+            change the preferred console.
+            '';
       };
 
     virtualisation.cores =