mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-10-31 22:51:22 +00:00
nixos/qemu: Deduplicate QEMU serialDevice into qemu-flags.nix
This commit is contained in:
parent
1ce1380497
commit
8e83158f12
@ -8,4 +8,8 @@
|
|||||||
"-net vde,vlan=${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
|
"-net vde,vlan=${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
qemuSerialDevice = 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}'";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,10 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
kernel = config.boot.kernelPackages.kernel;
|
kernel = config.boot.kernelPackages.kernel;
|
||||||
# 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}'";
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -28,8 +25,8 @@ in
|
|||||||
|
|
||||||
systemd.services.backdoor =
|
systemd.services.backdoor =
|
||||||
{ wantedBy = [ "multi-user.target" ];
|
{ wantedBy = [ "multi-user.target" ];
|
||||||
requires = [ "dev-hvc0.device" "dev-${serialDevice}.device" ];
|
requires = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ];
|
||||||
after = [ "dev-hvc0.device" "dev-${serialDevice}.device" ];
|
after = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ];
|
||||||
script =
|
script =
|
||||||
''
|
''
|
||||||
export USER=root
|
export USER=root
|
||||||
@ -46,7 +43,7 @@ in
|
|||||||
|
|
||||||
cd /tmp
|
cd /tmp
|
||||||
exec < /dev/hvc0 > /dev/hvc0
|
exec < /dev/hvc0 > /dev/hvc0
|
||||||
while ! exec 2> /dev/${serialDevice}; do sleep 0.1; done
|
while ! exec 2> /dev/${qemuSerialDevice}; do sleep 0.1; done
|
||||||
echo "connecting to host..." >&2
|
echo "connecting to host..." >&2
|
||||||
stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
|
stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
|
||||||
echo
|
echo
|
||||||
@ -55,10 +52,10 @@ in
|
|||||||
serviceConfig.KillSignal = "SIGHUP";
|
serviceConfig.KillSignal = "SIGHUP";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Prevent agetty from being instantiated on ${serialDevice}, since it
|
# Prevent agetty from being instantiated on the serial device, since it
|
||||||
# interferes with the backdoor (writes to ${serialDevice} will randomly fail
|
# interferes with the backdoor (writes to it will randomly fail
|
||||||
# with EIO). Likewise for hvc0.
|
# with EIO). Likewise for hvc0.
|
||||||
systemd.services."serial-getty@${serialDevice}".enable = false;
|
systemd.services."serial-getty@${qemuSerialDevice}".enable = false;
|
||||||
systemd.services."serial-getty@hvc0".enable = false;
|
systemd.services."serial-getty@hvc0".enable = false;
|
||||||
|
|
||||||
boot.initrd.preDeviceCommands =
|
boot.initrd.preDeviceCommands =
|
||||||
@ -94,7 +91,7 @@ in
|
|||||||
# Panic if an error occurs in stage 1 (rather than waiting for
|
# Panic if an error occurs in stage 1 (rather than waiting for
|
||||||
# user intervention).
|
# user intervention).
|
||||||
boot.kernelParams =
|
boot.kernelParams =
|
||||||
[ "console=${serialDevice}" "panic=1" "boot.panic_on_fail" ];
|
[ "console=${qemuSerialDevice}" "panic=1" "boot.panic_on_fail" ];
|
||||||
|
|
||||||
# `xwininfo' is used by the test driver to query open windows.
|
# `xwininfo' is used by the test driver to query open windows.
|
||||||
environment.systemPackages = [ pkgs.xorg.xwininfo ];
|
environment.systemPackages = [ pkgs.xorg.xwininfo ];
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
@ -21,11 +22,6 @@ let
|
|||||||
"aarch64-linux" = "${qemu}/bin/qemu-system-aarch64 -enable-kvm -machine virt,gic-version=host -cpu host";
|
"aarch64-linux" = "${qemu}/bin/qemu-system-aarch64 -enable-kvm -machine virt,gic-version=host -cpu host";
|
||||||
}.${pkgs.stdenv.system};
|
}.${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 =
|
vmName =
|
||||||
if config.networking.hostName == ""
|
if config.networking.hostName == ""
|
||||||
then "noname"
|
then "noname"
|
||||||
@ -34,7 +30,7 @@ let
|
|||||||
cfg = config.virtualisation;
|
cfg = config.virtualisation;
|
||||||
|
|
||||||
qemuGraphics = if cfg.graphics then "" else "-nographic";
|
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" ];
|
ttys = [ "tty1" "tty2" "tty3" "tty4" "tty5" "tty6" ];
|
||||||
|
|
||||||
# Shell script to start the VM.
|
# Shell script to start the VM.
|
||||||
|
Loading…
Reference in New Issue
Block a user