summaryrefslogtreecommitdiff
path: root/gnu/services/web.scm
diff options
context:
space:
mode:
authorArun Isaac <arunisaac@systemreboot.net>2025-09-19 16:11:04 +0100
committerArun Isaac <arunisaac@systemreboot.net>2025-09-24 12:21:30 +0100
commit464d738655590cb3df4ac6843dc2fd08dd3771f6 (patch)
tree0e195e1ce6a2e1240f0080d80b26a67ff7def013 /gnu/services/web.scm
parent734da975a2038cf47ca45d8864c45b8626773edb (diff)
services: nginx: Add stream configuration.
* gnu/services/web.scm (<nginx-stream-configuration>): New record type. (<nginx-configuration>)[stream]: New field. (emit-nginx-server-config): Add context argument. (default-nginx-config): Serialize stream. * doc/guix.texi (Web Services): Document it.
Diffstat (limited to 'gnu/services/web.scm')
-rw-r--r--gnu/services/web.scm46
1 files changed, 42 insertions, 4 deletions
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index d12257690ce..e3a5387ab72 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -68,6 +68,7 @@
#:use-module ((guix packages) #:select (package-version))
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (ice-9 match)
#:use-module (ice-9 format)
@@ -112,6 +113,7 @@
nginx-configuration-upstream-blocks
nginx-configuration-server-names-hash-bucket-size
nginx-configuration-server-names-hash-bucket-max-size
+ nginx-configuration-stream
nginx-configuration-modules
nginx-configuration-global-directives
nginx-configuration-extra-content
@@ -151,6 +153,11 @@
nginx-named-location-configuration-name
nginx-named-location-configuration-body
+ nginx-stream-configuration
+ nginx-stream-configuration-server-blocks
+ nginx-stream-configuraiton-upstream-blocks
+ nginx-stream-configuration-extra-content
+
nginx-service
nginx-service-type
@@ -587,6 +594,16 @@
(default #f))
(body nginx-named-location-configuration-body))
+(define-record-type* <nginx-stream-configuration>
+ nginx-stream-configuration make-nginx-stream-configuration
+ nginx-stream-configuration?
+ (upstream-blocks nginx-stream-configuration-upstream-blocks
+ (default '())) ;list of <nginx-upstream-configuration>
+ (server-blocks nginx-stream-configuration-server-blocks
+ (default '())) ;list of <nginx-server-configuration>
+ (extra-content nginx-stream-configuration-extra-content
+ (default '())))
+
(define-record-type* <nginx-configuration>
nginx-configuration make-nginx-configuration
nginx-configuration?
@@ -613,6 +630,8 @@
(default #f))
(server-names-hash-bucket-max-size nginx-configuration-server-names-hash-bucket-max-size
(default #f))
+ (stream nginx-configuration-stream
+ (default #f)) ;#f | <nginx-stream-configuration>
(modules nginx-configuration-modules (default '()))
(global-directives nginx-configuration-global-directives
(default '((events . ()))))
@@ -677,7 +696,7 @@ of index files."
(map (lambda (x) (list " " x "\n")) body)
" }\n"))))
-(define (emit-nginx-server-config server)
+(define* (emit-nginx-server-config server #:optional (context 'http))
(let ((listen (nginx-server-configuration-listen server))
(server-name (nginx-server-configuration-server-name server))
(ssl-certificate (nginx-server-configuration-ssl-certificate server))
@@ -702,16 +721,20 @@ of index files."
" server_name " (config-domain-strings server-name) ";\n"
(and/l ssl-certificate " ssl_certificate " <> ";\n")
(and/l ssl-certificate-key " ssl_certificate_key " <> ";\n")
- (if (not (equal? "" root))
+ (if (and (eq? context 'http)
+ (not (equal? "" root)))
(list " root " root ";\n")
"")
- (if (not (null? index))
+ (if (and (eq? context 'http)
+ (not (null? index)))
(list " index " (config-index-strings index) ";\n")
"")
(if (not (nil? try-files))
(and/l (config-index-strings try-files) " try_files " <> ";\n")
"")
- " server_tokens " (if server-tokens? "on" "off") ";\n"
+ (if (eq? context 'http)
+ (list " server_tokens " (if server-tokens? "on" "off") ";\n")
+ "")
"\n"
(map emit-nginx-location-config locations)
"\n"
@@ -761,6 +784,7 @@ of index files."
server-blocks upstream-blocks
server-names-hash-bucket-size
server-names-hash-bucket-max-size
+ stream
modules
global-directives
lua-package-path
@@ -773,6 +797,20 @@ of index files."
"error_log " (nginx-error-log-file config) " " (symbol->string log-level) ";\n"
(map emit-load-module modules)
(map emit-global-directive global-directives)
+ (match stream
+ (#f "")
+ (_
+ (list "stream {\n"
+ (map emit-nginx-upstream-config
+ (nginx-stream-configuration-upstream-blocks stream))
+ (map (cut emit-nginx-server-config <> 'stream)
+ (nginx-stream-configuration-server-blocks stream))
+ (let ((extra-content (nginx-stream-configuration-extra-content stream)))
+ (if (list? extra-content)
+ (map (cut list " " <> "\n")
+ extra-content)
+ extra-content))
+ "}\n")))
"http {\n"
" client_body_temp_path " run-directory "/client_body_temp;\n"
" proxy_temp_path " run-directory "/proxy_temp;\n"