-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Nginx formatter #34985
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
Nginx formatter #34985
Conversation
@GrahamcOfBorg test nginx |
Success on x86_64-linux (full log) Partial log (click to expand)
|
Success on aarch64-linux (full log) Partial log (click to expand)
|
Very cool! |
Could we add an option for it so it can be turned off? I want to use it myself, but I know that others (e362a3d#commitcomment-20787179) would like to not have to hard-depend on Python for changing nginx configs. |
Maybe make it opt-in? Everybody who cares about it, can temporary turn it on or leave it on all the time. |
This reverts commit 6e12406, and causes the nginx test to fail.
This fixes the nginx test failure.
9fcac9e
to
47aa537
Compare
I've added an option. I'd prefer to not default it to false, as anyone attempting to debug their nginx configs is unlikely to guess that the option exists, given that most other NixOS config files don't have this functionality. (Which is a problem in itself, but not in scope of this PR.) |
@GrahamcOfBorg test nginx |
1 similar comment
@GrahamcOfBorg test nginx |
Success on x86_64-linux (full log) Partial log (click to expand)
|
Success on aarch64-linux (full log) Partial log (click to expand)
|
@Baughn ok. In the unlikely case of bugs in the formatter, it could then at least be disabled. |
|
||
configFileFormatted = pkgs.runCommand "nginx.conf" { | ||
inherit configFileUnformatted; | ||
passAsFile = [ "configFileUnformatted" ]; |
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.
I do not think that these two lines are needed because the reference to configFileUnformatted
in the multi-line string below is directly to the store path that writeText
creates a few lines further down.
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.
@Baughn I can confirm the above two lines are not necessary.
Could you remove them? I would love to have this merged.
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.
See other review (just marking as changes requested).
I'm really not in favor of this. Both pulling in python and having a new option sound like bad solutions to the problem. When we are the ones who generate such a crippled Nix file, we should also be responsible for fixing it! The solution I'm proposing is to generate the file in a way similar to what I've done in #45470. That is, having a As a side effect this has the advantage that users are able to override default settings easily. A slight problem with this is that verbatim options can't be formatted this way, but if such a As an example, this is how the start of the config as specified in nginx/default.nix could look like: {
config = {
user = "${cfg.user} ${cfg.group}";
error_log = cfg.logError;
daemon = false;
# No need for null check, null values automatically have no effect
events = cfg.eventsConfig;
http = mkIf cfg.recommendedOptimisation {
sendfile = true;
tcp_nopush = true;
tcp_nodelay = true;
keepalive_timeout = 65;
types_hash_max_size = 2048;
} // {
# A list generates a key-value entry for every element
include = [
"${cfg.package}/conf/mime.types"
"${cfg.package}/conf/fastcgi.conf"
"${cfg.package}/conf/uwsgi_params"
];
resolver = mkIf (cfg.resolver.addresses != [])
"${toString cfg.resolver.addresses} ${optionalString (cfg.resolver.valid != "") "valid=${cfg.resolver.valid}"}";
ssl_protocols = cfg.sslProtocols;
};
};
} |
Maybe this should be closed as #57979 was merged? |
Motivation for this change
This makes nginx.conf human-readable.
While nominally the file is not meant for human consumption, in practice I commonly need to manually inspect the output of complex nginx configurations to verify that it actually looks the way I want. Being able to read it is therefore useful.
Before formatting: http://ix.io/K9v
After formatting: http://ix.io/K9k
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)