about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--arunisaac/meetfree.scm96
1 files changed, 94 insertions, 2 deletions
diff --git a/arunisaac/meetfree.scm b/arunisaac/meetfree.scm
index cb7504d..748164d 100644
--- a/arunisaac/meetfree.scm
+++ b/arunisaac/meetfree.scm
@@ -1,4 +1,9 @@
 (define-module (arunisaac meetfree)
+  #:use-module ((forge nginx) #:select (forge-nginx-service-type))
+  #:use-module ((gnu packages admin) #:select (shadow))
+  #:use-module ((gnu packages check) #:select (python-pytest))
+  #:use-module ((gnu packages nss) #:select (nss-certs))
+  #:use-module ((gnu packages python) #:select (python))
   #:use-module ((gnu packages python-build)
                 #:select (python-flit-core
                           python-hatch-vcs
@@ -12,6 +17,15 @@
   #:use-module ((gnu packages time)
                 #:select (python-dateutil python-tzdata))
   #:use-module ((gnu packages xml) #:select (python-lxml))
+  #:use-module (gnu services)
+  #:use-module ((gnu services web)
+                #:select (gunicorn-app
+                          gunicorn-service-type
+                          nginx-server-configuration
+                          nginx-location-configuration))
+  #:use-module (gnu system accounts)
+  #:use-module (gnu system file-systems)
+  #:use-module ((gnu system shadow) #:select (account-service-type))
   #:use-module (guix build-system pyproject)
   #:use-module (guix build-system python)
   #:use-module (guix download)
@@ -19,7 +33,15 @@
   #:use-module (guix git-download)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
-  #:use-module (guix utils))
+  #:use-module (guix profiles)
+  #:use-module (guix records)
+  #:use-module (guix utils)
+  #:export (meetfree-service-type
+
+            meetfree-configuration
+            meetfree-configuration-python-meetfree
+            meetfree-configuration-server-name
+            meetfree-configuration-allowed-groups))
 
 (define-public python-feedgen
   (package
@@ -126,7 +148,12 @@ does not require C extensions or system dependencies.")
              python-icalendar
              python-justhtml
              python-markdown
-             python-requests))
+             python-requests
+             ;; FIXME: nss-certs shouldn't be here. But, we add it
+             ;; because the gunicorn service is unable to pick up
+             ;; dependencies in environment variables. Fix that
+             ;; instead.
+             nss-certs))
       (native-inputs
        (list python-flit-core))
       (home-page "https://forge.systemreboot.net/meetfree")
@@ -136,3 +163,68 @@ and Atom feeds for meetup.com groups.  meetfree fetches data from
 meetup.com using its GraphQL API.  The GraphQL API does not require any
 authentication.")
       (license license:unlicense))))
+
+(define-record-type* <meetfree-configuration>
+  meetfree-configuration make-meetfree-configuration
+  meetfree-configuration?
+  (python-meetfree meetfree-configuration-python-meetfree
+                   (default python-meetfree))
+  (server-name meetfree-configuration-server-name)
+  (allowed-groups meetfree-configuration-allowed-groups
+                  (default #f))) ; list of group slugs or #f
+
+(define %meetfree-accounts
+  (list (user-account
+         (name "meetfree")
+         (group "meetfree")
+         (system? #t)
+         (comment "meetfree user")
+         (home-directory "/var/empty")
+         (shell (file-append shadow "/sbin/nologin")))
+        (user-group
+         (name "meetfree")
+         (system? #t))))
+
+(define meetfree-gunicorn-apps
+  (match-record-lambda <meetfree-configuration>
+    (python-meetfree server-name allowed-groups)
+    (list (gunicorn-app
+           (name "meetfree")
+           (package python-meetfree)
+           (wsgi-app-module "meetfree:app")
+           (user "meetfree")
+           (group "meetfree")
+           (environment-variables
+            `(("SSL_CERT_FILE"
+               . ,(file-append (profile
+                                 (content (packages->manifest
+                                           (list python python-meetfree))))
+                               "/etc/ssl/certs/ca-certificates.crt"))
+              ("MEETFREE_BASE_URL" . ,(string-append "https://" server-name))
+              ,@(if allowed-groups
+                    `(("MEETFREE_ALLOWED_GROUPS" . ,(string-join allowed-groups)))
+                    '())))
+           (extra-cli-arguments
+            (list "--capture-output"))))))
+
+(define meetfree-nginx-server-blocks
+  (match-record-lambda <meetfree-configuration>
+    (server-name)
+    (list (nginx-server-configuration
+           (server-name (list server-name))
+           (locations
+            (list (nginx-location-configuration
+                   (uri "/")
+                   (body
+                    (list "proxy_pass http://unix:/var/run/gunicorn/meetfree/socket:;")))))))))
+
+(define meetfree-service-type
+  (service-type
+   (name 'meetfree)
+   (description "Run meetfree.")
+   (extensions (list (service-extension account-service-type
+                                        (const %meetfree-accounts))
+                     (service-extension gunicorn-service-type
+                                        meetfree-gunicorn-apps)
+                     (service-extension forge-nginx-service-type
+                                        meetfree-nginx-server-blocks)))))