1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "containers-ephemeral";
4 maintainers = with lib.maintainers; [ patryk27 ];
7 nodes.machine = { pkgs, ... }: {
8 virtualisation.writableStore = true;
10 containers.webserver = {
12 privateNetwork = true;
13 hostAddress = "10.231.136.1";
14 localAddress = "10.231.136.2";
18 virtualHosts.localhost = {
19 root = pkgs.runCommand "localhost" {} ''
21 echo hello world > "$out/index.html"
25 networking.firewall.allowedTCPPorts = [ 80 ];
31 assert "webserver" in machine.succeed("nixos-container list")
33 machine.succeed("nixos-container start webserver")
35 with subtest("Container got its own root folder"):
36 machine.succeed("ls /run/nixos-containers/webserver")
38 with subtest("Container persistent directory is not created"):
39 machine.fail("ls /var/lib/nixos-containers/webserver")
41 # Since "start" returns after the container has reached
42 # multi-user.target, we should now be able to access it.
43 ip = machine.succeed("nixos-container show-ip webserver").rstrip()
44 machine.succeed(f"ping -n -c1 {ip}")
45 machine.succeed(f"curl --fail http://{ip}/ > /dev/null")
47 with subtest("Stop the container"):
48 machine.succeed("nixos-container stop webserver")
49 machine.fail(f"curl --fail --connect-timeout 2 http://{ip}/ > /dev/null")
51 with subtest("Container's root folder was removed"):
52 machine.fail("ls /run/nixos-containers/webserver")