1import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "systemd-initrd-simple";
3
4 nodes.machine = { pkgs, ... }: {
5 boot.initrd.systemd = {
6 enable = true;
7 emergencyAccess = true;
8 };
9 virtualisation.fileSystems."/".autoResize = true;
10 };
11
12 testScript = ''
13 import subprocess
14
15 with subtest("handover to stage-2 systemd works"):
16 machine.wait_for_unit("multi-user.target")
17 machine.succeed("systemd-analyze | grep -q '(initrd)'") # direct handover
18 machine.succeed("touch /testfile") # / is writable
19 machine.fail("touch /nix/store/testfile") # /nix/store is not writable
20 # Special filesystems are mounted by systemd
21 machine.succeed("[ -e /run/booted-system ]") # /run
22 machine.succeed("[ -e /sys/class ]") # /sys
23 machine.succeed("[ -e /dev/null ]") # /dev
24 machine.succeed("[ -e /proc/1 ]") # /proc
25 # stage-2-init mounted more special filesystems
26 machine.succeed("[ -e /dev/shm ]") # /dev/shm
27 machine.succeed("[ -e /dev/pts/ptmx ]") # /dev/pts
28 machine.succeed("[ -e /run/keys ]") # /run/keys
29
30 with subtest("groups work"):
31 machine.fail("journalctl -b 0 | grep 'systemd-udevd.*Unknown group.*ignoring'")
32
33 with subtest("growfs works"):
34 oldAvail = machine.succeed("df --output=avail / | sed 1d")
35 machine.shutdown()
36
37 subprocess.check_call(["qemu-img", "resize", "vm-state-machine/machine.qcow2", "+1G"])
38
39 machine.start()
40 newAvail = machine.succeed("df --output=avail / | sed 1d")
41
42 assert int(oldAvail) < int(newAvail), "File system did not grow"
43 '';
44})