summary refs log tree commit diff
path: root/nixos/tests/containers-ephemeral.nix
diff options
context:
space:
mode:
authorNikita Uvarov <uv.nikita@gmail.com>2019-08-18 21:37:38 +0200
committerNikita Uvarov <uv.nikita@gmail.com>2019-08-19 15:21:35 +0200
commitc740f0d4003330cd902de72fdb124ce276616d33 (patch)
tree4ee30c3821f775f73d55fc41f5cf3d7e0755d1fd /nixos/tests/containers-ephemeral.nix
parent44099371b245326a86370a92f5ee0f17a491d764 (diff)
downloadnixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.tar
nixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.tar.gz
nixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.tar.bz2
nixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.tar.lz
nixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.tar.xz
nixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.tar.zst
nixpkgs-c740f0d4003330cd902de72fdb124ce276616d33.zip
nixos/containers: add 'ephemeral' option
Diffstat (limited to 'nixos/tests/containers-ephemeral.nix')
-rw-r--r--nixos/tests/containers-ephemeral.nix56
1 files changed, 56 insertions, 0 deletions
diff --git a/nixos/tests/containers-ephemeral.nix b/nixos/tests/containers-ephemeral.nix
new file mode 100644
index 00000000000..1ef8717d9a0
--- /dev/null
+++ b/nixos/tests/containers-ephemeral.nix
@@ -0,0 +1,56 @@
+# Test for NixOS' container support.
+
+import ./make-test.nix ({ pkgs, ...} : {
+  name = "containers-ephemeral";
+
+  machine = { pkgs, ... }: {
+    virtualisation.memorySize = 768;
+    virtualisation.writableStore = true;
+
+    containers.webserver = {
+      ephemeral = true;
+      privateNetwork = true;
+      hostAddress = "10.231.136.1";
+      localAddress = "10.231.136.2";
+      config = {
+        services.nginx = {
+          enable = true;
+          virtualHosts.localhost = {
+            root = (pkgs.runCommand "localhost" {} ''
+              mkdir "$out"
+              echo hello world > "$out/index.html"
+            '');
+          };
+        };
+        networking.firewall.allowedTCPPorts = [ 80 ];
+      };
+    };
+  };
+
+  testScript = ''
+    $machine->succeed("nixos-container list") =~ /webserver/ or die;
+
+    # Start the webserver container.
+    $machine->succeed("nixos-container start webserver");
+
+    # Check that container got its own root folder
+    $machine->succeed("ls /run/containers/webserver");
+
+    # Check that container persistent directory is not created
+    $machine->fail("ls /var/lib/containers/webserver");
+
+    # Since "start" returns after the container has reached
+    # multi-user.target, we should now be able to access it.
+    my $ip = $machine->succeed("nixos-container show-ip webserver");
+    chomp $ip;
+    $machine->succeed("ping -n -c1 $ip");
+    $machine->succeed("curl --fail http://$ip/ > /dev/null");
+
+    # Stop the container.
+    $machine->succeed("nixos-container stop webserver");
+    $machine->fail("curl --fail --connect-timeout 2 http://$ip/ > /dev/null");
+
+    # Check that container's root folder was removed
+    $machine->fail("ls /run/containers/webserver");
+  '';
+})