at 15.09-beta 3.6 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{ config, lib, pkgs, ... }: 5 6with lib; 7 8let kernel = config.boot.kernelPackages.kernel; in 9 10{ 11 12 config = { 13 14 systemd.services.backdoor = 15 { wantedBy = [ "multi-user.target" ]; 16 requires = [ "dev-hvc0.device" "dev-ttyS0.device" ]; 17 after = [ "dev-hvc0.device" "dev-ttyS0.device" ]; 18 script = 19 '' 20 export USER=root 21 export HOME=/root 22 export DISPLAY=:0.0 23 source /etc/profile 24 cd /tmp 25 exec < /dev/hvc0 > /dev/hvc0 26 while ! exec 2> /dev/ttyS0; do sleep 0.1; done 27 echo "connecting to host..." >&2 28 stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion 29 echo 30 PS1= exec /bin/sh 31 ''; 32 serviceConfig.KillSignal = "SIGHUP"; 33 }; 34 35 # Prevent agetty from being instantiated on ttyS0, since it 36 # interferes with the backdoor (writes to ttyS0 will randomly fail 37 # with EIO). Likewise for hvc0. 38 systemd.services."serial-getty@ttyS0".enable = false; 39 systemd.services."serial-getty@hvc0".enable = false; 40 41 # Don't use a pager when executing backdoor actions. Because we 42 # use a tty, commands like systemctl or nix-store get confused 43 # into thinking they're running interactively. 44 environment.variables.PAGER = ""; 45 46 boot.initrd.postDeviceCommands = 47 '' 48 # Using acpi_pm as a clock source causes the guest clock to 49 # slow down under high host load. This is usually a bad 50 # thing, but for VM tests it should provide a bit more 51 # determinism (e.g. if the VM runs at lower speed, then 52 # timeouts in the VM should also be delayed). 53 echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource 54 ''; 55 56 boot.postBootCommands = 57 '' 58 # Panic on out-of-memory conditions rather than letting the 59 # OOM killer randomly get rid of processes, since this leads 60 # to failures that are hard to diagnose. 61 echo 2 > /proc/sys/vm/panic_on_oom 62 63 # Coverage data is written into /tmp/coverage-data. 64 mkdir -p /tmp/xchg/coverage-data 65 ''; 66 67 # If the kernel has been built with coverage instrumentation, make 68 # it available under /proc/gcov. 69 boot.kernelModules = [ "gcov-proc" ]; 70 71 # Panic if an error occurs in stage 1 (rather than waiting for 72 # user intervention). 73 boot.kernelParams = 74 [ "console=ttyS0" "panic=1" "boot.panic_on_fail" ]; 75 76 # `xwininfo' is used by the test driver to query open windows. 77 environment.systemPackages = [ pkgs.xorg.xwininfo ]; 78 79 # Log everything to the serial console. 80 services.journald.extraConfig = 81 '' 82 ForwardToConsole=yes 83 MaxLevelConsole=debug 84 ''; 85 86 # Don't clobber the console with duplicate systemd messages. 87 systemd.extraConfig = "ShowStatus=no"; 88 89 boot.consoleLogLevel = 7; 90 91 # Prevent tests from accessing the Internet. 92 networking.defaultGateway = mkOverride 150 ""; 93 networking.nameservers = mkOverride 150 [ ]; 94 95 systemd.globalEnvironment.GCOV_PREFIX = "/tmp/xchg/coverage-data"; 96 97 system.requiredKernelConfig = with config.lib.kernelConfig; [ 98 (isYes "SERIAL_8250_CONSOLE") 99 (isYes "SERIAL_8250") 100 (isEnabled "VIRTIO_CONSOLE") 101 ]; 102 103 networking.usePredictableInterfaceNames = false; 104 105 # Make it easy to log in as root when running the test interactively. 106 users.extraUsers.root.initialHashedPassword = mkOverride 150 ""; 107 108 }; 109 110}