at master 1.1 kB view raw
1{ pkgs, lib, ... }: 2{ 3 name = "static-web-server"; 4 meta = { 5 maintainers = with lib.maintainers; [ mac-chaffee ]; 6 }; 7 8 nodes.machine = 9 { pkgs, ... }: 10 { 11 services.static-web-server = { 12 enable = true; 13 listen = "[::]:8080"; 14 root = toString ( 15 pkgs.writeTextDir "nixos-test.html" '' 16 <h1>Hello NixOS!</h1> 17 '' 18 ); 19 configuration = { 20 general = { 21 directory-listing = true; 22 }; 23 }; 24 }; 25 }; 26 27 testScript = '' 28 machine.start() 29 machine.wait_for_unit("static-web-server.socket") 30 machine.wait_for_open_port(8080) 31 # We don't use wait_until_succeeds() because we're testing socket 32 # activation which better work on the first request 33 response = machine.succeed("curl -fsS localhost:8080") 34 assert "nixos-test.html" in response, "The directory listing page did not include a link to our nixos-test.html file" 35 response = machine.succeed("curl -fsS localhost:8080/nixos-test.html") 36 assert "Hello NixOS!" in response 37 machine.wait_for_unit("static-web-server.service") 38 ''; 39}