nixos/qemu: Deduplicate QEMU serialDevice into qemu-flags.nix

+14 -17
+4
nixos/lib/qemu-flags.nix
··· 8 8 "-net vde,vlan=${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}" 9 9 ]; 10 10 11 + qemuSerialDevice = if pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64 then "ttyS0" 12 + else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" 13 + else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; 14 + 11 15 }
+8 -11
nixos/modules/testing/test-instrumentation.nix
··· 4 4 { config, lib, pkgs, ... }: 5 5 6 6 with lib; 7 + with import ../../lib/qemu-flags.nix { inherit pkgs; }; 7 8 8 9 let 9 10 kernel = config.boot.kernelPackages.kernel; 10 - # FIXME: figure out a common place for this instead of copy pasting 11 - serialDevice = if pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64 then "ttyS0" 12 - else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" 13 - else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; 14 11 in 15 12 16 13 { ··· 28 25 29 26 systemd.services.backdoor = 30 27 { wantedBy = [ "multi-user.target" ]; 31 - requires = [ "dev-hvc0.device" "dev-${serialDevice}.device" ]; 32 - after = [ "dev-hvc0.device" "dev-${serialDevice}.device" ]; 28 + requires = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ]; 29 + after = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ]; 33 30 script = 34 31 '' 35 32 export USER=root ··· 46 43 47 44 cd /tmp 48 45 exec < /dev/hvc0 > /dev/hvc0 49 - while ! exec 2> /dev/${serialDevice}; do sleep 0.1; done 46 + while ! exec 2> /dev/${qemuSerialDevice}; do sleep 0.1; done 50 47 echo "connecting to host..." >&2 51 48 stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion 52 49 echo ··· 55 52 serviceConfig.KillSignal = "SIGHUP"; 56 53 }; 57 54 58 - # Prevent agetty from being instantiated on ${serialDevice}, since it 59 - # interferes with the backdoor (writes to ${serialDevice} will randomly fail 55 + # Prevent agetty from being instantiated on the serial device, since it 56 + # interferes with the backdoor (writes to it will randomly fail 60 57 # with EIO). Likewise for hvc0. 61 - systemd.services."serial-getty@${serialDevice}".enable = false; 58 + systemd.services."serial-getty@${qemuSerialDevice}".enable = false; 62 59 systemd.services."serial-getty@hvc0".enable = false; 63 60 64 61 boot.initrd.preDeviceCommands = ··· 94 91 # Panic if an error occurs in stage 1 (rather than waiting for 95 92 # user intervention). 96 93 boot.kernelParams = 97 - [ "console=${serialDevice}" "panic=1" "boot.panic_on_fail" ]; 94 + [ "console=${qemuSerialDevice}" "panic=1" "boot.panic_on_fail" ]; 98 95 99 96 # `xwininfo' is used by the test driver to query open windows. 100 97 environment.systemPackages = [ pkgs.xorg.xwininfo ];
+2 -6
nixos/modules/virtualisation/qemu-vm.nix
··· 10 10 { config, lib, pkgs, ... }: 11 11 12 12 with lib; 13 + with import ../../lib/qemu-flags.nix { inherit pkgs; }; 13 14 14 15 let 15 16 ··· 21 22 "aarch64-linux" = "${qemu}/bin/qemu-system-aarch64 -enable-kvm -machine virt,gic-version=host -cpu host"; 22 23 }.${pkgs.stdenv.system}; 23 24 24 - # FIXME: figure out a common place for this instead of copy pasting 25 - serialDevice = if pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64 then "ttyS0" 26 - else if pkgs.stdenv.isArm || pkgs.stdenv.isAarch64 then "ttyAMA0" 27 - else throw "Unknown QEMU serial device for system '${pkgs.stdenv.system}'"; 28 - 29 25 vmName = 30 26 if config.networking.hostName == "" 31 27 then "noname" ··· 34 30 cfg = config.virtualisation; 35 31 36 32 qemuGraphics = if cfg.graphics then "" else "-nographic"; 37 - kernelConsole = if cfg.graphics then "" else "console=${serialDevice}"; 33 + kernelConsole = if cfg.graphics then "" else "console=${qemuSerialDevice}"; 38 34 ttys = [ "tty1" "tty2" "tty3" "tty4" "tty5" "tty6" ]; 39 35 40 36 # Shell script to start the VM.