2022-03-21 03:51:50 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ lib, pkgs, ... }:
|
|
|
|
{
|
2022-03-20 20:11:32 +00:00
|
|
|
name = "systemd-initrd-simple";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-05-01 13:18:12 +00:00
|
|
|
nodes.machine =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
2023-09-20 03:39:51 +00:00
|
|
|
testing.initrdBackdoor = true;
|
|
|
|
boot.initrd.systemd.enable = true;
|
2023-03-05 17:46:28 +00:00
|
|
|
virtualisation.fileSystems."/".autoResize = true;
|
2022-03-20 20:11:32 +00:00
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-03-20 20:11:32 +00:00
|
|
|
testScript = ''
|
2022-03-21 03:51:50 +00:00
|
|
|
import subprocess
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-09-20 03:39:51 +00:00
|
|
|
with subtest("testing initrd backdoor"):
|
|
|
|
machine.wait_for_unit("initrd.target")
|
|
|
|
machine.succeed("systemctl status initrd-fs.target")
|
|
|
|
machine.switch_root()
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-04-04 11:57:32 +00:00
|
|
|
with subtest("handover to stage-2 systemd works"):
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.succeed("systemd-analyze | grep -q '(initrd)'") # direct handover
|
|
|
|
machine.succeed("touch /testfile") # / is writable
|
|
|
|
machine.fail("touch /nix/store/testfile") # /nix/store is not writable
|
|
|
|
# Special filesystems are mounted by systemd
|
|
|
|
machine.succeed("[ -e /run/booted-system ]") # /run
|
|
|
|
machine.succeed("[ -e /sys/class ]") # /sys
|
|
|
|
machine.succeed("[ -e /dev/null ]") # /dev
|
|
|
|
machine.succeed("[ -e /proc/1 ]") # /proc
|
|
|
|
# stage-2-init mounted more special filesystems
|
|
|
|
machine.succeed("[ -e /dev/shm ]") # /dev/shm
|
|
|
|
machine.succeed("[ -e /dev/pts/ptmx ]") # /dev/pts
|
|
|
|
machine.succeed("[ -e /run/keys ]") # /run/keys
|
2024-09-09 09:16:49 +00:00
|
|
|
# /nixos-closure didn't leak into stage-2
|
|
|
|
machine.succeed("[ ! -e /nixos-closure ]")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-07-22 05:32:22 +00:00
|
|
|
with subtest("groups work"):
|
|
|
|
machine.fail("journalctl -b 0 | grep 'systemd-udevd.*Unknown group.*ignoring'")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-04-04 11:57:32 +00:00
|
|
|
with subtest("growfs works"):
|
|
|
|
oldAvail = machine.succeed("df --output=avail / | sed 1d")
|
|
|
|
machine.shutdown()
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-04-04 11:57:32 +00:00
|
|
|
subprocess.check_call(["qemu-img", "resize", "vm-state-machine/machine.qcow2", "+1G"])
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-04-04 11:57:32 +00:00
|
|
|
machine.start()
|
2023-09-20 03:39:51 +00:00
|
|
|
machine.switch_root()
|
2022-04-04 11:57:32 +00:00
|
|
|
newAvail = machine.succeed("df --output=avail / | sed 1d")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2022-04-04 11:57:32 +00:00
|
|
|
assert int(oldAvail) < int(newAvail), "File system did not grow"
|
2022-03-20 20:11:32 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|