Skip to content
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: validate at build-time #377075

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Stunkymonkey
Copy link
Contributor

@Stunkymonkey Stunkymonkey commented Jan 26, 2025

its nice to validate the config before reloading/restarting. same as nginx

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jan 26, 2025
@Stunkymonkey Stunkymonkey requested a review from sephii January 26, 2025 19:22
@Stunkymonkey Stunkymonkey marked this pull request as ready for review January 26, 2025 19:22
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 26, 2025
@sephii
Copy link
Contributor

sephii commented Jan 26, 2025

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?

@Stunkymonkey
Copy link
Contributor Author

@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.

@Stunkymonkey Stunkymonkey marked this pull request as draft January 26, 2025 21:35
@Stunkymonkey Stunkymonkey force-pushed the caddy-validate branch 3 times, most recently from aa16781 to 59bfa80 Compare January 27, 2025 22:45
@Stunkymonkey
Copy link
Contributor Author

Stunkymonkey commented Jan 27, 2025

@sephii validating is a bit weird. caddy validate results into:

       > 2025/01/27 21:46:30.999 INFO    using config from file  {"file": "/nix/store/kz8lm6k81lsmziphpq0mfhdrv4nx049v-Caddyfile-formatted/Caddyfile"}
       > 2025/01/27 21:46:31.009 INFO    adapted config to JSON  {"adapter": "caddyfile"}
       > Error: setting up custom log 'log1': opening log writer using &logging.FileWriter{Filename:"/var/log/caddy/access-http:__localhost:8081.log", Mode:0x0, Roll:(*bool)(nil), RollSizeMB:0, RollCompress:(*bool)(nil), RollLocalTime:false, RollKeep:0, RollKeepDays:0}: mkdir /var: permission denied

it always wants to start and log the events, which can not work... so then i discovered caddy adapt, which validates the config itself. But somehow the json-test is not working any more, because of:

       last 1 log lines:
       > Error: Unexpected '{' on a new line; did you mean to place the '{' on the previous line?, at /nix/store/f2927acpq53srgy3sl722ssqj4yrn60k-caddy.json:10
       For full logs, run 'nix log /nix/store/b6ccpz1rfqvnj4ysdm4qmf5m4wb7r4vd-validate-caddy-config.drv'.

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

@sephii
Copy link
Contributor

sephii commented Feb 5, 2025

Sorry I’m very busy these days. I’ll give it a look soon, maybe next week!

@Stunkymonkey
Copy link
Contributor Author

@sephii no problem. thanks for reaching out.

@Stunkymonkey
Copy link
Contributor Author

I am currently stuck here caddyserver/caddy#6788 (comment) .

@mohammed90
Copy link

caddy adapt, which validates the config itself

That's not what adapt does. It doesn't validate config. It only converts it from whatever format the specified adapter accepts to JSON. The validation is something separate.

@Stunkymonkey Stunkymonkey force-pushed the caddy-validate branch 4 times, most recently from c985fbd to da256cd Compare February 13, 2025 21:00
@Stunkymonkey Stunkymonkey changed the title nixos/caddy: validate before start nixos/caddy: validate at build-time Feb 13, 2025
@Stunkymonkey Stunkymonkey marked this pull request as ready for review February 13, 2025 21:02
@Stunkymonkey
Copy link
Contributor Author

@sephii i finally managed to put something together. please take your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants