@@ -127,110 +127,109 @@ in
127127 imports = [
128128 ( nglib . mkOptionsEqual
129129 [
130- "nixos"
131130 "services"
132131 "nginx"
133132 "enable"
134133 ]
135134 [
135+ "nixos"
136136 "services"
137137 "nginx"
138138 "enable"
139139 ]
140+ lib . id
140141 )
141142 ] ;
142143
143144 config = {
144- services . nginx = lib . mkIf config . services . nginx . enable (
145- nglib . errorExperimentalNixOS config {
146- envsubst = true ;
147- configuration = lib . singleton {
148- daemon = "off" ;
149- worker_processes = 8 ;
150- user = "nginx" ;
151-
152- events . "" = {
153- use = "epoll" ;
154- worker_connections = 512 ;
155- } ;
156-
157- error_log = [
158- "/dev/stderr"
159- "warn"
160- ] ;
161-
162- pid = "/nginx.pid" ;
163-
164- http . "" =
165- [
166- {
167- server_tokens = "off" ;
168- include = [ [ "${ pkgs . nginx } /conf/mime.types" ] ] ;
169- charset = "utf-8" ;
170- access_log = [
171- "/dev/stdout"
172- "combined"
173- ] ;
145+ services . nginx = lib . mkIf config . services . nginx . enable ( {
146+ envsubst = true ;
147+ configuration = lib . singleton {
148+ daemon = "off" ;
149+ worker_processes = 8 ;
150+ user = "nginx" ;
151+
152+ events . "" = {
153+ use = "epoll" ;
154+ worker_connections = 512 ;
155+ } ;
174156
175- # $connection_upgrade is used for websocket proxying
176- map . "$$http_upgrade $$connection_upgrade" = {
177- default = "upgrade" ;
178- "''" = "close" ;
179- } ;
180- }
181- ]
182- ++ ( lib . optionals cfg . recommendedProxySettings [
183- {
184- proxy_redirect = "off" ;
185- proxy_connect_timeout = cfg . proxyTimeout ;
186- proxy_send_timeout = cfg . proxyTimeout ;
187- proxy_read_timeout = cfg . proxyTimeout ;
188- proxy_http_version = "1.1" ;
189- # don't let clients close the keep-alive connection to upstream. See the nginx blog for details:
190- # https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#no-keepalives
191- proxy_set_header = [
192- "Connection"
193- "''"
157+ error_log = [
158+ "/dev/stderr"
159+ "warn"
160+ ] ;
161+
162+ pid = "/nginx.pid" ;
163+
164+ http . "" =
165+ [
166+ {
167+ server_tokens = "off" ;
168+ include = [ [ "${ pkgs . nginx } /conf/mime.types" ] ] ;
169+ charset = "utf-8" ;
170+ access_log = [
171+ "/dev/stdout"
172+ "combined"
173+ ] ;
174+
175+ # $connection_upgrade is used for websocket proxying
176+ map . "$$http_upgrade $$connection_upgrade" = {
177+ default = "upgrade" ;
178+ "''" = "close" ;
179+ } ;
180+ }
181+ ]
182+ ++ ( lib . optionals cfg . recommendedProxySettings [
183+ {
184+ proxy_redirect = "off" ;
185+ proxy_connect_timeout = cfg . proxyTimeout ;
186+ proxy_send_timeout = cfg . proxyTimeout ;
187+ proxy_read_timeout = cfg . proxyTimeout ;
188+ proxy_http_version = "1.1" ;
189+ # don't let clients close the keep-alive connection to upstream. See the nginx blog for details:
190+ # https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#no-keepalives
191+ proxy_set_header = [
192+ "Connection"
193+ "''"
194+ ] ;
195+ }
196+ recommendedProxyConfig
197+ ] )
198+ ++ ( lib . flip lib . mapAttrsToList cfg . virtualHosts (
199+ server_name : server : {
200+ server . "" = {
201+ listen = [
202+ "80"
203+ "http2"
194204 ] ;
195- }
196- recommendedProxyConfig
197- ] )
198- ++ ( lib . flip lib . mapAttrsToList cfg . virtualHosts (
199- server_name : server : {
200- server . "" = {
201- listen = [
202- "80"
203- "http2"
204- ] ;
205- inherit server_name ;
206-
207- location = lib . flip lib . mapAttrs server . locations (
208- location : settings : [
209- ( lib . optionalAttrs (
210- settings . proxyPass != null && cfg . recommendedProxySettings
211- ) recommendedProxyConfig )
212- ( lib . optionalAttrs settings . proxyWebsockets {
213- proxy_http_version = "1.1" ;
214- proxy_set_header = [
215- [
216- "Upgrade"
217- "$$http_upgrade"
218- ]
219- [
220- "Connection"
221- "$$connection_upgrade"
222- ]
223- ] ;
224- } )
225- settings . extraConfig
226- ( lib . optionalAttrs ( settings . proxyPass != null ) { proxy_pass = settings . proxyPass ; } )
227- ]
228- ) ;
229- } ;
230- }
231- ) ) ;
232- } ;
233- }
234- ) ;
205+ inherit server_name ;
206+
207+ location = lib . flip lib . mapAttrs server . locations (
208+ location : settings : [
209+ ( lib . optionalAttrs (
210+ settings . proxyPass != null && cfg . recommendedProxySettings
211+ ) recommendedProxyConfig )
212+ ( lib . optionalAttrs settings . proxyWebsockets {
213+ proxy_http_version = "1.1" ;
214+ proxy_set_header = [
215+ [
216+ "Upgrade"
217+ "$$http_upgrade"
218+ ]
219+ [
220+ "Connection"
221+ "$$connection_upgrade"
222+ ]
223+ ] ;
224+ } )
225+ settings . extraConfig
226+ ( lib . optionalAttrs ( settings . proxyPass != null ) { proxy_pass = settings . proxyPass ; } )
227+ ]
228+ ) ;
229+ } ;
230+ }
231+ ) ) ;
232+ } ;
233+ } ) ;
235234 } ;
236235}
0 commit comments