You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
0.kind: enhancementAdd something new or improve an existing system.2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
#24664 added config file syntax checking using nginx -t in preStart of the systemd unit.
In #24664 (comment)@volth suggested to check it also at nix-evaluation time, thus failing even earlier. An example was provided for how to do it for Varnish, we'd have to do the same for nginx.
I think this is a great idea; this issue tracks doing that.
Or the time might be passed as an argument of the evaluation
This would certainly work.
I'd go step by step though: Keeping this issue about syntax validity (I think we all want that), and if we want time checks, put that into a different issue.
Do you actually mean evaluation time, or build time? #32062 is a build time check.
Note BTW that build-time configuration file checks often break if they refer to directories or users that don't exist yet. E.g. httpd -t fails if the user account mentioned in User doesn't exist yet.
And dns or hostnames in case of nginx. This could work in special cases, if the user takes care of it, but not in general. In other words, I could imagine an optional function that takes the configuration as input and returns a new store paths while checking the syntax - users would have to enable this feature and it would be required to disable sandboxes for this to work.
Do you actually mean evaluation time, or build time?
Sorry, build time. Will update the description.
Note BTW that build-time configuration file checks often break if they refer to directories or users that don't exist yet. E.g. httpd -t fails if the user account mentioned in User doesn't exist yet.
And dns or hostnames in case of nginx. This could work in special cases, if the user takes care of it, but not in general. In other words, I could imagine an optional function that takes the configuration as input and returns a new store paths while checking the syntax - users would have to enable this feature and it would be required to disable sandboxes for this to work.
Good points. Let's make it optional then.
I also found that nginx supports two kinds of validity checks:
# /nix/store/rzssgadfwrsbclpksvcy1zx39m50ry7r-nginx-1.12.2/bin/nginx -t -c /nix/store/lk94mvs3pv1ns9qv7zg0fhm07c7sic25-nginx.conf
nginx: [alert] could not open error log file: open() "/nix/store/rzssgadfwrsbclpksvcy1zx39m50ry7r-nginx-1.12.2/logs/error.log" failed (30: Read-only file system)
nginx: the configuration file /nix/store/lk94mvs3pv1ns9qv7zg0fhm07c7sic25-nginx.conf syntax is ok
2018/06/27 17:03:54 [emerg] 31414#31414: open() "/nix/store/rzssgadfwrsbclpksvcy1zx39m50ry7r-nginx-1.12.2/logs/nginx.pid" failed (30: Read-only file system)
nginx: configuration file /nix/store/lk94mvs3pv1ns9qv7zg0fhm07c7sic25-nginx.conf test failed
Notice how it does do syntax checks (syntax is ok), and configuration sensibleness checks (test failed).
Also funny how without further configuration it seems to think error.log and nginx.pid are supposed to be in the nix store (of course that can't work).
There could be a hook in switch-to-configuration that is runs in a mount namespace with the updated new /etc mounted but without any other sandbox. This hook then could run before any old service is stopped. The check would be something like (in pseudo-shell script):
$ unshare --mount
$namespace> mount --rbind / /tmp/sandbox
$namespace> mount --bind /nix/store/rghlmlk27y5ym6jnz7kv9nvp5n6wbqli-etc/etc /tmp/sandbox/etc/static
$namespace> chroot /tmp/sandbox /nix/store/<hash>-config-check || rollback
I am not sure how to cover things like /etc/passwd in this case. Maybe those special cases are simple enough to be be copied over somehow.
If somebody wants to implement this, but need some help with Linux namespaces, I can share my knowledge about this.
Notice how it does do syntax checks (syntax is ok), and configuration sensibleness checks (test failed).
I've had a quick look into the nginx source code; it doesn't right now give a super easy way to check only the syntax, and the function that parses the config (ngx_conf_parse()) cannot be called without initialisation of some other, rather global nginx stuff.
Hmm, this catches the most extreme syntax errors (like forgetting }), but doesn't seem to catch more basic syntax errors (forgetting ;) and also doesn't seem to have any idea over what directives nginx supports (e.g. you can change listen to listena and it's happy with that.
It feels like we need to urge upstream to get a "pure" syntax checking feature in to do this well.
I had a few instances where silly mistakes like forgetting a ; or writing incorrect try_files directives took down nginx, because the configuration built fine, but nginx -t failed in the pre start. Seems like there are some cases that are not handled by gixy.
If nginx -t is still that impure that it's not feasible to use it at build time after gixy, we could revisit running it during switch-to-configuration.
0.kind: enhancementAdd something new or improve an existing system.2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Activity
nh2 commentedon Mar 2, 2018
That sounds pretty impure though, can that even work when building in the sandbox, where time is stopped?
nh2 commentedon Mar 5, 2018
This would certainly work.
I'd go step by step though: Keeping this issue about syntax validity (I think we all want that), and if we want time checks, put that into a different issue.
edolstra commentedon Mar 5, 2018
Do you actually mean evaluation time, or build time? #32062 is a build time check.
Note BTW that build-time configuration file checks often break if they refer to directories or users that don't exist yet. E.g.
httpd -tfails if the user account mentioned inUserdoesn't exist yet.Mic92 commentedon Mar 5, 2018
And dns or hostnames in case of nginx. This could work in special cases, if the user takes care of it, but not in general. In other words, I could imagine an optional function that takes the configuration as input and returns a new store paths while checking the syntax - users would have to enable this feature and it would be required to disable sandboxes for this to work.
nh2 commentedon Jun 27, 2018
Sorry, build time. Will update the description.
Good points. Let's make it optional then.
I also found that nginx supports two kinds of validity checks:
Notice how it does do syntax checks (
syntax is ok), and configuration sensibleness checks (test failed).Also funny how without further configuration it seems to think
error.logandnginx.pidare supposed to be in the nix store (of course that can't work).Mic92 commentedon Jun 27, 2018
There could be a hook in switch-to-configuration that is runs in a mount namespace with the updated new
/etcmounted but without any other sandbox. This hook then could run before any old service is stopped. The check would be something like (in pseudo-shell script):I am not sure how to cover things like /etc/passwd in this case. Maybe those special cases are simple enough to be be copied over somehow.
If somebody wants to implement this, but need some help with Linux namespaces, I can share my knowledge about this.
nh2 commentedon Jun 28, 2018
I've had a quick look into the nginx source code; it doesn't right now give a super easy way to check only the syntax, and the function that parses the config (
ngx_conf_parse()) cannot be called without initialisation of some other, rather global nginx stuff.Mic92 commentedon Jun 28, 2018
I can easily imagine this, since every module can add additional keywords to the configuration.
nh2 commentedon Jun 28, 2018
Hmm, this catches the most extreme syntax errors (like forgetting
}), but doesn't seem to catch more basic syntax errors (forgetting;) and also doesn't seem to have any idea over what directives nginx supports (e.g. you can changelistentolistenaand it's happy with that.It feels like we need to urge upstream to get a "pure" syntax checking feature in to do this well.
globin commentedon Aug 19, 2019
Handled by gixy. Everything else that really evaluates the config won't work for deployments e.g via nixops.
gepbird commentedon Dec 25, 2025
I had a few instances where silly mistakes like forgetting a
;or writing incorrecttry_filesdirectives took down nginx, because the configuration built fine, butnginx -tfailed in the pre start. Seems like there are some cases that are not handled by gixy.If
nginx -tis still that impure that it's not feasible to use it at build time after gixy, we could revisit running it during switch-to-configuration.[-]nginx: Check syntax also at nix evaluation time[/-][+]nginx: Check syntax also at build time[/+]