at 23.05-pre 4.8 kB view raw
1# This module allows the test driver to connect to the virtual machine 2# via a root shell attached to port 514. 3 4{ options, config, lib, pkgs, ... }: 5 6with lib; 7 8let 9 qemu-common = import ../../lib/qemu-common.nix { inherit lib pkgs; }; 10in 11 12{ 13 14 config = { 15 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" ]; 20 script = 21 '' 22 export USER=root 23 export HOME=/root 24 export DISPLAY=:0.0 25 26 source /etc/profile 27 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 31 # interactively. 32 export PAGER= 33 34 cd /tmp 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 39 echo 40 PS1= exec /bin/sh 41 ''; 42 serviceConfig.KillSignal = "SIGHUP"; 43 }; 44 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; 50 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 54 # be set. 55 virtualisation = lib.optionalAttrs (options ? virtualisation.qemu) { 56 qemu = { 57 # Only use a serial console, no TTY. 58 # NOTE: optionalAttrs 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; 65 }; 66 }; 67 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; 74 }; 75 76 boot.kernelParams = [ 77 "console=${qemu-common.qemuSerialDevice}" 78 # Panic if an error occurs in stage 1 (rather than waiting for 79 # user intervention). 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). 86 "clock=acpi_pm" 87 ]; 88 89 # `xwininfo' is used by the test driver to query open windows. 90 environment.systemPackages = [ pkgs.xorg.xwininfo ]; 91 92 # Log everything to the serial console. 93 services.journald.extraConfig = 94 '' 95 ForwardToConsole=yes 96 MaxLevelConsole=debug 97 ''; 98 99 systemd.extraConfig = '' 100 # Don't clobber the console with duplicate systemd messages. 101 ShowStatus=no 102 # Allow very slow start 103 DefaultTimeoutStartSec=300 104 ''; 105 systemd.user.extraConfig = '' 106 # Allow very slow start 107 DefaultTimeoutStartSec=300 108 ''; 109 110 boot.consoleLogLevel = 7; 111 112 # Prevent tests from accessing the Internet. 113 networking.defaultGateway = mkOverride 150 ""; 114 networking.nameservers = mkOverride 150 [ ]; 115 116 system.requiredKernelConfig = with config.lib.kernelConfig; [ 117 (isYes "SERIAL_8250_CONSOLE") 118 (isYes "SERIAL_8250") 119 (isEnabled "VIRTIO_CONSOLE") 120 ]; 121 122 networking.usePredictableInterfaceNames = false; 123 124 # Make it easy to log in as root when running the test interactively. 125 users.users.root.initialHashedPassword = mkOverride 150 ""; 126 127 services.xserver.displayManager.job.logToJournal = true; 128 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; 132 133 # Squelch warning about unset system.stateVersion 134 system.stateVersion = lib.mkDefault lib.trivial.release; 135 }; 136 137}