From 0244a8d5d77102d96496fc624ecb2a441ab6d441 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 27 Apr 2024 00:46:11 +0300 Subject: [PATCH] nixos/caddy: don't set ExecReload if enableReload is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, setting services.caddy.enableReload to false fails in a very bad fashion: The reload command still gets executed, but fails: ``` Apr 26 21:23:01 n1-rk1 systemd[1]: Reloading Caddy... Apr 26 21:23:01 n1-rk1 caddy[70793]: {"level":"info","ts":1714166581.733018,"msg":"using provided configuration","config_file":"/etc/caddy/caddy_config","config_adapter":"caddyfile"} Apr 26 21:23:01 n1-rk1 caddy[70793]: {"level":"warn","ts":1714166581.7353032,"msg":"Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/caddy_config","line":3} Apr 26 21:23:01 n1-rk1 caddy[70793]: Error: sending configuration to instance: performing request: Post "http://localhost:2019/load": dial tcp [::1]:2019: connect: connection refused Apr 26 21:23:01 n1-rk1 systemd[1]: caddy.service: Control process exited, code=exited, status=1/FAILURE Apr 26 21:23:01 n1-rk1 systemd[1]: Reload failed for Caddy. ``` … and the server is not restarted either, as a ExecReload= command is specified. Fix this, by only setting ExecReload if the reload exists. The first empty string is still necessary to reset the old option. --- nixos/modules/services/web-servers/caddy/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/web-servers/caddy/default.nix b/nixos/modules/services/web-servers/caddy/default.nix index 1cd1448c7d56..064a0c71b586 100644 --- a/nixos/modules/services/web-servers/caddy/default.nix +++ b/nixos/modules/services/web-servers/caddy/default.nix @@ -365,7 +365,7 @@ in # If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect. ExecStart = [ "" ''${cfg.package}/bin/caddy run ${runOptions} ${optionalString cfg.resume "--resume"}'' ]; # Validating the configuration before applying it ensures we’ll get a proper error that will be reported when switching to the configuration - ExecReload = [ "" ''${cfg.package}/bin/caddy reload ${runOptions} --force'' ]; + ExecReload = [ "" ] ++ lib.optional cfg.enableReload "${lib.getExe cfg.package} reload ${runOptions} --force"; User = cfg.user; Group = cfg.group; ReadWritePaths = [ cfg.dataDir ];