about summary refs log tree commit diff
path: root/guix/forge/nginx.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/forge/nginx.scm')
-rw-r--r--guix/forge/nginx.scm25
1 files changed, 21 insertions, 4 deletions
diff --git a/guix/forge/nginx.scm b/guix/forge/nginx.scm
index a1f99c2..2e22bd8 100644
--- a/guix/forge/nginx.scm
+++ b/guix/forge/nginx.scm
@@ -1,5 +1,5 @@
 ;;; guix-forge --- Guix software forge meta-service
-;;; Copyright © 2023 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2023, 2025 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of guix-forge.
 ;;;
@@ -36,6 +36,7 @@
             forge-nginx-configuration-acme-challenge-directory
             forge-nginx-configuration-server-blocks
             nginx-socket->string
+            socket->nginx-proxy-pass
             forge-nginx-service-type))
 
 (define-record-type* <forge-nginx-configuration>
@@ -66,12 +67,28 @@ configuration (for example, in the @code{listen} and
     (($ <forge-ip-socket> (or "0.0.0.0" "::") port)
      (number->string port))
     (($ <forge-ip-socket> (? ipv4-address? ip) port)
-     (string-append ip ":" port))
+     (string-append ip ":" (number->string port)))
     (($ <forge-ip-socket> (? ipv6-address? ip) port)
-     (string-append "[" ip "]" ":" port))
+     (string-append "[" ip "]" ":" (number->string port)))
     (($ <forge-unix-socket> path)
      (string-append "unix:" path))))
 
+(define (socket->nginx-proxy-pass socket)
+  "Serialize @var{socket}, a forge socket, to an nginx @code{proxy_pass}
+directive."
+  (string-append
+   "proxy_pass "
+   (match socket
+     (($ <forge-host-socket> hostname port)
+      (string-append "http://" hostname ":" (number->string port)))
+     (($ <forge-ip-socket> (? ipv4-address? ip) port)
+      (string-append "http://" ip ":" (number->string port)))
+     (($ <forge-ip-socket> (? ipv6-address? ip) port)
+      (string-append "http://[" ip "]:" (number->string port)))
+     (($ <forge-unix-socket> path)
+      (string-append "http://unix:" path ":")))
+   ";"))
+
 (define (forge-nginx-server-blocks config)
   "Return list of nginx server blocks to provision for forge-web service
 specified by @var{config}."
@@ -82,7 +99,7 @@ specified by @var{config}."
            (locations
             (list (nginx-location-configuration
                    (uri "/.well-known/acme-challenge/")
-                   ;; Without a trailing slash, a alias of /var/foo
+                   ;; Without a trailing slash, an alias of /var/foo
                    ;; would lookup /bar at /var/foobar, not
                    ;; /var/foo/bar. So, a trailing slash is
                    ;; significant. Append it if not already