summaryrefslogtreecommitdiffstats
path: root/nixos/tests/ifstate/initrd.nix
blob: f21ca566f7281a28d5ce82306239c195e15e5afd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let
  mkIfStateConfig = id: {
    enable = true;
    settings.interfaces.eth1 = {
      addresses = [ "2001:0db8::${toString id}/64" ];
      link = {
        state = "up";
        kind = "physical";
      };
    };
  };
in
{
  name = "ifstate-initrd";

  nodes = {
    server = {
      imports = [ ../../modules/profiles/minimal.nix ];

      virtualisation.interfaces.eth1.vlan = 1;

      # Initrd IfState enforces stage 2 ifstate using assertion.
      networking.ifstate = {
        enable = true;
        settings.interfaces = { };
      };

      boot.initrd = {
        # otherwise the interfaces do not get created
        kernelModules = [ "virtio_net" ];

        network = {
          enable = true;
          ifstate = mkIfStateConfig 1 // {
            allowIfstateToDrasticlyIncreaseInitrdSize = true;
          };
        };

        systemd = {
          enable = true;
          network.enable = false;
          services.boot-blocker = {
            before = [ "initrd.target" ];
            wantedBy = [ "initrd.target" ];
            script = "sleep infinity";
            serviceConfig.Type = "oneshot";
          };
        };
      };
    };

    client = {
      imports = [ ../../modules/profiles/minimal.nix ];

      virtualisation.interfaces.eth1.vlan = 1;

      networking.ifstate = mkIfStateConfig 2;
    };
  };

  testScript = # python
    ''
      start_all()
      client.wait_for_unit("network.target")

      # try to ping the server from the client
      client.wait_until_succeeds("ping -c 1 2001:0db8::1")
    '';
}