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.
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.
to add on, adapt validates the input config (check its syntax) by default and will return error 1 when encounter invalid input.
sugar700
left a comment
There was a problem hiding this comment.
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. |
|
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.adapterfor supporting config formats other than Caddyfile.See https://caddyserver.com/docs/config-adapters.
sandboxinnix.confon non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"./result/bin/)nix path-info -Sbefore and after)