1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "systemd-initrd-network";
3 meta.maintainers = [ lib.maintainers.elvishjerricco ];
6 mkFlushTest = flush: script: { ... }: {
7 boot.initrd.systemd.enable = true;
8 boot.initrd.network = {
10 flushBeforeStage2 = flush;
12 systemd.services.check-flush = {
13 requiredBy = ["multi-user.target"];
14 before = ["network-pre.target" "multi-user.target"];
15 wants = ["network-pre.target"];
16 unitConfig.DefaultDependencies = false;
17 serviceConfig.Type = "oneshot";
18 path = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
24 boot.initrd.network.enable = true;
26 boot.initrd.systemd = {
28 # Enable network-online to fail the test in case of timeout
29 network.wait-online.timeout = 10;
30 network.wait-online.anyInterface = true;
31 targets.network-online.requiredBy = [ "initrd.target" ];
32 services.systemd-networkd-wait-online.requiredBy =
33 [ "network-online.target" ];
35 initrdBin = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
37 requiredBy = [ "initrd.target" ];
38 before = [ "initrd.target" ];
39 after = [ "network-online.target" ];
40 serviceConfig.Type = "oneshot";
41 path = [ pkgs.iproute2 pkgs.iputils pkgs.gnugrep ];
43 ip addr | grep 10.0.2.15 || exit 1
44 ping -c1 10.0.2.2 || exit 1
50 doFlush = mkFlushTest true ''
51 if ip addr | grep 10.0.2.15; then
52 echo "Network configuration survived switch-root; flushBeforeStage2 failed"
57 dontFlush = mkFlushTest false ''
58 if ! (ip addr | grep 10.0.2.15); then
59 echo "Network configuration didn't survive switch-root"
67 basic.wait_for_unit("multi-user.target")
68 doFlush.wait_for_unit("multi-user.target")
69 dontFlush.wait_for_unit("multi-user.target")
70 # Make sure the systemd-network user was set correctly in initrd
71 basic.succeed("[ $(stat -c '%U,%G' /run/systemd/netif/links) = systemd-network,systemd-network ]")
72 basic.succeed("ip addr show >&2")
73 basic.succeed("ip route show >&2")