aboutsummaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2023-12-07 10:57:45 +0100
committerW. Kosior <koszko@koszko.org>2024-09-04 21:02:08 +0200
commit5b9b23d2cdc6b18569887174c060e79c16efc2e1 (patch)
treeee0c504e4119f01973bf2c75bbe5d65711feb417 /gnu
parentcaa5d13dc4c8c99c42ec0777febfd164a677e40b (diff)
downloadguix-5b9b23d2cdc6b18569887174c060e79c16efc2e1.tar.gz
guix-5b9b23d2cdc6b18569887174c060e79c16efc2e1.zip
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
Diffstat (limited to 'gnu')
-rw-r--r--gnu/home/services/vcs.scm92
-rw-r--r--gnu/local.mk1
2 files changed, 93 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))))
diff --git a/gnu/local.mk b/gnu/local.mk
index f651f00eb2..37e2d35029 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -117,6 +117,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 \