about summary refs log tree commit diff
path: root/guix/forge/klaus.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/forge/klaus.scm')
-rw-r--r--guix/forge/klaus.scm177
1 files changed, 90 insertions, 87 deletions
diff --git a/guix/forge/klaus.scm b/guix/forge/klaus.scm
index 6ffb23c..23de1db 100644
--- a/guix/forge/klaus.scm
+++ b/guix/forge/klaus.scm
@@ -1,5 +1,5 @@
 ;;; guix-forge --- Guix software forge meta-service
-;;; Copyright © 2023, 2024 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2023–2025 Arun Isaac <arunisaac@systemreboot.net>
 ;;; Copyright © 2024 jgart <jgart@dismail.de>
 ;;;
 ;;; This file is part of guix-forge.
@@ -22,103 +22,106 @@
   #:use-module (forge environment)
   #:use-module ((forge git) #:select (git-without-safe-directory-check))
   #:use-module (forge gunicorn)
+  #:use-module (forge nginx)
   #:use-module (forge socket)
-  #:use-module ((gnu packages check) #:select (python-nose python-pytest))
-  #:use-module ((gnu packages python-build)
-                #:select (python-setuptools python-wheel))
-  #:use-module ((gnu packages python-web)
-                #:select (python-flask python-werkzeug))
   #:use-module ((gnu packages python-xyz)
-                #:select (python-dulwich python-humanize python-pygments))
+                #:select (python-docutils python-markdown))
+  #:use-module ((gnu packages version-control)
+                #:select (python-klaus)
+                #:prefix guix:)
+  #:use-module (gnu services)
+  #:use-module ((gnu services web) #:select (nginx-server-configuration
+                                             nginx-location-configuration))
   #:use-module (gnu system file-systems)
-  #:use-module (guix build-system pyproject)
-  #:use-module (guix build-system python)
-  #:use-module (guix download)
-  #:use-module (guix gexp)
-  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix deprecation)
   #:use-module (guix packages)
-  #:export (klaus-gunicorn-app))
-
-(define-public python-httpauth
-  (package
-    (name "python-httpauth")
-    (version "0.4.1")
-    (source (origin
-              (method url-fetch)
-              (uri (pypi-uri "httpauth" version))
-              (sha256
-               (base32
-                "1m6rwvivg61l3h34hf6p6gkqmr69sb1c4k5ha379nxq0p8bfgahb"))))
-    (build-system pyproject-build-system)
-    (native-inputs
-     (list python-pytest
-           python-setuptools
-           python-wheel))
-    (home-page "https://github.com/jonashaag/httpauth")
-    (synopsis "WSGI HTTP Digest Authentication middleware")
-    (description "@code{python-httpauth} is WSGI middleware that secures some/all
-routes using HTTP Digest Authentication.")
-    (license license:bsd-2)))
+  #:use-module (guix records)
+  #:export (<klaus-configuration>
+            klaus-configuration
+            klaus-configuration?
+            klaus-configuration-python-klaus
+            klaus-configuration-server-name
+            klaus-configuration-socket
+            klaus-configuration-repository-directory
+            klaus-configuration-site-name
+            klaus-service-type
+            klaus-gunicorn-app))
 
 (define-public python-klaus
   (package
-    (name "python-klaus")
-    (version "3.0.1")
-    (source (origin
-              (method url-fetch)
-              (uri (pypi-uri "klaus" version))
-              (sha256
-               (base32
-                "1w6sl15llnkcg7kmnpn64awdiis061q2gijnhdx0ng7z4p1glapl"))))
-    (build-system pyproject-build-system)
-    (arguments
-     (list #:tests? #f  ; tests fail
-           #:phases
-           #~(modify-phases %standard-phases
-               (add-after 'unpack 'configure-git
-                 (lambda* (#:key inputs #:allow-other-keys)
-                   (for-each (lambda (file)
-                               (substitute* file
-                                 (("\"git\"")
-                                  (string-append "\"" (search-input-file inputs "/bin/git") "\""))))
-                             (list "klaus/ctagsutils.py"
-                                   "klaus/repo.py"
-                                   "klaus/utils.py"
-                                   "tests/test_contrib.py"
-                                   "tests/test_make_app.py")))))))
+    (inherit guix:python-klaus)
     (inputs
-     ;; We use klaus to serve shared repositories. But, git's safe
-     ;; directory check does not permit us to use shared
-     ;; repositories. Disable it. The more long term solution is to rewrite
-     ;; klaus to not use the git CLI at all. See
-     ;; https://github.com/jonashaag/klaus/issues/322
-     (list git-without-safe-directory-check))
-    (native-inputs
-     (list python-pytest
-           python-setuptools
-           python-wheel))
+     ;; We use klaus to serve shared repositories. But, git's safe directory
+     ;; check does not permit us to use shared repositories. Disable it. The
+     ;; more long term solution is to rewrite klaus to not use the git CLI at
+     ;; all. See https://github.com/jonashaag/klaus/issues/322
+     (modify-inputs (package-inputs guix:python-klaus)
+       (replace "git-minimal" git-without-safe-directory-check)))
     (propagated-inputs
-     (list python-dulwich python-flask python-httpauth
-           python-humanize python-pygments python-werkzeug))
-    (home-page "https://github.com/jonashaag/klaus")
-    (synopsis "Simple git web viewer")
-    (description "klaus is a simple, easy-to-set-up git web viewer. It features
+     (modify-inputs (package-propagated-inputs guix:python-klaus)
+       ;; Add optional dependencies for markup rendering.
+       (prepend python-docutils python-markdown)))))
+
+(define-record-type* <klaus-configuration>
+  klaus-configuration make-klaus-configuration
+  klaus-configuration?
+  (python-klaus klaus-configuration-python-klaus
+                (default python-klaus))
+  (server-name klaus-configuration-server-name)
+  (socket klaus-configuration-socket
+          (default (forge-unix-socket
+                    (path "/var/run/gunicorn/klaus/socket"))))
+  (repository-directory klaus-configuration-repository-directory
+                        (default "/srv/git"))
+  (site-name klaus-configuration-site-name
+             (default #f)))
+
+(define klaus-gunicorn-apps
+  (match-record-lambda <klaus-configuration>
+    (python-klaus socket repository-directory site-name)
+    (list (gunicorn-app
+           (name "klaus")
+           (package python-klaus)
+           (wsgi-app-module "klaus.contrib.wsgi_autoreload")
+           (sockets (list socket))
+           (environment-variables (cons (environment-variable
+                                         (name "KLAUS_REPOS_ROOT")
+                                         (value repository-directory))
+                                        (if site-name
+                                            (list (environment-variable
+                                                   (name "KLAUS_SITE_NAME")
+                                                   (value site-name)))
+                                            (list))))
+           (mappings (list (file-system-mapping
+                            (source repository-directory)
+                            (target source))))))))
+
+(define klaus-nginx-server-blocks
+  (match-record-lambda <klaus-configuration>
+    (server-name socket)
+    (list (nginx-server-configuration
+           (server-name (list server-name))
+           (locations
+            (list (nginx-location-configuration
+                   (uri "/")
+                   (body (list (socket->nginx-proxy-pass socket))))))))))
 
-@itemize
-@item Super easy to set up -- no configuration required
-@item Syntax highlighting
-@item Markdown + RestructuredText rendering support
-@item Pull + push support (Git Smart HTTP)
-@item Code navigation using Exuberant ctags
-@end itemize")
-    (license license:isc)))
+(define klaus-service-type
+  (service-type
+   (name 'klaus)
+   (description "Run klaus.")
+   (extensions (list (service-extension gunicorn-service-type
+                                        klaus-gunicorn-apps)
+                     (service-extension forge-nginx-service-type
+                                        klaus-nginx-server-blocks)))))
 
-(define* (klaus-gunicorn-app repository-directory
-                             #:key
-                             (klaus python-klaus)
-                             (sockets (list (forge-unix-socket
-                                             (path "/var/run/gunicorn/klaus/socket"))))
-                             site-name)
+(define-deprecated (klaus-gunicorn-app repository-directory
+                                       #:key
+                                       (klaus python-klaus)
+                                       (sockets (list (forge-unix-socket
+                                                       (path "/var/run/gunicorn/klaus/socket"))))
+                                       site-name)
+  klaus-service-type
   "Return a @code{<gunicorn-app>} object to deploy klaus.
 
 @var{repository-directory} is the path to the directory containing git