nixpkgs/nixos/tests/systemd-initrd-networkd.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

110 lines
2.8 KiB
Nix

{
system ? builtins.currentSystem,
config ? { },
pkgs ? import ../.. { inherit system config; },
lib ? pkgs.lib,
}:
with import ../lib/testing-python.nix { inherit system pkgs; };
let
inherit (lib.maintainers) elvishjerricco;
common = {
boot.initrd.systemd = {
enable = true;
network.wait-online.timeout = 10;
network.wait-online.anyInterface = true;
targets.network-online.requiredBy = [ "initrd.target" ];
services.systemd-networkd-wait-online.requiredBy = [ "network-online.target" ];
initrdBin = [
pkgs.iproute2
pkgs.iputils
pkgs.gnugrep
];
};
testing.initrdBackdoor = true;
boot.initrd.network.enable = true;
};
mkFlushTest =
flush: script:
makeTest {
name = "systemd-initrd-network-${lib.optionalString (!flush) "no-"}flush";
meta.maintainers = [ elvishjerricco ];
nodes.machine = {
imports = [ common ];
boot.initrd.network.flushBeforeStage2 = flush;
systemd.services.check-flush = {
requiredBy = [ "multi-user.target" ];
before = [
"network-pre.target"
"multi-user.target"
"shutdown.target"
];
conflicts = [ "shutdown.target" ];
wants = [ "network-pre.target" ];
unitConfig.DefaultDependencies = false;
serviceConfig.Type = "oneshot";
path = [
pkgs.iproute2
pkgs.iputils
pkgs.gnugrep
];
inherit script;
};
};
testScript = ''
machine.wait_for_unit("network-online.target")
machine.succeed(
"ip addr | grep 10.0.2.15",
"ping -c1 10.0.2.2",
)
machine.switch_root()
machine.wait_for_unit("multi-user.target")
'';
};
in
{
basic = makeTest {
name = "systemd-initrd-network";
meta.maintainers = [ elvishjerricco ];
nodes.machine = common;
testScript = ''
machine.wait_for_unit("network-online.target")
machine.succeed(
"ip addr | grep 10.0.2.15",
"ping -c1 10.0.2.2",
)
machine.switch_root()
# Make sure the systemd-network user was set correctly in initrd
machine.wait_for_unit("multi-user.target")
machine.succeed("[ $(stat -c '%U,%G' /run/systemd/netif/links) = systemd-network,systemd-network ]")
machine.succeed("ip addr show >&2")
machine.succeed("ip route show >&2")
'';
};
doFlush = mkFlushTest true ''
if ip addr | grep 10.0.2.15; then
echo "Network configuration survived switch-root; flushBeforeStage2 failed"
exit 1
fi
'';
dontFlush = mkFlushTest false ''
if ! (ip addr | grep 10.0.2.15); then
echo "Network configuration didn't survive switch-root"
exit 1
fi
'';
}