-
-
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
WIP: nixos/caddy: validate config on build by default #380894
base: master
Are you sure you want to change the base?
Conversation
7e2bddf
to
e9425cc
Compare
e9425cc
to
07dfc55
Compare
validateCaddyConfig = | ||
adapter: configFile: | ||
builtins.fromJSON ( | ||
builtins.readFile ( | ||
pkgs.runCommand "caddy-validate" | ||
{ | ||
nativeBuildInputs = [ cfg.package ]; | ||
} | ||
'' | ||
if caddy validate --adapter ${toString adapter} --config ${configFile}; then | ||
echo "true" > $out | ||
else | ||
echo "false" > $out | ||
fi | ||
'' | ||
) | ||
); | ||
|
||
configValidationResult = validateCaddyConfig ( | ||
if cfg.adapter != null then cfg.adapter else "caddyfile" | ||
) cfg.configFile; |
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.
Import From Derivation (IFD) is actively discouraged. I'd encourage you to implement this similar to services.nginx
(through the use of pkgs.writes.writeNginxConfig
) which writes the configuration file as part of the derivation, but fails to build if it is incorrent.
@@ -378,6 +400,16 @@ in | |||
[here](https://caddyserver.com/docs/caddyfile/concepts#environment-variables) | |||
''; | |||
}; | |||
|
|||
enforceConfigValidation = mkOption { |
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.
Nit: for consistency with Nginx, I'd name this option validateConfigFile
.
webserver.wait_for_unit("caddy") | ||
|
||
with subtest("invalid config fails build when validation is enforced"): | ||
webserver.fail( |
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.
todo: the build is expect to fail ... so i need to check against that differently ...
Adds
enforceConfigValidation
option (default: true) to validate Caddyconfigurations during system build. This catches configuration errors early
in the deployment pipeline, improving reliability and security of Caddy
deployments.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-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.