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

nginx NixOS module: generated configuration has many superfluous newlines #34377

Closed
coretemp opened this issue Jan 29, 2018 · 6 comments
Closed

Comments

@coretemp
Copy link
Contributor

Issue description

A generated nginx configuration file contains many newlines, which make the file much longer than needed (and it makes it harder to read).

Steps to reproduce

service.nginx.enable = true;

Technical details

  • system: "x86_64-linux"
  • host os: Linux 4.13.4, NixOS, 17.09.git.39cd40f (Hummingbird)
  • multi-user?: yes
  • sandbox: no
  • version: nix-env (Nix) 1.11.15
  • channels(root): "nixos-17.09.2182.7f6f0c49f0"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs
@Baughn
Copy link
Contributor

Baughn commented Jan 29, 2018

I had a nginx configuration file cleaner submitted a while back, but it got backed out for not working quite right. (Around Unicode, iirc.)

Perhaps it's time to take another look at that.

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Jan 29, 2018

Nginx is particularly bad because the expression is quite complicated but this applies to practically every configuration files NixOS generates. Here's some

xorg.conf


Section "Device"
  Identifier "Device-amdgpu[0]"
  Driver "amdgpu"
  Option "AccelMethod" "glamor"
  Option "DRI"      "3"
Option "TearFree" "true"

  
EndSection

Section "Screen"
  Identifier "Screen-amdgpu[0]"
  Device "Device-amdgpu[0]"
  

  

  

  

EndSection




torrc.conf

GeoIPv6File /nix/store/d12qh0yn9q3qa7xnbsi0bwva1dcvmmmm-tor-0.3.2.9-geoip/share/tor/geoip6



SOCKSPort 127.0.0.1:9050 IsolateDestAddr
SOCKSPort 127.0.0.1:9063





# Performance
AvoidDiskWrites      1
HardwareAccel        1

homeserver.yaml




 no_tls: false




 pid_file: "/var/run/matrix-synapse.pid"
 web_client: true

 listeners: [{port: 8448, bind_address: "", type: http,

Personally I don't care much about the generated files: I'm not going to read it after I tested the module but It would be a nice improvement. If you try to generate clean files the code usually turns into a mess. A possible solution could be to remove empty lines. Not sure about the broken indentation.

@lheckemann
Copy link
Member

Workaround: view the file through sed 's/^\s*$//' | uniq

@bobvanderlinden
Copy link
Member

bobvanderlinden commented Nov 16, 2018

Allternatively we could use https://github.com/vasilevich/nginxbeautifier if needing minimal nodejs at build-time isn't a problem.

EDIT: Also found https://github.com/1connect/nginx-config-formatter, which is written in python.

@infinisil
Copy link
Member

For my #45470 I implemented a config variable having some Nix type (some combination of attrsets and lists), which then gets turned into the config string. Due to it being generated like this, the formatting of the config file has improved a lot: old new

The same could be done for postgresql.

@globin
Copy link
Member

globin commented Aug 19, 2019

Is formatted now.

@globin globin closed this as completed Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants