3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #56280 from Izorkin/nginx-config

nginx: formating the config file
This commit is contained in:
Elis Hirwing 2019-02-24 08:57:31 +01:00 committed by GitHub
commit d7ba376435
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,7 +44,25 @@ let
}
''));
configFile = pkgs.writeText "nginx.conf" ''
awkFormat = pkgs.writeText "awkFormat-nginx.awk" ''
awk -f
{sub(/^[ \t]+/,"");idx=0}
/\{/{ctx++;idx=1}
/\}/{ctx--}
{id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0}
'';
configFile = pkgs.stdenv.mkDerivation {
name = "nginx-config";
src = "";
phases = [ "installPhase" ];
installPhase = ''
mkdir $out
awk -f ${awkFormat} ${pre-configFile} | sed '/^\s*$/d' > $out/nginx.conf
'';
};
pre-configFile = pkgs.writeText "pre-nginx.conf" ''
user ${cfg.user} ${cfg.group};
error_log ${cfg.logError};
daemon off;
@ -638,10 +656,10 @@ in
preStart =
''
${cfg.preStart}
${cfg.package}/bin/nginx -c ${configFile} -p ${cfg.stateDir} -t
${cfg.package}/bin/nginx -c ${configFile}/nginx.conf -p ${cfg.stateDir} -t
'';
serviceConfig = {
ExecStart = "${cfg.package}/bin/nginx -c ${configFile} -p ${cfg.stateDir}";
ExecStart = "${cfg.package}/bin/nginx -c ${configFile}/nginx.conf -p ${cfg.stateDir}";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
Restart = "always";
RestartSec = "10s";