at master 1.8 kB view raw
1{ pkgs, lib, ... }: 2{ 3 name = "containers-ephemeral"; 4 meta = { 5 maintainers = with lib.maintainers; [ patryk27 ]; 6 }; 7 8 nodes.machine = 9 { pkgs, ... }: 10 { 11 virtualisation.writableStore = true; 12 13 containers.webserver = { 14 ephemeral = true; 15 privateNetwork = true; 16 hostAddress = "10.231.136.1"; 17 localAddress = "10.231.136.2"; 18 config = { 19 services.nginx = { 20 enable = true; 21 virtualHosts.localhost = { 22 root = pkgs.runCommand "localhost" { } '' 23 mkdir "$out" 24 echo hello world > "$out/index.html" 25 ''; 26 }; 27 }; 28 networking.firewall.allowedTCPPorts = [ 80 ]; 29 }; 30 }; 31 }; 32 33 testScript = '' 34 assert "webserver" in machine.succeed("nixos-container list") 35 36 machine.succeed("nixos-container start webserver") 37 38 with subtest("Container got its own root folder"): 39 machine.succeed("ls /run/nixos-containers/webserver") 40 41 with subtest("Container persistent directory is not created"): 42 machine.fail("ls /var/lib/nixos-containers/webserver") 43 44 # Since "start" returns after the container has reached 45 # multi-user.target, we should now be able to access it. 46 ip = machine.succeed("nixos-container show-ip webserver").rstrip() 47 machine.succeed(f"ping -n -c1 {ip}") 48 machine.succeed(f"curl --fail http://{ip}/ > /dev/null") 49 50 with subtest("Stop the container"): 51 machine.succeed("nixos-container stop webserver") 52 machine.fail(f"curl --fail --connect-timeout 2 http://{ip}/ > /dev/null") 53 54 with subtest("Container's root folder was removed"): 55 machine.fail("ls /run/nixos-containers/webserver") 56 ''; 57}