1let
2 hostIp = "192.168.0.1";
3 hostPort = 10080;
4 containerIp = "192.168.0.100";
5 containerPort = 80;
6in
7
8import ./make-test-python.nix ({ pkgs, lib, ... }: {
9 name = "containers-portforward";
10 meta = {
11 maintainers = with lib.maintainers; [ aristid aszlig eelco kampfschlaefer ianwookim ];
12 };
13
14 nodes.machine =
15 { pkgs, ... }:
16 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
17 virtualisation.writableStore = true;
18
19 containers.webserver =
20 { privateNetwork = true;
21 hostAddress = hostIp;
22 localAddress = containerIp;
23 forwardPorts = [ { protocol = "tcp"; hostPort = hostPort; containerPort = containerPort; } ];
24 config =
25 { services.httpd.enable = true;
26 services.httpd.adminAddr = "foo@example.org";
27 networking.firewall.allowedTCPPorts = [ 80 ];
28 };
29 };
30
31 virtualisation.additionalPaths = [ pkgs.stdenv ];
32 };
33
34 testScript =
35 ''
36 container_list = machine.succeed("nixos-container list")
37 assert "webserver" in container_list
38
39 # Start the webserver container.
40 machine.succeed("nixos-container start webserver")
41
42 # wait two seconds for the container to start and the network to be up
43 machine.sleep(2)
44
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")
50
51 # Stop the container.
52 machine.succeed("nixos-container stop webserver")
53 machine.fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null")
54
55 # Destroying a declarative container should fail.
56 machine.fail("nixos-container destroy webserver")
57 '';
58
59})