Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
caddy: address remaining MR comments for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
sephii committed Sep 8, 2020
1 parent c3a7c89 commit b8bfe94
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
18 changes: 12 additions & 6 deletions nixos/modules/services/web-servers/caddy.nix
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 6 additions & 2 deletions nixos/tests/caddy.nix
Expand Up @@ -11,6 +11,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
http://localhost {
encode gzip
file_server
root * ${
pkgs.runCommand "testdir" {} ''
mkdir "$out"
Expand All @@ -25,6 +26,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
http://localhost {
encode gzip
file_server
root * ${
pkgs.runCommand "testdir2" {} ''
mkdir "$out"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkgs/servers/caddy/v1.nix
Expand Up @@ -14,7 +14,8 @@ buildGoModule rec {
rev = "v${version}";
sha256 = "0jrhwmr6gggppskg5h450wybzkv17iq69dgw36hd1dp56q002i7g";
};
modSha256 = "1gc0xvsihr4zp7hkrdfrplvzkaphz1y4q53rgwn2jhd8s98l57an";

vendorSha256 = "09vnci9pp8zp7bvn8zj68wslz2nc54nhcd0ll31sqfjbp00215mj";

preBuild = ''
cat << EOF > caddy/main.go
Expand Down
4 changes: 2 additions & 2 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -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 {
Expand Down

0 comments on commit b8bfe94

Please sign in to comment.