From ff07c07608740e2297605b9b0b6d47a84d4126a3 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Tue, 7 Jan 2025 14:13:44 +0100 Subject: [PATCH 1/3] nixos/caddy: Fix default log file for http:// hostnames Caddy hostnames can begin with http:// to disable automatic HTTPS. The default value for services.caddy..logFormat puts the hostname in the log filename, resulting in a broken path. Similarly, multiple space-separated host names would not work before. Since version 2.9.0 (commit 7c52e7a), caddy fails to start if it cannot open the log file. This caused NixOS test failures (e.g., nixosTests.dokuwiki). --- nixos/modules/services/web-servers/caddy/vhost-options.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/web-servers/caddy/vhost-options.nix b/nixos/modules/services/web-servers/caddy/vhost-options.nix index 04feb6dc66c67..73ef4b87ee528 100644 --- a/nixos/modules/services/web-servers/caddy/vhost-options.nix +++ b/nixos/modules/services/web-servers/caddy/vhost-options.nix @@ -58,7 +58,7 @@ in logFormat = mkOption { type = types.lines; default = '' - output file ${cfg.logDir}/access-${config.hostName}.log + output file ${cfg.logDir}/access-${lib.replaceStrings [ "/" " " ] [ "_" "_" ] config.hostName}.log ''; defaultText = '' output file ''${config.services.caddy.logDir}/access-''${hostName}.log From 21a14a0881d25aedb99859c62e7603cd76fc546c Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Tue, 7 Jan 2025 18:50:14 +0100 Subject: [PATCH 2/3] nixosTests.caddy: Fix with-plugins hash --- nixos/tests/caddy.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix index 36d0051cf0370..a5ca2f3d29bf7 100644 --- a/nixos/tests/caddy.nix +++ b/nixos/tests/caddy.nix @@ -70,7 +70,7 @@ import ./make-test-python.nix ( services.caddy = { package = pkgs.caddy.withPlugins { plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20241211194404-3865845790a7" ]; - hash = "sha256-zgMdtOJbmtRSfTlrrg8njr11in2C7OAXLB+34V23jek="; + hash = "sha256-BorJJWICgAWU7DrpDZJWifMnIYtGWldt/4S1VELwGJI="; }; configFile = pkgs.writeText "Caddyfile" '' { From dacfe3f0295e4e827048cd08424da628c9ff4802 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Tue, 7 Jan 2025 23:13:54 +0100 Subject: [PATCH 3/3] nixosTests.caddy: Add test for multiple hostnames --- nixos/tests/caddy.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix index a5ca2f3d29bf7..71d73465d0887 100644 --- a/nixos/tests/caddy.nix +++ b/nixos/tests/caddy.nix @@ -41,6 +41,11 @@ import ./make-test-python.nix ( "http://localhost:8081" = { }; }; }; + specialisation.multiple-hostnames.configuration = { + services.caddy.virtualHosts = { + "http://localhost:8080 http://localhost:8081" = { }; + }; + }; specialisation.rfc42.configuration = { services.caddy.settings = { apps.http.servers.default = { @@ -93,6 +98,7 @@ import ./make-test-python.nix ( explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file"; justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload"; multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs"; + multipleHostnames = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-hostnames"; rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42"; withPluginsConfig = "${nodes.webserver.system.build.toplevel}/specialisation/with-plugins"; in @@ -117,6 +123,13 @@ import ./make-test-python.nix ( webserver.wait_for_open_port(8080) webserver.wait_for_open_port(8081) + with subtest("a virtual host with multiple hostnames works"): + webserver.succeed( + "${multipleHostnames}/bin/switch-to-configuration test >&2" + ) + webserver.wait_for_open_port(8080) + webserver.wait_for_open_port(8081) + with subtest("rfc42 settings config"): webserver.succeed( "${rfc42Config}/bin/switch-to-configuration test >&2"