2 # containers IP on VLAN 1
3 containerIp1 = "192.168.1.253";
4 containerIp2 = "192.168.1.254";
7 import ./make-test-python.nix ({ pkgs, lib, ... }: {
8 name = "containers-macvlans";
10 maintainers = with lib.maintainers; [ montag451 ];
18 virtualisation.vlans = [ 1 ];
20 # To be able to ping containers from the host, it is necessary
21 # to create a macvlan on the host on the VLAN 1 network.
22 networking.macvlans.mv-eth1-host = {
26 networking.interfaces.eth1.ipv4.addresses = lib.mkForce [];
27 networking.interfaces.mv-eth1-host = {
28 ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ];
33 macvlans = [ "eth1" ];
36 networking.interfaces.mv-eth1 = {
37 ipv4.addresses = [ { address = containerIp1; prefixLength = 24; } ];
44 macvlans = [ "eth1" ];
47 networking.interfaces.mv-eth1 = {
48 ipv4.addresses = [ { address = containerIp2; prefixLength = 24; } ];
57 virtualisation.vlans = [ 1 ];
64 machine1.wait_for_unit("default.target")
65 machine2.wait_for_unit("default.target")
68 "Ping between containers to check that macvlans are created in bridge mode"
70 machine1.succeed("nixos-container run test1 -- ping -n -c 1 ${containerIp2}")
72 with subtest("Ping containers from the host (machine1)"):
73 machine1.succeed("ping -n -c 1 ${containerIp1}")
74 machine1.succeed("ping -n -c 1 ${containerIp2}")
77 "Ping containers from the second machine to check that containers are reachable from the outside"
79 machine2.succeed("ping -n -c 1 ${containerIp1}")
80 machine2.succeed("ping -n -c 1 ${containerIp2}")