From 8e83158f124f6c8d5583a32102f281bde10769cd Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Tue, 30 Jan 2018 11:28:26 +0200 Subject: nixos/qemu: Deduplicate QEMU serialDevice into qemu-flags.nix --- nixos/modules/virtualisation/qemu-vm.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'nixos/modules/virtualisation/qemu-vm.nix') diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 26f7945a4eda..c52f637604ae 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -10,6 +10,7 @@ { config, lib, pkgs, ... }: with lib; +with import ../../lib/qemu-flags.nix { inherit pkgs; }; let @@ -21,11 +22,6 @@ let "aarch64-linux" = "${qemu}/bin/qemu-system-aarch64 -enable-kvm -machine virt,gic-version=host -cpu host"; }.${pkgs.stdenv.system}; - # FIXME: figure out a common place for this instead of copy pasting - serialDevice = if pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64 then "ttyS0" - else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" - else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; - vmName = if config.networking.hostName == "" then "noname" @@ -34,7 +30,7 @@ let cfg = config.virtualisation; qemuGraphics = if cfg.graphics then "" else "-nographic"; - kernelConsole = if cfg.graphics then "" else "console=${serialDevice}"; + kernelConsole = if cfg.graphics then "" else "console=${qemuSerialDevice}"; ttys = [ "tty1" "tty2" "tty3" "tty4" "tty5" "tty6" ]; # Shell script to start the VM. -- cgit 1.4.1 From 71631a922b4005497fe3b93fdfe5899e2f6d7a2c Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Wed, 6 Dec 2017 20:26:22 +0200 Subject: runInLinuxVM: Use QEMU command line that works on other architectures ... by moving the existing definition to qemu-flags.nix and reusing that. --- nixos/lib/qemu-flags.nix | 6 ++++++ nixos/modules/virtualisation/qemu-vm.nix | 8 +------- pkgs/build-support/vm/default.nix | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) (limited to 'nixos/modules/virtualisation/qemu-vm.nix') diff --git a/nixos/lib/qemu-flags.nix b/nixos/lib/qemu-flags.nix index fb00c3183fbf..fcdcbf1b0077 100644 --- a/nixos/lib/qemu-flags.nix +++ b/nixos/lib/qemu-flags.nix @@ -12,4 +12,10 @@ else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; + qemuBinary = qemuPkg: { + "i686-linux" = "${qemuPkg}/bin/qemu-kvm"; + "x86_64-linux" = "${qemuPkg}/bin/qemu-kvm -cpu kvm64"; + "armv7l-linux" = "${qemuPkg}/bin/qemu-system-arm -enable-kvm -machine virt -cpu host"; + "aarch64-linux" = "${qemuPkg}/bin/qemu-system-aarch64 -enable-kvm -machine virt,gic-version=host -cpu host"; + }.${pkgs.stdenv.system} or (throw "Unknown QEMU binary for '${pkgs.stdenv.system}'"); } diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index c52f637604ae..13d0eb7de5c2 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -15,12 +15,6 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; }; let qemu = config.system.build.qemu or pkgs.qemu_test; - qemuKvm = { - "i686-linux" = "${qemu}/bin/qemu-kvm"; - "x86_64-linux" = "${qemu}/bin/qemu-kvm -cpu kvm64"; - "armv7l-linux" = "${qemu}/bin/qemu-system-arm -enable-kvm -machine virt -cpu host"; - "aarch64-linux" = "${qemu}/bin/qemu-system-aarch64 -enable-kvm -machine virt,gic-version=host -cpu host"; - }.${pkgs.stdenv.system}; vmName = if config.networking.hostName == "" @@ -79,7 +73,7 @@ let '')} # Start QEMU. - exec ${qemuKvm} \ + exec ${qemuBinary qemu} \ -name ${vmName} \ -m ${toString config.virtualisation.memorySize} \ -smp ${toString config.virtualisation.cores} \ diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index cf6e7cc1fe4e..d599f9bbb65f 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -23,8 +23,6 @@ rec { patches = [ ../../../nixos/modules/virtualisation/azure-qemu-220-no-etc-install.patch ]; }); - qemuProg = "${qemu}/bin/qemu-kvm"; - modulesClosure = makeModulesClosure { inherit kernel rootModules; @@ -204,8 +202,7 @@ rec { qemuCommandLinux = '' - ${qemuProg} \ - ${lib.optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"} \ + ${qemuBinary qemu} \ -nographic -no-reboot \ -device virtio-rng-pci \ -virtfs local,path=${storeDir},security_model=none,mount_tag=store \ -- cgit 1.4.1