2 hostIp = "192.168.0.1";
4 containerIp = "192.168.0.100";
8 import ./make-test-python.nix ({ pkgs, lib, ... }: {
9 name = "containers-portforward";
11 maintainers = with lib.maintainers; [ aristid aszlig eelco kampfschlaefer ianwookim ];
16 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
17 virtualisation.writableStore = true;
19 containers.webserver =
20 { privateNetwork = true;
22 localAddress = containerIp;
23 forwardPorts = [ { protocol = "tcp"; hostPort = hostPort; containerPort = containerPort; } ];
25 { services.httpd.enable = true;
26 services.httpd.adminAddr = "foo@example.org";
27 networking.firewall.allowedTCPPorts = [ 80 ];
31 virtualisation.additionalPaths = [ pkgs.stdenv ];
36 container_list = machine.succeed("nixos-container list")
37 assert "webserver" in container_list
39 # Start the webserver container.
40 machine.succeed("nixos-container start webserver")
42 # wait two seconds for the container to start and the network to be up
45 # Since "start" returns after the container has reached
46 # multi-user.target, we should now be able to access it.
47 # ip = machine.succeed("nixos-container show-ip webserver").strip()
48 machine.succeed("ping -n -c1 ${hostIp}")
49 machine.succeed("curl --fail http://${hostIp}:${toString hostPort}/ > /dev/null")
52 machine.succeed("nixos-container stop webserver")
53 machine.fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null")
55 # Destroying a declarative container should fail.
56 machine.fail("nixos-container destroy webserver")