From 77af8aba7c289435cbdee8998f71bcd92cd0fb2d Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 7 Dec 2023 10:57:45 +0100 Subject: home: services: Add localhost-repo-server. * gnu/home/services/vcs.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Record 'home/services/vcs.scm'. Change-Id: I37d3c1dacc26eb31b9b7ec434ed760c7cf84cc32 --- gnu/home/services/vcs.scm | 92 +++++++++++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 2 files changed, 93 insertions(+) create mode 100644 gnu/home/services/vcs.scm (limited to 'gnu') 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 + +(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)))) diff --git a/gnu/local.mk b/gnu/local.mk index bc172d4257..aeb5a70517 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -114,6 +114,7 @@ GNU_SYSTEM_MODULES = \ %D%/home/services/syncthing.scm \ %D%/home/services/mcron.scm \ %D%/home/services/utils.scm \ + %D%/home/services/vcs.scm \ %D%/home/services/xdg.scm \ %D%/image.scm \ %D%/packages.scm \ -- cgit v1.2.3