1 import ./make-test-python.nix (
4 name = "containers-ephemeral";
6 maintainers = with lib.maintainers; [ patryk27 ];
12 virtualisation.writableStore = true;
14 containers.webserver = {
16 privateNetwork = true;
17 hostAddress = "10.231.136.1";
18 localAddress = "10.231.136.2";
22 virtualHosts.localhost = {
23 root = pkgs.runCommand "localhost" { } ''
25 echo hello world > "$out/index.html"
29 networking.firewall.allowedTCPPorts = [ 80 ];
35 assert "webserver" in machine.succeed("nixos-container list")
37 machine.succeed("nixos-container start webserver")
39 with subtest("Container got its own root folder"):
40 machine.succeed("ls /run/nixos-containers/webserver")
42 with subtest("Container persistent directory is not created"):
43 machine.fail("ls /var/lib/nixos-containers/webserver")
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").rstrip()
48 machine.succeed(f"ping -n -c1 {ip}")
49 machine.succeed(f"curl --fail http://{ip}/ > /dev/null")
51 with subtest("Stop the container"):
52 machine.succeed("nixos-container stop webserver")
53 machine.fail(f"curl --fail --connect-timeout 2 http://{ip}/ > /dev/null")
55 with subtest("Container's root folder was removed"):
56 machine.fail("ls /run/nixos-containers/webserver")