1 # This module allows the test driver to connect to the virtual machine
2 # via a root shell attached to port 514.
4 { options, config, lib, pkgs, ... }:
9 qemu-common = import ../../lib/qemu-common.nix { inherit lib pkgs; };
16 systemd.services.backdoor =
17 { wantedBy = [ "multi-user.target" ];
18 requires = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
19 after = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
28 # Don't use a pager when executing backdoor
29 # actions. Because we use a tty, commands like systemctl
30 # or nix-store get confused into thinking they're running
35 exec < /dev/hvc0 > /dev/hvc0
36 while ! exec 2> /dev/${qemu-common.qemuSerialDevice}; do sleep 0.1; done
37 echo "connecting to host..." >&2
38 stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
42 serviceConfig.KillSignal = "SIGHUP";
45 # Prevent agetty from being instantiated on the serial device, since it
46 # interferes with the backdoor (writes to it will randomly fail
47 # with EIO). Likewise for hvc0.
48 systemd.services."serial-getty@${qemu-common.qemuSerialDevice}".enable = false;
49 systemd.services."serial-getty@hvc0".enable = false;
51 # Only set these settings when the options exist. Some tests (e.g. those
52 # that do not specify any nodes, or an empty attr set as nodes) will not
53 # have the QEMU module loaded and thuse these options can't and should not
55 virtualisation = lib.optionalAttrs (options ? virtualisation.qemu) {
57 # Only use a serial console, no TTY.
59 # test-instrumentation.nix appears to be used without qemu-vm.nix, so
60 # we avoid defining consoles if not possible.
61 # TODO: refactor such that test-instrumentation can import qemu-vm
62 # or declare virtualisation.qemu.console option in a module that's always imported
63 consoles = [ qemu-common.qemuSerialDevice ];
64 package = lib.mkDefault pkgs.qemu_test;
68 boot.kernel.sysctl = {
69 "kernel.hung_task_timeout_secs" = 600;
70 # Panic on out-of-memory conditions rather than letting the
71 # OOM killer randomly get rid of processes, since this leads
72 # to failures that are hard to diagnose.
73 "vm.panic_on_oom" = lib.mkDefault 2;
77 "console=${qemu-common.qemuSerialDevice}"
78 # Panic if an error occurs in stage 1 (rather than waiting for
80 "panic=1" "boot.panic_on_fail"
81 # Using acpi_pm as a clock source causes the guest clock to
82 # slow down under high host load. This is usually a bad
83 # thing, but for VM tests it should provide a bit more
84 # determinism (e.g. if the VM runs at lower speed, then
85 # timeouts in the VM should also be delayed).
89 # `xwininfo' is used by the test driver to query open windows.
90 environment.systemPackages = [ pkgs.xorg.xwininfo ];
92 # Log everything to the serial console.
93 services.journald.extraConfig =
99 systemd.extraConfig = ''
100 # Don't clobber the console with duplicate systemd messages.
102 # Allow very slow start
103 DefaultTimeoutStartSec=300
105 systemd.user.extraConfig = ''
106 # Allow very slow start
107 DefaultTimeoutStartSec=300
110 boot.consoleLogLevel = 7;
112 # Prevent tests from accessing the Internet.
113 networking.defaultGateway = mkOverride 150 "";
114 networking.nameservers = mkOverride 150 [ ];
116 system.requiredKernelConfig = with config.lib.kernelConfig; [
117 (isYes "SERIAL_8250_CONSOLE")
118 (isYes "SERIAL_8250")
119 (isEnabled "VIRTIO_CONSOLE")
122 networking.usePredictableInterfaceNames = false;
124 # Make it easy to log in as root when running the test interactively.
125 users.users.root.initialHashedPassword = mkOverride 150 "";
127 services.xserver.displayManager.job.logToJournal = true;
129 # Make sure we use the Guest Agent from the QEMU package for testing
130 # to reduce the closure size required for the tests.
131 services.qemuGuest.package = pkgs.qemu_test.ga;
133 # Squelch warning about unset system.stateVersion
134 system.stateVersion = lib.mkDefault lib.trivial.release;