aboutsummaryrefslogtreecommitdiff
path: root/gnu/home/services/vcs.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/home/services/vcs.scm')
-rw-r--r--gnu/home/services/vcs.scm92
1 files changed, 92 insertions, 0 deletions
diff --git a/gnu/home/services/vcs.scm b/gnu/home/services/vcs.scm
new file mode 100644
index 0000000000..6ac7140d70
--- /dev/null
+++ b/gnu/home/services/vcs.scm
@@ -0,0 +1,92 @@
+;;; SPDX-License-Identifier: CC0-1.0
+;;;
+;;; Copyright © 2023 Wojtek Kosior <koszko@koszko.org>
+
+(define-module (gnu home services vcs)
+ #:use-module ((guix gexp) #:select
+ (gexp file-append mixed-text-file computed-file file-like?))
+ #:use-module ((gnu services) #:select (service-type service-extension))
+ #:use-module ((gnu services configuration) #:select
+ (define-configuration/no-serialization alist?))
+ #:use-module ((gnu home services shepherd) #:select
+ (home-shepherd-service-type shepherd-service))
+ #:use-module ((gnu packages version-control) #:select (git))
+ #:use-module ((gnu packages web) #:select (lighttpd))
+ #:export (home-localhost-repo-server-configuration
+ home-localhost-repo-server-configuration?
+ home-localhost-repo-server-configuration-lighttpd
+ home-localhost-repo-server-configuration-git
+ home-localhost-repo-server-configuration-port
+ home-localhost-repo-server-configuration-repos
+
+ home-localhost-repo-server-service-type))
+
+(define-configuration/no-serialization
+ home-localhost-repo-server-configuration
+ (lighttpd
+ (file-like lighttpd)
+ "The Lighttpd package to use.")
+ (git
+ (file-like git)
+ "The Git package to use.")
+ (port
+ (integer 8098)
+ "TCP port to serve repositories on.")
+ (repos
+ (alist '())
+ "Association list mapping repository names to their filesystm paths."))
+
+(define (repositories-root repos)
+ (computed-file "repos"
+ #~(begin
+ (mkdir #$output)
+ (chdir #$output)
+ (for-each (lambda (repo)
+ (symlink (cdr repo) (car repo)))
+ '#$repos))))
+
+(define (lighttpd-conf config)
+ (let* ((repos (home-localhost-repo-server-configuration-repos config))
+ (git (home-localhost-repo-server-configuration-git config))
+ (port (home-localhost-repo-server-configuration-port config))
+ (git-backend (file-append git "/libexec/git-core/git-http-backend")))
+ (mixed-text-file "lighttpd.conf"
+ "\
+server.document-root = \"/dev/null\"
+server.modules = ( \"mod_alias\", \"mod_cgi\", \"mod_setenv\")
+server.port = " (format #f "~a" port) "
+
+alias.url = ( \"/\" => \"" git-backend "/\" )
+cgi.assign = (\"\" => \"\")
+
+setenv.add-environment = (
+ \"GIT_PROJECT_ROOT\" => \"" (repositories-root repos) "\",
+ \"GIT_HTTP_EXPORT_ALL\" => \"\"
+)
+")))
+
+(define (home-localhost-repo-server-services config)
+ (let ((lighttpd (home-localhost-repo-server-configuration-lighttpd config))
+ (lighttpd-config-file (lighttpd-conf config)))
+ (list (shepherd-service
+ (provision '(localhost-repo-server))
+ (modules '((shepherd support))) ;for '%user-log-dir'
+ (start #~(make-forkexec-constructor
+ '(#$(file-append lighttpd "/sbin/lighttpd") "-D"
+ "-f" #$lighttpd-config-file)
+ #:log-file (string-append
+ %user-log-dir
+ "/localhost-repo-server.log")))
+ (stop #~(make-kill-destructor))
+ (documentation "Start local Lighttpd process that will serve
+cloneable git repositories on localhost.")))))
+
+(define home-localhost-repo-server-service-type
+ (service-type
+ (name 'home-localhost-repo-server)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-localhost-repo-server-services)))
+ (description "Serve local GIT repositories over HTTP so that they can be
+easily cloneable using http://localhost URLs.")
+ (default-value (home-localhost-repo-server-configuration))))