···
1
+
# Test for NixOS' container support.
4
+
hostIp = "192.168.0.1";
6
+
containerIp = "192.168.0.100";
10
+
import ./make-test.nix ({ pkgs, ...} : {
11
+
name = "containers-portforward";
12
+
meta = with pkgs.stdenv.lib.maintainers; {
13
+
maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ianwookim ];
17
+
{ config, pkgs, ... }:
18
+
{ imports = [ ../modules/installer/cd-dvd/channel.nix ];
19
+
virtualisation.writableStore = true;
20
+
virtualisation.memorySize = 768;
22
+
containers.webserver =
23
+
{ privateNetwork = true;
24
+
hostAddress = hostIp;
25
+
localAddress = containerIp;
26
+
forwardPorts = [ { protocol = "tcp"; hostPort = hostPort; containerPort = containerPort; } ];
28
+
{ services.httpd.enable = true;
29
+
services.httpd.adminAddr = "foo@example.org";
30
+
networking.firewall.allowedTCPPorts = [ 80 ];
31
+
networking.firewall.allowPing = true;
35
+
virtualisation.pathsInNixDB = [ pkgs.stdenv ];
40
+
$machine->succeed("nixos-container list") =~ /webserver/ or die;
42
+
# Start the webserver container.
43
+
$machine->succeed("nixos-container start webserver");
45
+
# wait two seconds for the container to start and the network to be up
48
+
# Since "start" returns after the container has reached
49
+
# multi-user.target, we should now be able to access it.
50
+
#my $ip = $machine->succeed("nixos-container show-ip webserver");
52
+
$machine->succeed("ping -n -c1 ${hostIp}");
53
+
$machine->succeed("curl --fail http://${hostIp}:${toString hostPort}/ > /dev/null");
55
+
# Stop the container.
56
+
$machine->succeed("nixos-container stop webserver");
57
+
$machine->fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null");
59
+
# Destroying a declarative container should fail.
60
+
$machine->fail("nixos-container destroy webserver");