lol

nginx: Verify that configuration is syntactically correct (#17208)

authored by

Robin Lambertz and committed by
Rok Garbas
103805de 48829c78

+12 -3
+12 -3
nixos/modules/services/web-servers/nginx/default.nix
··· 5 5 let 6 6 cfg = config.services.nginx; 7 7 nginx = cfg.package; 8 - configFile = pkgs.writeText "nginx.conf" '' 8 + configFileText = '' 9 9 user ${cfg.user} ${cfg.group}; 10 10 daemon off; 11 11 ··· 19 19 ''} 20 20 ${cfg.appendConfig} 21 21 ''; 22 + configFile = pkgs.runCommand "nginx.conf" { 23 + text = configFileText; 24 + passAsFile = ["text"]; 25 + preferLocalBuild = true; 26 + allowSubstitutes = false; 27 + } '' 28 + mkdir -p "$(dirname "$out")" 29 + mv "$textPath" "$out" 30 + (${nginx}/bin/nginx -t -c "$out" -p ${cfg.stateDir} || true) 2>&1 | grep -q 'syntax is ok' 31 + ''; 32 + 22 33 in 23 34 24 35 { ··· 91 102 }; 92 103 93 104 config = mkIf cfg.enable { 94 - # TODO: test user supplied config file pases syntax test 95 - 96 105 systemd.services.nginx = { 97 106 description = "Nginx Web Server"; 98 107 after = [ "network.target" ];