2019-11-06 15:56:16 +03:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
2019-10-09 14:32:03 +03:00
|
|
|
name = "caddy";
|
2021-01-10 22:08:30 +03:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2020-11-17 14:02:06 +03:00
|
|
|
maintainers = [ xfix Br1ght0ne ];
|
2019-10-09 14:32:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
webserver = { pkgs, lib, ... }: {
|
|
|
|
services.caddy.enable = true;
|
2022-03-18 03:27:04 +03:00
|
|
|
services.caddy.extraConfig = ''
|
2019-10-09 14:32:03 +03:00
|
|
|
http://localhost {
|
2020-05-08 12:39:24 +03:00
|
|
|
encode gzip
|
2019-10-09 14:32:03 +03:00
|
|
|
|
2020-09-07 10:42:00 +03:00
|
|
|
file_server
|
2020-05-08 12:39:24 +03:00
|
|
|
root * ${
|
2019-10-09 14:32:03 +03:00
|
|
|
pkgs.runCommand "testdir" {} ''
|
|
|
|
mkdir "$out"
|
|
|
|
echo hello world > "$out/example.html"
|
|
|
|
''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2023-02-21 19:21:38 +03:00
|
|
|
services.caddy.enableReload = true;
|
2019-10-09 14:32:03 +03:00
|
|
|
|
2020-03-06 01:07:20 +03:00
|
|
|
specialisation.config-reload.configuration = {
|
2022-03-18 03:27:04 +03:00
|
|
|
services.caddy.extraConfig = ''
|
2020-03-06 01:07:20 +03:00
|
|
|
http://localhost:8080 {
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2021-08-19 17:50:55 +03:00
|
|
|
specialisation.multiple-configs.configuration = {
|
|
|
|
services.caddy.virtualHosts = {
|
|
|
|
"http://localhost:8080" = { };
|
|
|
|
"http://localhost:8081" = { };
|
|
|
|
};
|
|
|
|
};
|
2023-08-22 21:14:35 +03:00
|
|
|
specialisation.rfc42.configuration = {
|
|
|
|
services.caddy.settings = {
|
|
|
|
apps.http.servers.default = {
|
|
|
|
listen = [ ":80" ];
|
|
|
|
routes = [{
|
|
|
|
handle = [{
|
|
|
|
body = "hello world";
|
|
|
|
handler = "static_response";
|
|
|
|
status_code = 200;
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-12-06 23:34:38 +03:00
|
|
|
specialisation.explicit-config-file.configuration = {
|
|
|
|
services.caddy.configFile = pkgs.writeText "Caddyfile" ''
|
|
|
|
localhost:80
|
|
|
|
|
|
|
|
respond "hello world"
|
|
|
|
'';
|
|
|
|
};
|
2019-10-09 14:32:03 +03:00
|
|
|
};
|
2021-09-01 10:15:50 +03:00
|
|
|
};
|
2019-10-09 14:32:03 +03:00
|
|
|
|
2021-09-01 10:15:50 +03:00
|
|
|
testScript = { nodes, ... }:
|
|
|
|
let
|
2023-12-06 23:34:38 +03:00
|
|
|
explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file";
|
2023-02-21 19:21:38 +03:00
|
|
|
justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload";
|
|
|
|
multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs";
|
2023-08-22 21:14:35 +03:00
|
|
|
rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42";
|
2021-09-01 10:15:50 +03:00
|
|
|
in
|
|
|
|
''
|
|
|
|
url = "http://localhost/example.html"
|
|
|
|
webserver.wait_for_unit("caddy")
|
2022-06-11 15:22:53 +03:00
|
|
|
webserver.wait_for_open_port(80)
|
2019-10-09 14:32:03 +03:00
|
|
|
|
|
|
|
|
2021-09-01 10:15:50 +03:00
|
|
|
with subtest("config is reloaded on nixos-rebuild switch"):
|
|
|
|
webserver.succeed(
|
|
|
|
"${justReloadSystem}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
2022-06-11 15:22:53 +03:00
|
|
|
webserver.wait_for_open_port(8080)
|
2023-02-21 19:21:38 +03:00
|
|
|
webserver.fail("journalctl -u caddy | grep -q -i stopped")
|
|
|
|
webserver.succeed("journalctl -u caddy | grep -q -i reloaded")
|
2020-03-06 01:07:20 +03:00
|
|
|
|
2021-09-01 10:15:50 +03:00
|
|
|
with subtest("multiple configs are correctly merged"):
|
|
|
|
webserver.succeed(
|
|
|
|
"${multipleConfigs}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
2022-06-11 15:22:53 +03:00
|
|
|
webserver.wait_for_open_port(8080)
|
|
|
|
webserver.wait_for_open_port(8081)
|
2023-08-22 21:14:35 +03:00
|
|
|
|
|
|
|
with subtest("rfc42 settings config"):
|
|
|
|
webserver.succeed(
|
|
|
|
"${rfc42Config}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
|
|
|
webserver.wait_for_open_port(80)
|
|
|
|
webserver.succeed("curl http://localhost | grep hello")
|
2023-12-06 23:34:38 +03:00
|
|
|
|
|
|
|
with subtest("explicit configFile"):
|
|
|
|
webserver.succeed(
|
|
|
|
"${explicitConfigFile}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
|
|
|
webserver.wait_for_open_port(80)
|
|
|
|
webserver.succeed("curl http://localhost | grep hello")
|
2021-09-01 10:15:50 +03:00
|
|
|
'';
|
|
|
|
})
|