system-configuration/modules/services/gitile.scm

gitile.scm

1
;;; GNU Guix --- Functional package management for GNU
2
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
3
;;;
4
;;; This file is part of GNU Guix.
5
;;;
6
;;; GNU Guix is free software; you can redistribute it and/or modify it
7
;;; under the terms of the GNU General Public License as published by
8
;;; the Free Software Foundation; either version 3 of the License, or (at
9
;;; your option) any later version.
10
;;;
11
;;; GNU Guix is distributed in the hope that it will be useful, but
12
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
;;; GNU General Public License for more details.
15
;;;
16
;;; You should have received a copy of the GNU General Public License
17
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
18
;;;
19
;;; Some of the help text was taken from the default dovecot.conf files.
20
21
(define-module (services gitile)
22
  #:use-module (gnu services)
23
  #:use-module (gnu services base)
24
  #:use-module (gnu services configuration)
25
  #:use-module (gnu services shepherd)
26
  #:use-module (gnu system pam)
27
  #:use-module (gnu system shadow)
28
  #:use-module (gnu packages admin)
29
  #:use-module (packages gitile)
30
  #:use-module (guix gexp)
31
  #:use-module (guix records)
32
  #:use-module (ice-9 match)
33
  #:export (gitile-service-type
34
            gitile-configuration))
35
36
(define-record-type* <gitile-configuration>
37
  gitile-configuration make-gitile-configuration gitile-configuration?
38
  (package gitile-configuration-package
39
           (default gitile))
40
  (host gitile-configuration-host
41
        (default "localhost"))
42
  (port gitile-configuration-port
43
        (default 8080))
44
  (database gitile-configuration-database
45
            (default "/var/lib/gitile/gitile-db.sql"))
46
  (repositories gitile-configuration-repositories
47
                (default "/var/lib/gitolite/repositories")))
48
49
(define (gitile-config-file host port database repositories)
50
  (define build
51
    #~(write `(config
52
                (port #$port)
53
                (host #$host)
54
                (database #$database)
55
                (repositories #$repositories))
56
             (open-output-file #$output)))
57
58
  (computed-file "gitile.conf" build))
59
60
(define gitile-shepherd-service
61
  (match-lambda
62
    (($ <gitile-configuration> package host port database repositories)
63
     (list (shepherd-service
64
             (provision '(gitile))
65
             (requirement '(loopback))
66
             (documentation "gitile")
67
             (start (let ((gitile (file-append package "/bin/gitile")))
68
                          #~(make-forkexec-constructor
69
                              `(,#$gitile "-c" #$(gitile-config-file
70
                                                   host port database
71
                                                   repositories))
72
                              #:user "gitile"
73
                              #:group "git")))
74
             (stop #~(make-kill-destructor)))))))
75
76
(define %gitile-accounts
77
  (list (user-account
78
          (name "gitile")
79
          (group "git")
80
          (system? #t)
81
          (comment "Gitile user")
82
          (home-directory "/var/empty")
83
          (shell (file-append shadow "/sbin/nologin")))))
84
85
(define gitile-service-type
86
  (service-type
87
    (name 'gitile)
88
    (extensions
89
      (list (service-extension account-service-type
90
                               (const %gitile-accounts))
91
            (service-extension shepherd-root-service-type
92
                               gitile-shepherd-service)))
93
    (default-value
94
      (gitile-configuration))))
95