about summary refs log tree commit diff
path: root/nixos/modules/testing
diff options
context:
space:
mode:
authorWill Fancher <elvishjerricco@gmail.com>2023-09-19 23:30:52 -0400
committerWill Fancher <elvishjerricco@gmail.com>2023-11-09 17:02:01 -0500
commitf8ba8be54b7277ee284850119dc156297633b6b3 (patch)
tree9bf8547232847a85bb907547dc7af547e1476377 /nixos/modules/testing
parentcfbb29d76949ae53c457f152c52c173ea4bdd862 (diff)
downloadnixlib-f8ba8be54b7277ee284850119dc156297633b6b3.tar
nixlib-f8ba8be54b7277ee284850119dc156297633b6b3.tar.gz
nixlib-f8ba8be54b7277ee284850119dc156297633b6b3.tar.bz2
nixlib-f8ba8be54b7277ee284850119dc156297633b6b3.tar.lz
nixlib-f8ba8be54b7277ee284850119dc156297633b6b3.tar.xz
nixlib-f8ba8be54b7277ee284850119dc156297633b6b3.tar.zst
nixlib-f8ba8be54b7277ee284850119dc156297633b6b3.zip
testing-instrumentation: Factor backdoor service out to variable
Diffstat (limited to 'nixos/modules/testing')
-rw-r--r--nixos/modules/testing/test-instrumentation.nix75
1 files changed, 39 insertions, 36 deletions
diff --git a/nixos/modules/testing/test-instrumentation.nix b/nixos/modules/testing/test-instrumentation.nix
index c91e54f5a4d7..6c4b4f13d04b 100644
--- a/nixos/modules/testing/test-instrumentation.nix
+++ b/nixos/modules/testing/test-instrumentation.nix
@@ -7,48 +7,51 @@ with lib;
 
 let
   qemu-common = import ../../lib/qemu-common.nix { inherit lib pkgs; };
+
+  backdoorService = {
+    wantedBy = [ "multi-user.target" ];
+    requires = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
+    after = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
+    script =
+      ''
+        export USER=root
+        export HOME=/root
+        export DISPLAY=:0.0
+
+        source /etc/profile
+
+        # Don't use a pager when executing backdoor
+        # actions. Because we use a tty, commands like systemctl
+        # or nix-store get confused into thinking they're running
+        # interactively.
+        export PAGER=
+
+        cd /tmp
+        exec < /dev/hvc0 > /dev/hvc0
+        while ! exec 2> /dev/${qemu-common.qemuSerialDevice}; do sleep 0.1; done
+        echo "connecting to host..." >&2
+        stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
+        # The following line is essential since it signals to
+        # the test driver that the shell is ready.
+        # See: the connect method in the Machine class.
+        echo "Spawning backdoor root shell..."
+        # Passing the terminal device makes bash run non-interactively.
+        # Otherwise we get errors on the terminal because bash tries to
+        # setup things like job control.
+        # Note: calling bash explicitly here instead of sh makes sure that
+        # we can also run non-NixOS guests during tests.
+        PS1= exec /usr/bin/env bash --norc /dev/hvc0
+      '';
+      serviceConfig.KillSignal = "SIGHUP";
+  };
+
 in
 
 {
 
   config = {
 
-    systemd.services.backdoor =
-      { wantedBy = [ "multi-user.target" ];
-        requires = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
-        after = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
-        script =
-          ''
-            export USER=root
-            export HOME=/root
-            export DISPLAY=:0.0
-
-            source /etc/profile
-
-            # Don't use a pager when executing backdoor
-            # actions. Because we use a tty, commands like systemctl
-            # or nix-store get confused into thinking they're running
-            # interactively.
-            export PAGER=
-
-            cd /tmp
-            exec < /dev/hvc0 > /dev/hvc0
-            while ! exec 2> /dev/${qemu-common.qemuSerialDevice}; do sleep 0.1; done
-            echo "connecting to host..." >&2
-            stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
-            # The following line is essential since it signals to
-            # the test driver that the shell is ready.
-            # See: the connect method in the Machine class.
-            echo "Spawning backdoor root shell..."
-            # Passing the terminal device makes bash run non-interactively.
-            # Otherwise we get errors on the terminal because bash tries to
-            # setup things like job control.
-            # Note: calling bash explicitly here instead of sh makes sure that
-            # we can also run non-NixOS guests during tests.
-            PS1= exec /usr/bin/env bash --norc /dev/hvc0
-          '';
-        serviceConfig.KillSignal = "SIGHUP";
-      };
+    systemd.services.backdoor = backdoorService
 
     # Prevent agetty from being instantiated on the serial device, since it
     # interferes with the backdoor (writes to it will randomly fail