2 hostIp = "192.168.0.1";
3 containerIp = "192.168.0.100/24";
5 containerIp6 = "fc00::2/7";
8 import ./make-test-python.nix ({ pkgs, lib, ... }: {
9 name = "containers-bridge";
11 maintainers = with lib.maintainers; [ aristid aszlig eelco kampfschlaefer ];
16 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
17 virtualisation.writableStore = true;
19 networking.bridges = {
24 networking.interfaces = {
26 ipv4.addresses = [{ address = hostIp; prefixLength = 24; }];
27 ipv6.addresses = [{ address = hostIp6; prefixLength = 7; }];
31 containers.webserver =
34 privateNetwork = true;
36 localAddress = containerIp;
37 localAddress6 = containerIp6;
39 { services.httpd.enable = true;
40 services.httpd.adminAddr = "foo@example.org";
41 networking.firewall.allowedTCPPorts = [ 80 ];
48 privateNetwork = true;
51 { services.httpd.enable = true;
52 services.httpd.adminAddr = "foo@example.org";
53 networking.firewall.allowedTCPPorts = [ 80 ];
58 virtualisation.additionalPaths = [ pkgs.stdenv ];
62 machine.wait_for_unit("default.target")
63 assert "webserver" in machine.succeed("nixos-container list")
65 with subtest("Start the webserver container"):
66 assert "up" in machine.succeed("nixos-container status webserver")
68 with subtest("Bridges exist inside containers"):
70 "nixos-container run webserver -- ip link show eth0",
71 "nixos-container run web-noip -- ip link show eth0",
74 ip = "${containerIp}".split("/")[0]
75 machine.succeed(f"ping -n -c 1 {ip}")
76 machine.succeed(f"curl --fail http://{ip}/ > /dev/null")
78 ip6 = "${containerIp6}".split("/")[0]
79 machine.succeed(f"ping -n -c 1 {ip6}")
80 machine.succeed(f"curl --fail http://[{ip6}]/ > /dev/null")
83 "nixos-container show-ip works in case of an ipv4 address "
84 + "with subnetmask in CIDR notation."
86 result = machine.succeed("nixos-container show-ip webserver").rstrip()
89 with subtest("Stop the container"):
90 machine.succeed("nixos-container stop webserver")
92 f"curl --fail --connect-timeout 2 http://{ip}/ > /dev/null",
93 f"curl --fail --connect-timeout 2 http://[{ip6}]/ > /dev/null",
96 # Destroying a declarative container should fail.
97 machine.fail("nixos-container destroy webserver")