diff --git a/nixos/modules/services/web-servers/caddy.nix b/nixos/modules/services/web-servers/caddy.nix index e5f1df774bbc..dda26fe491a1 100644 --- a/nixos/modules/services/web-servers/caddy.nix +++ b/nixos/modules/services/web-servers/caddy.nix @@ -16,13 +16,15 @@ let }; }]; }; - adaptedConfig = importJSON (pkgs.runCommand "caddy-config-adapted.json" { } '' + + adaptedConfig = pkgs.runCommand "caddy-config-adapted.json" { } '' ${cfg.package}/bin/caddy adapt \ --config ${configFile} --adapter ${cfg.adapter} > $out - ''); - # TODO: validate with `caddy validate`? - configJSON = pkgs.writeText "caddy-config.json" (builtins.toJSON - (recursiveUpdate adaptedConfig tlsConfig)); + ''; + tlsJSON = pkgs.writeText "tls.json" (builtins.toJSON tlsConfig); + configJSON = pkgs.runCommand "caddy-config.json" { } '' + ${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${adaptedConfig} ${tlsJSON} > $out + ''; in { options.services.caddy = { enable = mkEnableOption "Caddy web server"; @@ -114,7 +116,11 @@ in { -root=/var/tmp -conf=${configFile} \ -ca=${cfg.ca} -email=${cfg.email} ${optionalString cfg.agree "-agree"} ''; - ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID"; + ExecReload = + if isCaddy2 then + "${cfg.package}/bin/caddy reload --config ${configJSON}" + else + "${pkgs.coreutils}/bin/kill -USR1 $MAINPID"; Type = "simple"; User = "caddy"; Group = "caddy"; diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix index e9a93df4f486..445a7fa6b0b4 100644 --- a/nixos/tests/caddy.nix +++ b/nixos/tests/caddy.nix @@ -11,6 +11,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { http://localhost { encode gzip + file_server root * ${ pkgs.runCommand "testdir" {} '' mkdir "$out" @@ -25,6 +26,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { http://localhost { encode gzip + file_server root * ${ pkgs.runCommand "testdir2" {} '' mkdir "$out" @@ -59,9 +61,11 @@ import ./make-test-python.nix ({ pkgs, ... }: { ) etag = etag.replace("\r\n", " ") http_code = webserver.succeed( - "curl -w \"%{{http_code}}\" -X HEAD -H 'If-None-Match: {}' {}".format(etag, url) + "curl --silent --show-error -o /dev/null -w \"%{{http_code}}\" --head -H 'If-None-Match: {}' {}".format( + etag, url + ) ) - assert int(http_code) == 304, "HTTP code is not 304" + assert int(http_code) == 304, "HTTP code is {}, expected 304".format(http_code) return etag diff --git a/pkgs/servers/caddy/v1.nix b/pkgs/servers/caddy/v1.nix index bcd4b7065b58..8a18904af2c8 100644 --- a/pkgs/servers/caddy/v1.nix +++ b/pkgs/servers/caddy/v1.nix @@ -14,7 +14,8 @@ buildGoModule rec { rev = "v${version}"; sha256 = "0jrhwmr6gggppskg5h450wybzkv17iq69dgw36hd1dp56q002i7g"; }; - modSha256 = "1gc0xvsihr4zp7hkrdfrplvzkaphz1y4q53rgwn2jhd8s98l57an"; + + vendorSha256 = "09vnci9pp8zp7bvn8zj68wslz2nc54nhcd0ll31sqfjbp00215mj"; preBuild = '' cat << EOF > caddy/main.go diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dba9d0c793b7..a3e555215477 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1507,8 +1507,8 @@ in ''; }); - caddy = callPackage ../servers/caddy { }; - caddy1 = callPackage ../servers/caddy/v1.nix { }; + caddy = callPackage ../servers/caddy { buildGoModule = buildGo114Module; }; # https://github.com/lucas-clemente/quic-go/issues/2614 + caddy1 = callPackage ../servers/caddy/v1.nix { buildGoModule = buildGo114Module; }; traefik = callPackage ../servers/traefik { }; calamares = libsForQt5.callPackage ../tools/misc/calamares {