-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/caddy: add support for Caddy v2 #86686
Conversation
25e256a
to
72b9184
Compare
@GrahamcOfBorg test caddy |
a36379a
to
598dae6
Compare
- Update configuration syntax - Add filalex77 as a maintainer
Rename legacy v1 to `caddy1`
598dae6
to
4d7b3c2
Compare
@xfix I removed the commit adding |
${cfg.package}/bin/caddy adapt \ | ||
--config ${configFile} --adapter ${cfg.adapter} > $out | ||
''); | ||
# TODO: validate with `caddy validate`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we actually want caddy validate
as I mentioned earlier (mostly because it verifies paths exist, and it's reasonable that they may not exist in build environment due to being outside nix store).
# TODO: validate with `caddy validate`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to add on, adapt
validates the input config (check its syntax) by default and will return error 1 when encounter invalid input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine, it's mergeable after the TODO comment gets deleted.
|
There are 2 official upstream systemd service files with explanation at https://github.com/caddyserver/dist/tree/master/init. In compare to v1 the Caddy v2 starts without configuration file and best practice in v2 is to use API to upload config. JSON is native format, but with simple curl POST it is possible to upload regular Caddyfile too. Caddy reloads last state after restart. All that is working with https://github.com/caddyserver/dist/blob/master/init/caddy-api.service. In my opinion that this should be default in NixOS. The configuration file should be added to command line arguments only if additional parameters related to configuration source and provider are specified. |
It would be really nice to have this in 20.09. :) can I help in some way? |
@filalex77 What is the status of this pull request? I really would like to have this in NixOS 20.09. My opinion is that we don't need Caddy API support for 20.09. It could be implemented in the future, but I don't think it should block Caddy v2 support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID";
should be changed to use caddy reload --config ${path}
instead for Caddy 2 as USR1 signal is no longer supported.
I've opened a new PR which addresses the remaining comments in the hope of getting this in 20.09. I've also rebased on current master. I still have problems with running tests though, any help is appreciated. |
Motivation for this change
Caddy v2 was recently released.
While v2 support is necessary, configs for v1 shouldn't break (at least until 20.09).
Things done
This PR adds support for Caddy v2, and uses it by default, while still allowing users to opt-in to using Caddy v1.
Added
services.caddy.adapter
for supporting config formats other than Caddyfile.See https://caddyserver.com/docs/config-adapters.
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)