nixos/caddy: use v2 by default

This commit is contained in:
Oleksii Filonenko 2020-05-08 09:35:55 +00:00 committed by Sylvain Fankhauser
parent 8cc592abfa
commit d71cadacd9
No known key found for this signature in database
GPG Key ID: 4228AB9EC0612ADA

View File

@ -20,6 +20,7 @@ let
${cfg.package}/bin/caddy adapt \ ${cfg.package}/bin/caddy adapt \
--config ${configFile} --adapter ${cfg.adapter} > $out --config ${configFile} --adapter ${cfg.adapter} > $out
''); '');
# TODO: validate with `caddy validate`?
configJSON = pkgs.writeText "caddy-config.json" (builtins.toJSON configJSON = pkgs.writeText "caddy-config.json" (builtins.toJSON
(recursiveUpdate adaptedConfig tlsConfig)); (recursiveUpdate adaptedConfig tlsConfig));
in { in {
@ -28,18 +29,18 @@ in {
config = mkOption { config = mkOption {
default = ""; default = "";
# TODO: update example text on v2.0 release
example = '' example = ''
example.com { example.com {
gzip encode gzip
minify log
log syslog
root /srv/http root /srv/http
} }
''; '';
type = types.lines; type = types.lines;
description = "Verbatim Caddyfile to use"; description = ''
Verbatim Caddyfile to use.
Caddy v2 supports multiple config formats via adapters (see <option>services.caddy.adapter</option>).
'';
}; };
adapter = mkOption { adapter = mkOption {
@ -47,8 +48,7 @@ in {
example = "nginx"; example = "nginx";
type = types.str; type = types.str;
description = '' description = ''
Name of the config adapter to use. Name of the config adapter to use. Not applicable to Caddy v1.
See https://caddyserver.com/docs/config-adapters for the full list. See https://caddyserver.com/docs/config-adapters for the full list.
''; '';
}; };
@ -79,19 +79,20 @@ in {
The data directory, for storing certificates. Before 17.09, this The data directory, for storing certificates. Before 17.09, this
would create a .caddy directory. With 17.09 the contents of the would create a .caddy directory. With 17.09 the contents of the
.caddy directory are in the specified data directory instead. .caddy directory are in the specified data directory instead.
Caddy v2 replaced CADDYPATH with XDG directories.
See https://caddyserver.com/docs/conventions#file-locations.
''; '';
}; };
package = mkOption { package = mkOption {
default = pkgs.caddy; default = pkgs.caddy2;
defaultText = "pkgs.caddy"; defaultText = "pkgs.caddy2";
example = "pkgs.caddy2"; example = "pkgs.caddy";
type = types.package; type = types.package;
description = '' description = ''
Caddy package to use. Caddy package to use.
To use Caddy v1 (obsolete), set this to <option>pkgs.caddy</option>.
Note: to use Caddy v2, set this to <option>pkgs.caddy2</option>.
v2 will become the default after it is released.
''; '';
}; };
}; };
@ -99,7 +100,7 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services.caddy = { systemd.services.caddy = {
description = "Caddy web server"; description = "Caddy web server";
# upstream unit: https://github.com/caddyserver/caddy/blob/master/dist/init/linux-systemd/caddy.service # upstream unit: https://github.com/caddyserver/dist/blob/master/init/caddy.service
after = [ "network-online.target" ]; after = [ "network-online.target" ];
wants = [ "network-online.target" ]; # systemd-networkd-wait-online.service wants = [ "network-online.target" ]; # systemd-networkd-wait-online.service
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];