gnu: services: Fix mysql service activation.
[jackhill/guix/guix.git] / gnu / services / web.scm
index 35efddb..3ac7b7f 100644 (file)
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
-;;; Copyright © 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2016 ng0 <ng0@n0.is>
 ;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
 ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
@@ -9,6 +9,7 @@
 ;;; Copyright © 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
 ;;; Copyright © 2017, 2018, 2019 Christopher Baines <mail@cbaines.net>
 ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -42,6 +43,7 @@
   #:use-module (gnu packages gnupg)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages logging)
+  #:use-module (gnu packages mail)
   #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (guix modules)
@@ -95,6 +97,7 @@
             nginx-configuration-upstream-blocks
             nginx-configuration-server-names-hash-bucket-size
             nginx-configuration-server-names-hash-bucket-max-size
+            nginx-configuration-modules
             nginx-configuration-extra-content
             nginx-configuration-file
 
             patchwork-configuration-domain
 
             patchwork-virtualhost
-            patchwork-service-type))
+            patchwork-service-type
+
+            mumi-service-type))
 
 ;;; Commentary:
 ;;;
                            addresses-and-ports
                            contents)
                         `(,(string-append
-                            "<VirtualHost " addresses-and-ports ">\n")
+                            "\n<VirtualHost " addresses-and-ports ">\n")
                           ,@contents
                           "\n</VirtualHost>\n"))
                        ((? string? x)
                                  (default #f))
   (server-names-hash-bucket-max-size nginx-configuration-server-names-hash-bucket-max-size
                                      (default #f))
+  (modules nginx-configuration-modules (default '()))
   (extra-content nginx-configuration-extra-content
                  (default ""))
   (file          nginx-configuration-file         ;#f | string | file-like
@@ -542,6 +548,9 @@ of index files."
         ((? string? str) (list str " ")))
       names))
 
+(define (emit-load-module module)
+  (list "load_module " module ";\n"))
+
 (define emit-nginx-location-config
   (match-lambda
     (($ <nginx-location-configuration> uri body)
@@ -615,12 +624,14 @@ of index files."
                  server-blocks upstream-blocks
                  server-names-hash-bucket-size
                  server-names-hash-bucket-max-size
+                 modules
                  extra-content)
    (apply mixed-text-file "nginx.conf"
           (flatten
            "user nginx nginx;\n"
            "pid " run-directory "/pid;\n"
            "error_log " log-directory "/error.log info;\n"
+           (map emit-load-module modules)
            "http {\n"
            "    client_body_temp_path " run-directory "/client_body_temp;\n"
            "    proxy_temp_path " run-directory "/proxy_temp;\n"
@@ -682,7 +693,8 @@ of index files."
        (system* (string-append #$nginx "/sbin/nginx")
                 "-c" #$(or file
                            (default-nginx-config config))
-                  "-t"))))
+                "-p" #$run-directory
+                "-t"))))
 
 (define (nginx-shepherd-service config)
   (match-record config
@@ -733,8 +745,8 @@ of index files."
                             (server-blocks
                               (append (nginx-configuration-server-blocks config)
                               servers)))))
-                (default-value
-                  (nginx-configuration))))
+                (default-value (nginx-configuration))
+                (description "Run the nginx Web server.")))
 
 (define-record-type* <fcgiwrap-configuration> fcgiwrap-configuration
   make-fcgiwrap-configuration
@@ -1038,13 +1050,24 @@ a webserver.")
          (shell (file-append shadow "/sbin/nologin")))))
 
 (define %hpcguix-web-activation
-  #~(begin
-      (use-modules (guix build utils))
-      (let ((home-dir "/var/cache/guix/web")
-            (user (getpwnam "hpcguix-web")))
-        (mkdir-p home-dir)
-        (chown home-dir (passwd:uid user) (passwd:gid user))
-        (chmod home-dir #o755))))
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils)
+                     (ice-9 ftw))
+
+        (let ((home-dir "/var/cache/guix/web")
+              (user (getpwnam "hpcguix-web")))
+          (mkdir-p home-dir)
+          (chown home-dir (passwd:uid user) (passwd:gid user))
+          (chmod home-dir #o755)
+
+          ;; Remove stale 'packages.json.lock' file (and other lock files, if
+          ;; any) since that would prevent 'packages.json' from being updated.
+          (for-each (lambda (lock)
+                      (delete-file (string-append home-dir "/" lock)))
+                    (scandir home-dir
+                             (lambda (file)
+                               (string-suffix? ".lock" file))))))))
 
 (define %hpcguix-web-log-file
   "/var/log/hpcguix-web.log")
@@ -1424,7 +1447,7 @@ ADMINS = [
 
 DEBUG = " #$(if debug? "True" "False") "
 
-ENABLE_REST_API = " #$(if enable-xmlrpc? "True" "False") "
+ENABLE_REST_API = " #$(if enable-rest-api? "True" "False") "
 ENABLE_XMLRPC = " #$(if enable-xmlrpc? "True" "False") "
 
 FORCE_HTTPS_LINKS = " #$(if force-https-links? "True" "False") "
@@ -1632,3 +1655,55 @@ WSGIPassAuthorization On
                              patchwork-getmail-configs)))
    (description
     "Patchwork patch tracking system.")))
+
+\f
+;;;
+;;; Mumi.
+;;;
+
+(define %mumi-activation
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (mkdir-p "/var/mumi/mails")
+        (let* ((pw  (getpwnam "mumi"))
+               (uid (passwd:uid pw))
+               (gid (passwd:gid pw)))
+          (chown "/var/mumi" uid gid)
+          (chown "/var/mumi/mails" uid gid)))))
+
+(define %mumi-accounts
+  (list (user-group (name "mumi") (system? #t))
+        (user-account
+         (name "mumi")
+         (group "mumi")
+         (system? #t)
+         (comment "Mumi web server")
+         (home-directory "/var/empty")
+         (shell (file-append shadow "/sbin/nologin")))))
+
+(define (mumi-shepherd-services mumi)
+  (list (shepherd-service
+         (provision '(mumi))
+         (documentation "Mumi bug-tracking web interface.")
+         (requirement '(networking))
+         (start #~(make-forkexec-constructor
+                   '(#$(file-append mumi "/bin/mumi"))
+                   #:user "mumi" #:group "mumi"
+                   #:log-file "/var/log/mumi.log"))
+         (stop #~(make-kill-destructor)))))
+
+(define mumi-service-type
+  (service-type
+   (name 'mumi)
+   (extensions
+    (list (service-extension activation-service-type
+                             (const %mumi-activation))
+          (service-extension account-service-type
+                             (const %mumi-accounts))
+          (service-extension shepherd-root-service-type
+                             mumi-shepherd-services)))
+   (description
+    "Run Mumi, a Web interface to the Debbugs bug-tracking server.")
+   (default-value mumi)))