services.nginx: allow startup with ipv6 disabled (#21360)

currently services.nginx does not start up if `networking.enableIPv6 = false`
the commit changes the nginx behavior to handle this case accordingly.
The commit resolves #21308

authored by Felix Richter and committed by Robin Gloster d8478c79 9f6bd823

+7 -4
+7 -4
nixos/modules/services/web-servers/nginx/default.nix
··· 10 10 sslCertificateKey = "/var/lib/acme/${vhostName}/key.pem"; 11 11 }) 12 12 ) cfg.virtualHosts; 13 + enableIPv6 = config.networking.enableIPv6; 13 14 14 15 configFile = pkgs.writeText "nginx.conf" '' 15 16 user ${cfg.user} ${cfg.group}; ··· 84 85 ${optionalString cfg.statusPage '' 85 86 server { 86 87 listen 80; 87 - listen [::]:80; 88 + ${optionalString enableIPv6 "listen [::]:80;" } 88 89 89 90 server_name localhost; 90 91 ··· 92 93 stub_status on; 93 94 access_log off; 94 95 allow 127.0.0.1; 95 - allow ::1; 96 + ${optionalString enableIPv6 "allow ::1;"} 96 97 deny all; 97 98 } 98 99 } ··· 133 134 ${optionalString vhost.forceSSL '' 134 135 server { 135 136 listen 80 ${optionalString vhost.default "default"}; 136 - listen [::]:80 ${optionalString vhost.default "default"}; 137 + ${optionalString enableIPv6 138 + ''listen [::]:80 ${optionalString vhost.default "default"};'' 139 + } 137 140 138 141 server_name ${serverName} ${concatStringsSep " " vhost.serverAliases}; 139 142 ${acmeLocation} ··· 145 148 146 149 server { 147 150 listen ${listenString}; 148 - listen [::]:${listenString}; 151 + ${optionalString enableIPv6 "listen [::]:${listenString};"} 149 152 150 153 server_name ${serverName} ${concatStringsSep " " vhost.serverAliases}; 151 154 ${acmeLocation}