git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #59181 from Izorkin/nginx-format

nixos/nginx: fix error in writeNginxConfig

commit4d4f110ca541f10cd643c84b176a4757095c5bf0 authorJörg Thalheim <Mic92@users.noreply.github.com> dateWed 10 Apr 2019, 19:23 (8 years ago) parentd5cc30b496a73d
2 files changed+11−3
nixos/tests/nginx.nix+1 pkgs/build-support/writers/default.nix+10−3
nixos/tests/nginx.nix+1
@@ -28,6 +28,7 @@ import ./make-test.nix ({ pkgs, ...} : {
2828 services.nginx.virtualHosts."0.my.test" = {
2929 extraConfig = ''
3030 access_log syslog:server=unix:/dev/log,facility=user,tag=mytag,severity=info ceeformat;
31+ location /favicon.ico { allow all; access_log off; log_not_found off; }
3132 '';
3233 };
3334 };
pkgs/build-support/writers/default.nix+10−3
@@ -178,13 +178,20 @@ rec {
178178 writeJSBin = name:
179179 writeJS "/bin/${name}";
180180
181+ awkFormatNginx = builtins.toFile "awkFormat-nginx.awk" ''
182+ awk -f
183+ {sub(/^[ \t]+/,"");idx=0}
184+ /\{/{ctx++;idx=1}
185+ /\}/{ctx--}
186+ {id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0}
187+ '';
188+
181189 writeNginxConfig = name: text: pkgs.runCommand name {
182190 inherit text;
183191 passAsFile = [ "text" ];
184192 } /* sh */ ''
185− cp "$textPath" $out
186− ${pkgs.nginx-config-formatter}/bin/nginxfmt $out
187− ${pkgs.gnused}/bin/sed -i '/^$/d' $out
193+ # nginx-config-formatter has an error - https://github.com/1connect/nginx-config-formatter/issues/16
194+ ${pkgs.gawk}/bin/awk -f ${awkFormatNginx} "$textPath" | ${pkgs.gnused}/bin/sed '/^\s*$/d' > $out
188195 ${pkgs.gixy}/bin/gixy $out
189196 '';
190197