system-configuration/modules/services/gitile.scm

gitile.scm

1
;;; GNU Guix --- Functional package management for GNU
2
;;; Copyright © 2020, 2021 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 services web)
27
  #:use-module (gnu system pam)
28
  #:use-module (gnu system shadow)
29
  #:use-module (gnu packages admin)
30
  #:use-module (packages gitile)
31
  #:use-module (guix gexp)
32
  #:use-module (guix records)
33
  #:use-module (ice-9 match)
34
  #:export (gitile-service-type
35
            gitile-configuration))
36
37
(define-record-type* <gitile-configuration>
38
  gitile-configuration make-gitile-configuration gitile-configuration?
39
  (package gitile-configuration-package
40
           (default gitile))
41
  (host gitile-configuration-host
42
        (default "localhost"))
43
  (port gitile-configuration-port
44
        (default 8080))
45
  (database gitile-configuration-database
46
            (default "/var/lib/gitile/gitile-db.sql"))
47
  (repositories gitile-configuration-repositories
48
                (default "/var/lib/gitolite/repositories"))
49
  (base-git-url gitile-configuration-base-git-url)
50
  (index-title gitile-configuration-index-title
51
               (default "Index"))
52
  (intro gitile-configuration-intro
53
         (default '()))
54
  (footer gitile-configuration-footer
55
          (default '()))
56
  (nginx gitile-configuration-nginx))
57
58
(define (gitile-config-file host port database repositories base-git-url
59
                            index-title intro footer)
60
  (define build
61
    #~(write `(config
62
                (port #$port)
63
                (host #$host)
64
                (database #$database)
65
                (repositories #$repositories)
66
                (base-git-url #$base-git-url)
67
                (index-title #$index-title)
68
                (intro #$intro)
69
                (footer #$footer))
70
             (open-output-file #$output)))
71
72
  (computed-file "gitile.conf" build))
73
74
(define gitile-nginx-server-block
75
  (match-lambda
76
    (($ <gitile-configuration> package host port database repositories
77
        base-git-url index-title intro footer nginx)
78
     (list (nginx-server-configuration
79
             (inherit nginx)
80
             (locations
81
               (append
82
                 (list
83
                   (nginx-location-configuration
84
                            (uri "/")
85
                            (body
86
                              (list
87
                                #~(string-append "proxy_pass http://" #$host
88
                                                 ":" (number->string #$port)
89
                                                 "/;")))))
90
                 (map
91
                   (lambda (loc)
92
                     (nginx-location-configuration
93
                       (uri loc)
94
                       (body
95
                         (list
96
                           #~(string-append "root " #$package "/share/gitile/assets;")))))
97
                   '("/css" "/js" "/images"))
98
                 (nginx-server-configuration-locations nginx))))))))
99
100
(define gitile-shepherd-service
101
  (match-lambda
102
    (($ <gitile-configuration> package host port database repositories
103
        base-git-url index-title intro footer nginx)
104
     (list (shepherd-service
105
             (provision '(gitile))
106
             (requirement '(loopback))
107
             (documentation "gitile")
108
             (start (let ((gitile (file-append package "/bin/gitile")))
109
                          #~(make-forkexec-constructor
110
                              `(,#$gitile "-c" #$(gitile-config-file
111
                                                   host port database
112
                                                   repositories
113
                                                   base-git-url index-title
114
                                                   intro footer))
115
                              #:user "gitile"
116
                              #:group "git")))
117
             (stop #~(make-kill-destructor)))))))
118
119
(define %gitile-accounts
120
  (list (user-account
121
          (name "gitile")
122
          (group "git")
123
          (system? #t)
124
          (comment "Gitile user")
125
          (home-directory "/var/empty")
126
          (shell (file-append shadow "/sbin/nologin")))))
127
128
(define gitile-service-type
129
  (service-type
130
    (name 'gitile)
131
    (description "gitile git forge service")
132
    (extensions
133
      (list (service-extension account-service-type
134
                               (const %gitile-accounts))
135
            (service-extension shepherd-root-service-type
136
                               gitile-shepherd-service)
137
            (service-extension nginx-service-type
138
                               gitile-nginx-server-block)))))
139