2 webserverFor = hostAddress: localAddress: {
3 inherit hostAddress localAddress;
8 adminAddr = "foo@example.org";
10 networking.firewall.allowedTCPPorts = [ 80 ];
14 in import ./make-test-python.nix ({ pkgs, lib, ... }: {
15 name = "containers-ipv4-ipv6";
17 maintainers = with lib.maintainers; [ aristid aszlig eelco kampfschlaefer ];
22 imports = [ ../modules/installer/cd-dvd/channel.nix ];
27 containers.webserver4 = webserverFor "10.231.136.1" "10.231.136.2";
28 containers.webserver6 = webserverFor "fc00::2" "fc00::1";
29 virtualisation.additionalPaths = [ pkgs.stdenv ];
32 testScript = { nodes, ... }: ''
37 # put [] around ipv6 addresses for curl
38 host = ip if ":" not in ip else f"[{ip}]"
39 return f"curl --fail --connect-timeout 2 http://{host}/ > /dev/null"
42 def get_ip(container):
43 # need to distinguish because show-ip won't work for ipv6
44 if container == "webserver4":
45 ip = machine.succeed(f"nixos-container show-ip {container}").rstrip()
46 assert ip == "${nodes.machine.config.containers.webserver4.localAddress}"
48 return "${nodes.machine.config.containers.webserver6.localAddress}"
51 for container in "webserver4", "webserver6":
52 assert container in machine.succeed("nixos-container list")
54 with subtest(f"Start container {container}"):
55 machine.succeed(f"nixos-container start {container}")
56 # wait 2s for container to start and network to be up
59 # Since "start" returns after the container has reached
60 # multi-user.target, we should now be able to access it.
62 ip = get_ip(container)
63 with subtest(f"{container} reacts to pings and HTTP requests"):
64 machine.succeed(f"ping -n -c1 {ip}")
65 machine.succeed(curl_host(ip))
67 with subtest(f"Stop container {container}"):
68 machine.succeed(f"nixos-container stop {container}")
69 machine.fail(curl_host(ip))
71 # Destroying a declarative container should fail.
72 machine.fail(f"nixos-container destroy {container}")