1 import ./make-test-python.nix ({ pkgs, ... }: {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ Br1ght0ne ];
8 webserver = { pkgs, lib, ... }: {
9 services.caddy.enable = true;
10 services.caddy.extraConfig = ''
16 pkgs.runCommand "testdir" {} ''
18 echo hello world > "$out/example.html"
23 services.caddy.enableReload = true;
25 specialisation.config-reload.configuration = {
26 services.caddy.extraConfig = ''
27 http://localhost:8080 {
31 specialisation.multiple-configs.configuration = {
32 services.caddy.virtualHosts = {
33 "http://localhost:8080" = { };
34 "http://localhost:8081" = { };
37 specialisation.rfc42.configuration = {
38 services.caddy.settings = {
39 apps.http.servers.default = {
44 handler = "static_response";
51 specialisation.explicit-config-file.configuration = {
52 services.caddy.configFile = pkgs.writeText "Caddyfile" ''
61 testScript = { nodes, ... }:
63 explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file";
64 justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload";
65 multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs";
66 rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42";
69 url = "http://localhost/example.html"
70 webserver.wait_for_unit("caddy")
71 webserver.wait_for_open_port(80)
74 with subtest("config is reloaded on nixos-rebuild switch"):
76 "${justReloadSystem}/bin/switch-to-configuration test >&2"
78 webserver.wait_for_open_port(8080)
79 webserver.fail("journalctl -u caddy | grep -q -i stopped")
80 webserver.succeed("journalctl -u caddy | grep -q -i reloaded")
82 with subtest("multiple configs are correctly merged"):
84 "${multipleConfigs}/bin/switch-to-configuration test >&2"
86 webserver.wait_for_open_port(8080)
87 webserver.wait_for_open_port(8081)
89 with subtest("rfc42 settings config"):
91 "${rfc42Config}/bin/switch-to-configuration test >&2"
93 webserver.wait_for_open_port(80)
94 webserver.succeed("curl http://localhost | grep hello")
96 with subtest("explicit configFile"):
98 "${explicitConfigFile}/bin/switch-to-configuration test >&2"
100 webserver.wait_for_open_port(80)
101 webserver.succeed("curl http://localhost | grep hello")