;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2020, 2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . ;;; ;;; Some of the help text was taken from the default dovecot.conf files. (define-module (services gitile) #:use-module (gnu services) #:use-module (gnu services base) #:use-module (gnu services configuration) #:use-module (gnu services shepherd) #:use-module (gnu services web) #:use-module (gnu system pam) #:use-module (gnu system shadow) #:use-module (gnu packages admin) #:use-module (packages gitile) #:use-module (guix gexp) #:use-module (guix records) #:use-module (ice-9 match) #:export (gitile-service-type gitile-configuration)) (define-record-type* gitile-configuration make-gitile-configuration gitile-configuration? (package gitile-configuration-package (default gitile)) (host gitile-configuration-host (default "localhost")) (port gitile-configuration-port (default 8080)) (database gitile-configuration-database (default "/var/lib/gitile/gitile-db.sql")) (repositories gitile-configuration-repositories (default "/var/lib/gitolite/repositories")) (base-git-url gitile-configuration-base-git-url) (index-title gitile-configuration-index-title (default "Index")) (intro gitile-configuration-intro (default '())) (footer gitile-configuration-footer (default '())) (nginx gitile-configuration-nginx)) (define (gitile-config-file host port database repositories base-git-url index-title intro footer) (define build #~(write `(config (port #$port) (host #$host) (database #$database) (repositories #$repositories) (base-git-url #$base-git-url) (index-title #$index-title) (intro #$intro) (footer #$footer)) (open-output-file #$output))) (computed-file "gitile.conf" build)) (define gitile-nginx-server-block (match-lambda (($ package host port database repositories base-git-url index-title intro footer nginx) (list (nginx-server-configuration (inherit nginx) (locations (append (list (nginx-location-configuration (uri "/") (body (list #~(string-append "proxy_pass http://" #$host ":" (number->string #$port) "/;"))))) (map (lambda (loc) (nginx-location-configuration (uri loc) (body (list #~(string-append "root " #$package "/share/gitile/assets;"))))) '("/css" "/js" "/images")) (nginx-server-configuration-locations nginx)))))))) (define gitile-shepherd-service (match-lambda (($ package host port database repositories base-git-url index-title intro footer nginx) (list (shepherd-service (provision '(gitile)) (requirement '(loopback)) (documentation "gitile") (start (let ((gitile (file-append package "/bin/gitile"))) #~(make-forkexec-constructor `(,#$gitile "-c" #$(gitile-config-file host port database repositories base-git-url index-title intro footer)) #:user "gitile" #:group "git"))) (stop #~(make-kill-destructor))))))) (define %gitile-accounts (list (user-account (name "gitile") (group "git") (system? #t) (comment "Gitile user") (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))) (define gitile-service-type (service-type (name 'gitile) (description "gitile git forge service") (extensions (list (service-extension account-service-type (const %gitile-accounts)) (service-extension shepherd-root-service-type gitile-shepherd-service) (service-extension nginx-service-type gitile-nginx-server-block)))))