Skip to content

nixos/nginx: use nginxfmt and gixy - #57979

Merged
Mic92 merged 2 commits into
NixOS:masterfrom
4z3:writeNginxConfig
Apr 4, 2019
Merged

Mic92 merged 2 commits into
NixOS:masterfrom
4z3:writeNginxConfig

Conversation

@4z3

@4z3 4z3 commented Mar 20, 2019 •

Copy link
Copy Markdown
Contributor
Motivation for this change

Currently nginx.conf gets formatted by an awk script. This PR replaces that script by writeNginxConfig which uses nginx-config-formatter to format, and gixy to analyze nginx configurations.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@4z3
4z3 requested a review from infinisil as a code owner March 20, 2019 18:01
@GrahamcOfBorg GrahamcOfBorg 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/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Mar 20, 2019
@Mic92
Mic92 requested a review from fpletz March 21, 2019 14:49
Comment thread pkgs/build-support/writers/default.nix Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How likely is gixy to break valid configuration?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a opt-out flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how likely it is, but I'd argue that broken configurations should be fixed instead. Alternatively, writeNginxConfig can be overridden. This might not be the most convenient solution, but it's also not too painful either. Basically a writeNginxConfig = self.writeText would be sufficient. Anyway, if it's really desired, we can make it optional, or even pass arguments to gixy (but I haven't needed that myself before).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could test on master and see how many people would complain about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here to complain about it, breaks generic forward proxy configs

@TomSmeets TomSmeets left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails with:

error: attribute 'writeNginxConfig' missing

@4z3
4z3 force-pushed the writeNginxConfig branch from 499c755 to 59fac1a Compare March 23, 2019 10:16
@GrahamcOfBorg GrahamcOfBorg added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Mar 23, 2019
@Mic92

Mic92 commented Mar 24, 2019

Copy link
Copy Markdown
Member

@GrahamcOfBorg test nginx

@Mic92
Mic92 merged commit 6dd7483 into NixOS:master Apr 4, 2019
@Izorkin

Izorkin commented Apr 8, 2019

Copy link
Copy Markdown
Contributor

Error work this code

location /example { allow 192.168.0.0/16; deny all; }

result

  location /example {
    allow 192.168.0.0/16;
    deny all;
  }
  ;

character is added ;

@Mic92

Mic92 commented Apr 8, 2019

Copy link
Copy Markdown
Member

@Izorkin is it nginx or gixy that rejects the generated code?

@Izorkin

Izorkin commented Apr 8, 2019

Copy link
Copy Markdown
Contributor

Nginx error:

апр 08 14:55:45 web.elven.pw systemd[1]: Starting Nginx Web Server...
апр 08 14:55:45 web.elven.pw pnzhwc1q1is8vbdkg34ksicqq9jh5chc-unit-script-nginx-pre-start[2430]: nginx: [emerg] unexpected ";" in /nix/store/glvppaxv9gqg9vj179ph9rmj8yg41d72-nginx.conf:151

@Mic92

Mic92 commented Apr 8, 2019

Copy link
Copy Markdown
Member

Ok. So it is nginx itself.

@Izorkin Izorkin mentioned this pull request Apr 8, 2019
2 of 10 tasks
@aanderse aanderse mentioned this pull request Apr 10, 2019
7 of 9 tasks
@jb55

jb55 commented Apr 18, 2019

Copy link
Copy Markdown
Contributor

@Mic92

I guess we could test on master and see how many people would complain about it.

I can't upgrade to latest unstable because of this. I get no useful error messages:

builder for '/nix/store/d2hphy6y9hn4wsj513b70vw8w3hnbzvp-nginx.conf.drv' failed with exit code 1; last 10 log lines:
   }
  }
  
  ==================== Summary ===================
  Total issues:
      Unspecified: 0
      Low: 0
      Medium: 1
      High: 1
cannot build derivation '/nix/store/7r84gqm501i30qqfhzvdvlv1bzg6fsr7-unit-nginx.service.drv': 1 dependencies couldn't be built

@Izorkin

Izorkin commented Apr 19, 2019

Copy link
Copy Markdown
Contributor

@jb55 need full log. Example:

building all machine configurations...
unpacking 'https://github.com/nix-community/NUR/archive/master.tar.gz'...
these derivations will be built:
  /nix/store/vg217jgnrfmm2kk9nk10rjvbvnqhavk7-nginx.conf.drv
  /nix/store/4k3hn2nvgf21bx551iq0zzf3ib4vl9a5-unit-script-nginx-pre-start.drv
  /nix/store/csixd8qnkwy9llqard5gpilxd52234hb-unit-nginx.service.drv
  /nix/store/z2r5caxs8g0d98ibx8mf779rm5s7l1mm-system-units.drv
  /nix/store/gsjrv7d56f8ipf98bqv95ad5ln420lx0-etc.drv
  /nix/store/wgfp73fldfzcsp8n20ii2yc9mi8wwfmy-nixos-system-my_site-19.09pre176321.4c4ad72a43c.drv
  /nix/store/56wkdkff2w42zfx2063sg978idh0g2s8-nixops-machines.drv
building '/nix/store/vg217jgnrfmm2kk9nk10rjvbvnqhavk7-nginx.conf.drv'...

==================== Results ===================

>> Problem: [http_splitting] Possible HTTP-Splitting vulnerability.
Severity: HIGH
Description: Using variables that can contain "\n" or "\r" may lead to http injection.
Additional info: https://github.com/yandex/gixy/blob/master/docs/en/plugins/httpsplitting.md
Reason: At least variable "$uri" can contain "\n"
Pseudo config:

server {
        server_name my_site;

        location @backend_prober {
                proxy_pass http://nginx-unit-13/$uri?args;
        }
}

==================== Summary ===================
Total issues:
    Unspecified: 0
    Low: 0
    Medium: 0
    High: 1

builder for '/nix/store/vg217jgnrfmm2kk9nk10rjvbvnqhavk7-nginx.conf.drv' failed with exit code 1
cannot build derivation '/nix/store/csixd8qnkwy9llqard5gpilxd52234hb-unit-nginx.service.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/z2r5caxs8g0d98ibx8mf779rm5s7l1mm-system-units.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/gsjrv7d56f8ipf98bqv95ad5ln420lx0-etc.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/wgfp73fldfzcsp8n20ii2yc9mi8wwfmy-nixos-system-my_site-19.09pre176321.4c4ad72a43c.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/56wkdkff2w42zfx2063sg978idh0g2s8-nixops-machines.drv': 1 dependencies couldn't be built
error: build of '/nix/store/56wkdkff2w42zfx2063sg978idh0g2s8-nixops-machines.drv' failed
Traceback (most recent call last):
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/bin/..nixops-wrapped-wrapped", line 990, in <module>
    args.op()
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/bin/..nixops-wrapped-wrapped", line 411, in op_deploy
    max_concurrent_activate=args.max_concurrent_activate)
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/lib/python2.7/site-packages/nixops/deployment.py", line 1056, in deploy
    self.run_with_notify('deploy', lambda: self._deploy(**kwargs))
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/lib/python2.7/site-packages/nixops/deployment.py", line 1045, in run_with_notify
    f()
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/lib/python2.7/site-packages/nixops/deployment.py", line 1056, in <lambda>
    self.run_with_notify('deploy', lambda: self._deploy(**kwargs))
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/lib/python2.7/site-packages/nixops/deployment.py", line 996, in _deploy
    self.configs_path = self.build_configs(dry_run=dry_run, repair=repair, include=include, exclude=exclude)
  File "/nix/store/dmcxlqi7fwb4jws8c1qrzncfvqibvp0m-nixops-1.6.1/lib/python2.7/site-packages/nixops/deployment.py", line 664, in build_configs
    raise Exception("unable to build all machine configurations")
Exception: unable to build all machine configurations

@jb55

jb55 commented Apr 20, 2019 •

Copy link
Copy Markdown
Contributor

lzorkin: I need the full log too, I have no idea how to get that. I just reverted these commits for now.

@Mic92

Mic92 commented Apr 23, 2019

Copy link
Copy Markdown
Member

@jb55 use nix log /nix/store/d2hphy6y9hn4wsj513b70vw8w3hnbzvp-nginx.conf.drv to get the full log.

nixos-cuda-channel-updater Bot pushed a commit to nixos-cuda/nixpkgs that referenced this pull request Oct 29, 2026
This fixes `nginx` being unable to hash passwords, when built without `perl`,
as `libxcrypt` was added to `nginx` only as propagatedBuildInput from `perl`

RESOLVES NixOS#57979
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 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants