1# Test for NixOS' container support.
2
3import ./make-test.nix ({ pkgs, ...} : {
4 name = "containers-ipv4";
5 meta = with pkgs.stdenv.lib.maintainers; {
6 maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ];
7 };
8
9 machine =
10 { pkgs, ... }:
11 { imports = [ ../modules/installer/cd-dvd/channel.nix ];
12 virtualisation.writableStore = true;
13 virtualisation.memorySize = 768;
14
15 containers.webserver =
16 { privateNetwork = true;
17 hostAddress = "10.231.136.1";
18 localAddress = "10.231.136.2";
19 config =
20 { services.httpd.enable = true;
21 services.httpd.adminAddr = "foo@example.org";
22 networking.firewall.allowedTCPPorts = [ 80 ];
23 networking.firewall.allowPing = true;
24 system.stateVersion = "18.03";
25 };
26 };
27
28 virtualisation.pathsInNixDB = [ pkgs.stdenv ];
29 };
30
31 testScript =
32 ''
33 $machine->succeed("nixos-container list") =~ /webserver/ or die;
34
35 # Start the webserver container.
36 $machine->succeed("nixos-container start webserver");
37
38 # wait two seconds for the container to start and the network to be up
39 sleep 2;
40
41 # Since "start" returns after the container has reached
42 # multi-user.target, we should now be able to access it.
43 my $ip = $machine->succeed("nixos-container show-ip webserver");
44 chomp $ip;
45 $machine->succeed("ping -n -c1 $ip");
46 $machine->succeed("curl --fail http://$ip/ > /dev/null");
47
48 # Stop the container.
49 $machine->succeed("nixos-container stop webserver");
50 $machine->fail("curl --fail --connect-timeout 2 http://$ip/ > /dev/null");
51
52 # Destroying a declarative container should fail.
53 $machine->fail("nixos-container destroy webserver");
54 '';
55
56})