gnu: guix-data-service: Update to 0.0.1-7.156b7ee.
[jackhill/guix/guix.git] / gnu / services / guix.scm
CommitLineData
dd2a8327
CB
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Christopher Baines <mail@cbaines.net>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify
7;;; it under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation, either version 3 of the License, or
9;;; (at your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful,
12;;; but 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(define-module (gnu services guix)
20 #:use-module (ice-9 match)
21 #:use-module (guix gexp)
22 #:use-module (guix records)
23 #:use-module ((gnu packages base)
24 #:select (glibc-utf8-locales))
25 #:use-module (gnu packages admin)
26 #:use-module (gnu packages web)
27 #:use-module (gnu services)
28 #:use-module (gnu services base)
29 #:use-module (gnu services admin)
30 #:use-module (gnu services shepherd)
31 #:use-module (gnu services getmail)
32 #:use-module (gnu system shadow)
33 #:export (<guix-data-service-configuration>
34 guix-data-service-configuration
35 guix-data-service-configuration?
36 guix-data-service-package
37 guix-data-service-user
38 guix-data-service-group
39 guix-data-service-port
40 guix-data-service-host
41 guix-data-service-getmail-idle-mailboxes
42 guix-data-service-commits-getmail-retriever-configuration
43
44 guix-data-service-type))
45
46;;;; Commentary:
47;;;
48;;; This module implements a service that to run instances of the Guix Data
49;;; Service, which provides data about Guix over time.
50;;;
51;;;; Code:
52
53(define-record-type* <guix-data-service-configuration>
54 guix-data-service-configuration make-guix-data-service-configuration
55 guix-data-service-configuration?
56 (package guix-data-service-package
57 (default guix-data-service))
58 (user guix-data-service-configuration-user
59 (default "guix-data-service"))
60 (group guix-data-service-configuration-group
61 (default "guix-data-service"))
62 (port guix-data-service-port
63 (default 8765))
64 (host guix-data-service-host
65 (default "127.0.0.1"))
66 (getmail-idle-mailboxes
67 guix-data-service-getmail-idle-mailboxes
68 (default #f))
69 (commits-getmail-retriever-configuration
70 guix-data-service-commits-getmail-retriever-configuration
71 (default #f)))
72
73(define (guix-data-service-profile-packages config)
74 "Return the guix-data-service package, this will populate the
75ca-certificates.crt file in the system profile."
76 (list
77 (guix-data-service-package config)))
78
79(define (guix-data-service-shepherd-services config)
80 (match-record config <guix-data-service-configuration>
81 (package user group port host)
82 (list
83 (shepherd-service
84 (documentation "Guix Data Service web server")
85 (provision '(guix-data-service))
86 (requirement '(postgres networking))
87 (start #~(make-forkexec-constructor
88 (list #$(file-append package
89 "/bin/guix-data-service")
90 "--pid-file=/var/run/guix-data-service/pid"
91 #$(string-append "--port=" (number->string port))
92 #$(string-append "--host=" host)
93 ;; Perform any database migrations when the
94 ;; service is started
95 "--update-database")
96
97 #:user #$user
98 #:group #$group
99 #:pid-file "/var/run/guix-data-service/pid"
100 ;; Allow time for migrations to run
101 #:pid-file-timeout 60
102 #:environment-variables
103 `(,(string-append
104 "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
105 "LC_ALL=en_US.utf8")
106 #:log-file "/var/log/guix-data-service/web.log"))
107 (stop #~(make-kill-destructor)))
108
109 (shepherd-service
110 (documentation "Guix Data Service process jobs")
111 (provision '(guix-data-service-process-jobs))
112 (requirement '(postgres
113 networking
114 ;; Require guix-data-service, as that the database
115 ;; migrations are handled through this service
116 guix-data-service))
117 (start #~(make-forkexec-constructor
118 (list
119 #$(file-append package
120 "/bin/guix-data-service-process-jobs"))
121 #:user #$user
122 #:group #$group
123 #:environment-variables
124 `("HOME=/var/lib/guix-data-service"
125 "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
126 ,(string-append
127 "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
128 "LC_ALL=en_US.utf8")
129 #:log-file "/var/log/guix-data-service/process-jobs.log"))
130 (stop #~(make-kill-destructor))))))
131
132(define (guix-data-service-activation config)
133 #~(begin
134 (use-modules (guix build utils))
135
136 (define %user (getpw "guix-data-service"))
137
138 (chmod "/var/lib/guix-data-service" #o755)
139
140 (mkdir-p "/var/log/guix-data-service")
141
142 ;; Allow writing the PID file
143 (mkdir-p "/var/run/guix-data-service")
144 (chown "/var/run/guix-data-service"
145 (passwd:uid %user)
146 (passwd:gid %user))))
147
148(define (guix-data-service-account config)
149 (match-record config <guix-data-service-configuration>
150 (user group)
151 (list (user-group
152 (name group)
153 (system? #t))
154 (user-account
155 (name user)
156 (group group)
157 (system? #t)
158 (comment "Guix Data Service user")
159 (home-directory "/var/lib/guix-data-service")
160 (shell (file-append shadow "/sbin/nologin"))))))
161
162(define (guix-data-service-getmail-configuration config)
163 (match config
164 (($ <guix-data-service-configuration> package user group
165 port host
166 #f #f)
167 '())
168 (($ <guix-data-service-configuration> package user group
169 port host
170 getmail-idle-mailboxes
171 commits-getmail-retriever-configuration)
172 (list
173 (getmail-configuration
174 (name 'guix-data-service)
175 (user user)
176 (group group)
177 (directory "/var/lib/getmail/guix-data-service")
178 (rcfile
179 (getmail-configuration-file
180 (retriever commits-getmail-retriever-configuration)
181 (destination
182 (getmail-destination-configuration
183 (type "MDA_external")
184 (path (file-append
185 package
186 "/bin/guix-data-service-process-branch-updated-email"))))
187 (options
188 (getmail-options-configuration
189 (read-all #f)
190 (delivered-to #f)
191 (received #f)))))
192 (idle getmail-idle-mailboxes))))))
193
194(define guix-data-service-type
195 (service-type
196 (name 'guix-data-service)
197 (extensions
198 (list
199 (service-extension profile-service-type
200 guix-data-service-profile-packages)
201 (service-extension shepherd-root-service-type
202 guix-data-service-shepherd-services)
203 (service-extension activation-service-type
204 guix-data-service-activation)
205 (service-extension account-service-type
206 guix-data-service-account)
207 (service-extension getmail-service-type
208 guix-data-service-getmail-configuration)))
209 (default-value
210 (guix-data-service-configuration))
211 (description
212 "Run an instance of the Guix Data Service.")))