summaryrefslogtreecommitdiff
path: root/deployment/services/web.scm
diff options
context:
space:
mode:
Diffstat (limited to 'deployment/services/web.scm')
-rw-r--r--deployment/services/web.scm182
1 files changed, 182 insertions, 0 deletions
diff --git a/deployment/services/web.scm b/deployment/services/web.scm
new file mode 100644
index 0000000..b076056
--- /dev/null
+++ b/deployment/services/web.scm
@@ -0,0 +1,182 @@
+;;; SPDX-License-Identifier: GPL-3.0-or-later
+;;; SPDX-FileCopyrightText: 2026 Marek Paśnikowski <marek@marekpasnikowski.pl>
+
+;;; COPYRIGHT NOTICE
+;;;
+;;; Copyright 2026, Marek Paśnikowski <marek@marekpasnikowski.pl>
+
+;;; LICENSE NOTICE
+;;;
+;;; This library is free software: you can redistribute it and/or modify it under the terms of
+;;; the GNU General Public License as published by the Free Software Foundation,
+;;; either version 3 of the License, or (at your option) any later version.
+;;;
+;;; This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+;;; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+;;; See the GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License along with this library.
+;;; If not, see <https://www.gnu.org/licenses/>.
+
+(define-module (deployment services web)
+ #:export (fcgiwrap-service-aisaka
+ nginx-service-aisaka
+ nginx-location-well-known
+ nginx-service-type*)
+ #:use-module (gnu services)
+ #:use-module (gnu services web)
+ #:use-module (guix gexp)
+ #:use-module ((gnu packages matrix)
+ #:prefix gnu:packages:matrix:)
+ #:use-module ((gnu packages web)
+ #:prefix gnu:packages:web:)
+ #:use-module ((gnu system shadow)
+ #:prefix gnu:system:shadow:)
+ #:use-module ((sovereign system accounts)
+ #:prefix sovereign:system:accounts:))
+
+(define fcgiwrap-configuration-aisaka
+ (fcgiwrap-configuration
+ (package gnu:packages:web:fcgiwrap)
+ (socket "tcp:127.0.0.1:9000")
+ (user "git")
+ (group "git")))
+
+(define fcgiwrap-service-aisaka
+ (service
+ fcgiwrap-service-type
+ fcgiwrap-configuration-aisaka))
+
+(define nginx-accounts
+ (let
+ ((accounts- (list sovereign:system:accounts:nginx-group
+ sovereign:system:accounts:nginx-account)))
+ (const accounts-)))
+
+(define nginx-extension-of-account
+ (service-extension gnu:system:shadow:account-service-type
+ nginx-accounts))
+
+(define (extend-account extension)
+ (let*
+ ((extension-target- (service-extension-target extension))
+ (account-service-type?- (eq? extension-target-
+ gnu:system:shadow:account-service-type)))
+ (if account-service-type?-
+ nginx-extension-of-account
+ extension)))
+
+(define nginx-service-type*
+ (let
+ ((nginx-extensions- (service-type-extensions nginx-service-type)))
+ (service-type
+ (inherit nginx-service-type)
+ (extensions (map extend-account
+ nginx-extensions-)))))
+
+(define nginx-location-proxy-guix
+ (nginx-location-configuration
+ (body (list "proxy_pass http://localhost:8080/ ;"
+ "proxy_set_header X-Script-Name \"\" ;"
+ "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;"
+ "proxy_set_header Host $http_host ;"
+ "proxy_pass_header Authorization ;"))
+ (uri "/")))
+
+(define nginx-location-proxy-matrix
+ (nginx-location-configuration
+ (body (list "proxy_pass http://localhost:8008 ;"
+ "proxy_set_header X-Forwarded-For $remote_addr ;"
+ "proxy_set_header X-Forwarded-Proto $scheme ;"
+ "proxy_set_header Host $host:$server_port ;"
+ "client_max_body_size 1024M ;"))
+ (uri "~ ^(/_matrix|/_synapse/client)")))
+
+(define nginx-location-proxy-radicale
+ (nginx-location-configuration
+ (body (list "proxy_pass http://localhost:5232/ ;"
+ "proxy_set_header X-Script-Name \"\" ;"
+ "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;"
+ "proxy_set_header Host $http_host ;"
+ "proxy_pass_header Authorization ;"))
+ (uri "/")))
+
+(define nginx-location-proxy-auth
+ (nginx-location-configuration
+ (body (list "proxy_set_header Host $host;"
+ "proxy_set_header X-Real-IP $remote_addr;"
+ "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;"
+ "proxy_set_header X-Forwarded-Proto $scheme;"
+ "if ($ssl_client_verify != SUCCESS) {return 403;}"))
+ (uri "/")))
+
+(define nginx-location-well-known
+ (nginx-location-configuration
+ (body (list "root /srv/www/marek/marekpasnikowski.pl ;"))
+ (uri "/.well-known")))
+
+(define nginx-location-well-known-matrix-client
+ (nginx-location-configuration
+ (body (list "return 200 '{\"m.homeserver\": {\"base_url\": \"https://matrix.marekpasnikowski.pl\"}}' ;"
+ "default_type application/json ;"
+ "add_header Access-Control-Allow-Origin * ;"))
+ (uri "/.well-known/matrix/client")))
+
+(define nginx-server-guix
+ (nginx-server-configuration
+ (locations (list nginx-location-proxy-guix))
+ (listen (list "192.168.10.2:443 ssl"))
+ (server-name (list "guix.marekpasnikowski.pl"))
+ (ssl-certificate "/etc/letsencrypt/live/marekpasnikowski.pl/fullchain.pem")
+ (ssl-certificate-key "/etc/letsencrypt/live/marekpasnikowski.pl/privkey.pem")))
+
+(define nginx-server-matrix
+ (nginx-server-configuration
+ (locations (list nginx-location-proxy-matrix))
+ (listen (list "192.168.10.2:443 ssl"
+ "192.168.10.2:8448 ssl default_server"))
+ (root (file-append gnu:packages:matrix:synapse
+ "/lib/python3.11/site-packages/synapse/static"))
+ (server-name (list "matrix.marekpasnikowski.pl"))
+ (ssl-certificate "/etc/letsencrypt/live/marekpasnikowski.pl/fullchain.pem")
+ (ssl-certificate-key "/etc/letsencrypt/live/marekpasnikowski.pl/privkey.pem")
+ (raw-content (list "proxy_http_version 1.1 ;"))))
+
+(define nginx-server-portal
+ (nginx-server-configuration
+ (locations (list nginx-location-well-known
+ nginx-location-well-known-matrix-client))
+ (listen (list "192.168.10.2:443 ssl"))
+ (root "/srv/www/marek/marekpasnikowski.pl")
+ (server-name (list 'default
+ "marekpasnikowski.pl"))
+ (ssl-certificate "/etc/letsencrypt/live/marekpasnikowski.pl/fullchain.pem")
+ (ssl-certificate-key "/etc/letsencrypt/live/marekpasnikowski.pl/privkey.pem")))
+
+(define nginx-server-radicale
+ (nginx-server-configuration
+ (locations (list nginx-location-proxy-radicale
+ nginx-location-well-known))
+ (listen (list "192.168.10.2:443 ssl"))
+ (server-name (list "radicale.marekpasnikowski.pl"))))
+
+(define nginx-server-www
+ (nginx-server-configuration
+ (listen (list "192.168.10.2:443 ssl"))
+ (root "/srv/www/marek/marekpasnikowski.pl")
+ (server-name (list "www.marekpasnikowski.pl"))))
+
+(define nginx-configuration*
+ (nginx-configuration
+ (shepherd-requirement (list 'networking))
+ (server-blocks (list nginx-server-portal
+ nginx-server-www
+ nginx-server-guix
+ nginx-server-matrix
+ nginx-server-radicale))))
+
+(define nginx-service-aisaka
+ (service nginx-service-type*
+ nginx-configuration*))
+
+;;; EOF