summary refs log tree commit diff
path: root/gnu/services/web.scm
diff options
context:
space:
mode:
authorAlexandru-Sergiu Marton <brown121407@posteo.ro>2020-10-25 02:19:39 +0300
committerLudovic Courtès <ludo@gnu.org>2020-10-27 18:00:28 +0100
commit2ade5bdeb8978d252f298df7150b8d1a359e618d (patch)
tree8ea7e0794202e04f3bf710960acaa91067139719 /gnu/services/web.scm
parent1a7bfbb67da5c871816ba33fdcac900751dac3d4 (diff)
downloadguix-2ade5bdeb8978d252f298df7150b8d1a359e618d.tar.gz
services: Add gmnisrv web service.
* gnu/services/web.scm (<gmnisrv-configuration>): New record type.
(%default-gmnisrv-config-file): New variable.
(%gmnisrv-accounts, %gmnisrv-activation): New variables.
(gmnisrv-shepherd-service): New procedure.
(gmnisrv-service-type): New variable.
* doc/guix.texi (Web Services): Document it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/services/web.scm')
-rw-r--r--gnu/services/web.scm73
1 files changed, 73 insertions, 0 deletions
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 2384ec691c..7e17dac6e2 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -14,6 +14,7 @@
 ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
 ;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
+;;; Copyright © 2020 Alexandru-Sergiu Marton <brown121407@posteo.ro>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1798,3 +1799,75 @@ WSGIPassAuthorization On
     "Run Mumi, a Web interface to the Debbugs bug-tracking server.")
    (default-value
      (mumi-configuration))))
+
+(define %default-gmnisrv-config-file
+  (plain-file "gmnisrv.ini" "
+listen=0.0.0.0:1965 [::]:1965
+
+[:tls]
+store=/var/lib/gemini/certs
+
+organization=gmnisrv on Guix user
+
+[localhost]
+root=/srv/gemini
+"))
+
+(define-record-type* <gmnisrv-configuration>
+  gmnisrv-configuration make-gmnisrv-configuration
+  gmnisrv-configuration?
+  (package     gmnisrv-configuration-package
+               (default gmnisrv))
+  (config-file gmnisrv-configuration-config-file
+               (default %default-gmnisrv-config-file)))
+
+(define gmnisrv-shepherd-service
+  (match-lambda
+    (($ <gmnisrv-configuration> package config-file)
+     (list (shepherd-service
+            (provision '(gmnisrv))
+            (requirement '(networking))
+            (documentation "Run the gmnisrv Gemini server.")
+            (start (let ((gmnisrv (file-append package "/bin/gmnisrv")))
+                     #~(make-forkexec-constructor
+                        (list #$gmnisrv "-C" #$config-file)
+                        #:user "gmnisrv" #:group "gmnisrv"
+                        #:log-file "/var/log/gmnisrv.log")))
+            (stop #~(make-kill-destructor)))))))
+
+(define %gmnisrv-accounts
+  (list (user-group (name "gmnisrv") (system? #t))
+        (user-account
+         (name "gmnisrv")
+         (group "gmnisrv")
+         (system? #t)
+         (comment "gmnisrv Gemini server")
+         (home-directory "/var/empty")
+         (shell (file-append shadow "/sbin/nologin")))))
+
+(define %gmnisrv-activation
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (mkdir-p "/var/lib/gemini/certs")
+        (let* ((pw  (getpwnam "gmnisrv"))
+               (uid (passwd:uid pw))
+               (gid (passwd:gid pw)))
+          (chown "/var/lib/gemini" uid gid)
+          (chown "/var/lib/gemini/certs" uid gid)))))
+
+(define gmnisrv-service-type
+  (service-type
+   (name 'guix)
+   (extensions
+    (list (service-extension activation-service-type
+                             (const %gmnisrv-activation))
+          (service-extension account-service-type
+                             (const %gmnisrv-accounts))
+          (service-extension shepherd-root-service-type
+                             gmnisrv-shepherd-service)))
+   (description
+    "Run the gmnisrv Gemini server.")
+   (default-value
+     (gmnisrv-configuration))))