mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 13:40:28 +03:00
testing-instrumentation: Factor backdoor service out to variable
This commit is contained in:
parent
cfbb29d769
commit
f8ba8be54b
1 changed files with 39 additions and 36 deletions
|
@ -7,48 +7,51 @@ with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
qemu-common = import ../../lib/qemu-common.nix { inherit lib pkgs; };
|
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
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
systemd.services.backdoor =
|
systemd.services.backdoor = 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";
|
|
||||||
};
|
|
||||||
|
|
||||||
# Prevent agetty from being instantiated on the serial device, since it
|
# Prevent agetty from being instantiated on the serial device, since it
|
||||||
# interferes with the backdoor (writes to it will randomly fail
|
# interferes with the backdoor (writes to it will randomly fail
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue