nixos/caddy: validate at build-time#377075
Conversation
|
We used to have this done in the build phase (which, in my opinion, is a better place to have it) before it was removed in 27b7132 (because the way it was done caused an import from derivation, but I think it can be easily adapted). How about doing the check in the build phase? |
|
@sephii doing this while building is an ever better idea. To catch the errors as early as possible. I am marking my MR as draft and ping you again if I have something. Thanks for the fast response. |
aa16781 to
59bfa80
Compare
|
@sephii validating is a bit weird. it always wants to start and log the events, which can not work... so then i discovered but the config is a valid json... not sure why caddy does this: https://github.com/caddyserver/caddy/blob/9996d6a70ba76a94dfc90548f25fbac0ce9da497/caddyconfig/caddyfile/parse.go#L656 |
|
Sorry I’m very busy these days. I’ll give it a look soon, maybe next week! |
|
@sephii no problem. thanks for reaching out. |
59bfa80 to
e79afe2
Compare
|
I am currently stuck here caddyserver/caddy#6788 (comment) . |
That's not what |
da256cd to
2de2277
Compare
|
@sephii i finally managed to put something together. please take your time. |
|
Ok I finally got some time for this, thanks for your patience. Based on your code I worked out a different implementation that does not rely on an assertion but on running the I’ll let you check it out and make changes to your PR if you think it’s good, otherwise please let me know. |
2de2277 to
7449208
Compare
|
@sephii thanks for this. much more cleaner and simpler. lets not over-complicate it. |
|
Could you please also revert the change to the |
7449208 to
911bc6f
Compare
911bc6f to
63b6df4
Compare
|
@sephii should be correct now. thanks for your help and your suggestions. |
sephii
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/5269 |
|
@sephii are you fine with merging? I could do it, or do you want additional reviewer? |
|
If you can merge it, please do! |
|
|
||
| # 'validate' cannot be used for validation, due to log location access | ||
| # See https://github.com/caddyserver/caddy/issues/6788 | ||
| ${lib.getExe cfg.package} adapt --config $out/Caddyfile |
There was a problem hiding this comment.
This breaks cross-compiled nixos configs, since you can't run a non native binary on a different kind of build machine.
There was a problem hiding this comment.
Would it be enough to pass cfg.package as a native build input on line 53 and then just call caddy adapt?
|
Have you tested this with environment variables? I use an environment variable for API token and the build fails with The environment variable is obviously not available at build time. |
|
This seems indeed incompatible with local validation. How about we add a I suggest we also add an entry to the release notes since this change is not as backwards compatible as I thought (or set |
If this breaks everyone passing API tokens with the
If this is limited to environment variables, we could set |
|
maybe we should merge #393806 until we figured out the rest of the problems sorry for the delayed response, I was ill for a few days |
|
there was #380894 already dealing with this stuff ... |
|
@Stunkymonkey you removed the |
|
PS: we should make it a config to disable it! as there are cases where it will fail! example: have static own ssl certs on the target host but not on the build host ... |
|
ok I have updated #380894 ... |
This PR was created on Jan 26, your PR was created on Feb 10. Your PR seems to suffer from the same problem that was mentioned in this discussion regarding the use of environment variables in the Caddy config. We should either disable the configuration check at build time by default, or find a way to only enable it if we’re sure the config can be checked locally. |
|
the default setup can be enabled only quite complex can not ... and in this case the option can simply be disabled ... |
its nice to validate the config before reloading/restarting. same as nginx
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.