Commit | Line | Data |
---|---|---|
dd2a8327 | 1 | ;;; GNU Guix --- Functional package management for GNU |
087cdafc | 2 | ;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <mail@cbaines.net> |
dd2a8327 CB |
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) | |
15955e9b | 20 | #:use-module (srfi srfi-1) |
dd2a8327 CB |
21 | #:use-module (ice-9 match) |
22 | #:use-module (guix gexp) | |
23 | #:use-module (guix records) | |
15955e9b | 24 | #:use-module (guix packages) |
dd2a8327 CB |
25 | #:use-module ((gnu packages base) |
26 | #:select (glibc-utf8-locales)) | |
27 | #:use-module (gnu packages admin) | |
15955e9b | 28 | #:use-module (gnu packages databases) |
dd2a8327 | 29 | #:use-module (gnu packages web) |
15955e9b CB |
30 | #:use-module (gnu packages guile) |
31 | #:use-module (gnu packages guile-xyz) | |
32 | #:use-module (gnu packages package-management) | |
dd2a8327 CB |
33 | #:use-module (gnu services) |
34 | #:use-module (gnu services base) | |
35 | #:use-module (gnu services admin) | |
36 | #:use-module (gnu services shepherd) | |
37 | #:use-module (gnu services getmail) | |
38 | #:use-module (gnu system shadow) | |
15955e9b CB |
39 | #:export (guix-build-coordinator-configuration |
40 | guix-build-coordinator-configuration? | |
41 | guix-build-coordinator-configuration-package | |
42 | guix-build-coordinator-configuration-user | |
43 | guix-build-coordinator-configuration-group | |
44 | guix-build-coordinator-configuration-datastore-uri-string | |
45 | guix-build-coordinator-configuration-agent-communication-uri-string | |
46 | guix-build-coordinator-configuration-client-communication-uri-string | |
47 | guix-build-coordinator-configuration-allocation-strategy | |
48 | guix-build-coordinator-configuration-hooks | |
09aeabb9 | 49 | guix-build-coordinator-configuration-parallel-hooks |
15955e9b CB |
50 | guix-build-coordinator-configuration-guile |
51 | ||
52 | guix-build-coordinator-service-type | |
53 | ||
98ab323a CB |
54 | guix-build-coordinator-agent-configuration |
55 | guix-build-coordinator-agent-configuration? | |
56 | guix-build-coordinator-agent-configuration-package | |
57 | guix-build-coordinator-agent-configuration-user | |
58 | guix-build-coordinator-agent-configuration-coordinator | |
7556130c | 59 | guix-build-coordinator-agent-configuration-authentication |
98ab323a CB |
60 | guix-build-coordinator-agent-configuration-systems |
61 | guix-build-coordinator-agent-configuration-max-parallel-builds | |
e83b9fe4 | 62 | guix-build-coordinator-agent-configuration-max-allocated-builds |
e2ab6fb0 | 63 | guix-build-coordinator-agent-configuration-max-1min-load-average |
98ab323a CB |
64 | guix-build-coordinator-agent-configuration-derivation-substitute-urls |
65 | guix-build-coordinator-agent-configuration-non-derivation-substitute-urls | |
66 | ||
7556130c CB |
67 | guix-build-coordinator-agent-password-auth |
68 | guix-build-coordinator-agent-password-auth? | |
69 | guix-build-coordinator-agent-password-auth-uuid | |
70 | guix-build-coordinator-agent-password-auth-password | |
71 | ||
72 | guix-build-coordinator-agent-password-file-auth | |
73 | guix-build-coordinator-agent-password-file-auth? | |
74 | guix-build-coordinator-agent-password-file-auth-uuid | |
75 | guix-build-coordinator-agent-password-file-auth-password-file | |
76 | ||
8a7b4ce0 CB |
77 | guix-build-coordinator-agent-dynamic-auth |
78 | guix-build-coordinator-agent-dynamic-auth? | |
79 | guix-build-coordinator-agent-dynamic-auth-agent-name | |
80 | guix-build-coordinator-agent-dynamic-auth-token | |
81 | ||
c6c48494 CB |
82 | guix-build-coordinator-agent-dynamic-auth-with-file |
83 | guix-build-coordinator-agent-dynamic-auth-with-file? | |
84 | guix-build-coordinator-agent-dynamic-auth-with-file-agent-name | |
85 | guix-build-coordinator-agent-dynamic-auth-with-file-token-file | |
86 | ||
98ab323a CB |
87 | guix-build-coordinator-agent-service-type |
88 | ||
c14714cb CB |
89 | guix-build-coordinator-queue-builds-configuration |
90 | guix-build-coordinator-queue-builds-configuration? | |
91 | guix-build-coordinator-queue-builds-configuration-package | |
92 | guix-build-coordinator-queue-builds-configuration-user | |
93 | guix-build-coordinator-queue-builds-coordinator | |
94 | guix-build-coordinator-queue-builds-configuration-systems | |
95 | guix-build-coordinator-queue-builds-configuration-system-and-targets | |
96 | guix-build-coordinator-queue-builds-configuration-guix-data-service | |
c4ad2757 | 97 | guix-build-coordinator-queue-builds-configuration-guix-data-service-build-server-id |
c14714cb CB |
98 | guix-build-coordinator-queue-builds-configuration-processed-commits-file |
99 | ||
100 | guix-build-coordinator-queue-builds-service-type | |
101 | ||
15955e9b | 102 | <guix-data-service-configuration> |
dd2a8327 CB |
103 | guix-data-service-configuration |
104 | guix-data-service-configuration? | |
105 | guix-data-service-package | |
106 | guix-data-service-user | |
107 | guix-data-service-group | |
108 | guix-data-service-port | |
109 | guix-data-service-host | |
110 | guix-data-service-getmail-idle-mailboxes | |
111 | guix-data-service-commits-getmail-retriever-configuration | |
112 | ||
087cdafc CB |
113 | guix-data-service-type |
114 | ||
115 | nar-herder-service-type | |
116 | nar-herder-configuration | |
117 | nar-herder-configuration? | |
118 | nar-herder-configuration-package | |
119 | nar-herder-configuration-user | |
120 | nar-herder-configuration-group | |
121 | nar-herder-configuration-mirror | |
122 | nar-herder-configuration-database | |
123 | nar-herder-configuration-database-dump | |
124 | nar-herder-configuration-host | |
125 | nar-herder-configuration-port | |
126 | nar-herder-configuration-storage | |
127 | nar-herder-configuration-storage-limit | |
e32cc011 CB |
128 | nar-herder-configuration-storage-nar-removal-criteria |
129 | nar-herder-configuration-log-level)) | |
dd2a8327 CB |
130 | |
131 | ;;;; Commentary: | |
132 | ;;; | |
15955e9b | 133 | ;;; Services specifically related to GNU Guix. |
dd2a8327 CB |
134 | ;;; |
135 | ;;;; Code: | |
136 | ||
15955e9b CB |
137 | (define-record-type* <guix-build-coordinator-configuration> |
138 | guix-build-coordinator-configuration make-guix-build-coordinator-configuration | |
139 | guix-build-coordinator-configuration? | |
140 | (package guix-build-coordinator-configuration-package | |
141 | (default guix-build-coordinator)) | |
142 | (user guix-build-coordinator-configuration-user | |
143 | (default "guix-build-coordinator")) | |
144 | (group guix-build-coordinator-configuration-group | |
145 | (default "guix-build-coordinator")) | |
146 | (database-uri-string | |
147 | guix-build-coordinator-configuration-datastore-uri-string | |
148 | (default "sqlite:///var/lib/guix-build-coordinator/guix_build_coordinator.db")) | |
149 | (agent-communication-uri-string | |
150 | guix-build-coordinator-configuration-agent-communication-uri-string | |
151 | (default "http://0.0.0.0:8745")) | |
152 | (client-communication-uri-string | |
153 | guix-build-coordinator-configuration-client-communication-uri-string | |
154 | (default "http://127.0.0.1:8746")) | |
155 | (allocation-strategy | |
156 | guix-build-coordinator-configuration-allocation-strategy | |
157 | (default #~basic-build-allocation-strategy)) | |
158 | (hooks guix-build-coordinator-configuration-hooks | |
159 | (default '())) | |
09aeabb9 CB |
160 | (parallel-hooks guix-build-coordinator-configuration-parallel-hooks |
161 | (default '())) | |
15955e9b CB |
162 | (guile guix-build-coordinator-configuration-guile |
163 | (default guile-3.0-latest))) | |
164 | ||
98ab323a CB |
165 | (define-record-type* <guix-build-coordinator-agent-configuration> |
166 | guix-build-coordinator-agent-configuration | |
167 | make-guix-build-coordinator-agent-configuration | |
168 | guix-build-coordinator-agent-configuration? | |
169 | (package guix-build-coordinator-agent-configuration-package | |
dfc5d524 | 170 | (default guix-build-coordinator/agent-only)) |
98ab323a CB |
171 | (user guix-build-coordinator-agent-configuration-user |
172 | (default "guix-build-coordinator-agent")) | |
173 | (coordinator guix-build-coordinator-agent-configuration-coordinator | |
174 | (default "http://localhost:8745")) | |
7556130c | 175 | (authentication guix-build-coordinator-agent-configuration-authentication) |
98ab323a CB |
176 | (systems guix-build-coordinator-agent-configuration-systems |
177 | (default #f)) | |
178 | (max-parallel-builds | |
179 | guix-build-coordinator-agent-configuration-max-parallel-builds | |
180 | (default 1)) | |
e83b9fe4 CB |
181 | (max-allocated-builds |
182 | guix-build-coordinator-agent-configuration-max-allocated-builds | |
183 | (default #f)) | |
e2ab6fb0 CB |
184 | (max-1min-load-average |
185 | guix-build-coordinator-agent-configuration-max-1min-load-average | |
186 | (default #f)) | |
98ab323a CB |
187 | (derivation-substitute-urls |
188 | guix-build-coordinator-agent-configuration-derivation-substitute-urls | |
189 | (default #f)) | |
190 | (non-derivation-substitute-urls | |
191 | guix-build-coordinator-agent-configuration-non-derivation-substitute-urls | |
192 | (default #f))) | |
193 | ||
7556130c CB |
194 | (define-record-type* <guix-build-coordinator-agent-password-auth> |
195 | guix-build-coordinator-agent-password-auth | |
196 | make-guix-build-coordinator-agent-password-auth | |
197 | guix-build-coordinator-agent-password-auth? | |
198 | (uuid guix-build-coordinator-agent-password-auth-uuid) | |
199 | (password guix-build-coordinator-agent-password-auth-password)) | |
200 | ||
201 | (define-record-type* <guix-build-coordinator-agent-password-file-auth> | |
202 | guix-build-coordinator-agent-password-file-auth | |
203 | make-guix-build-coordinator-agent-password-file-auth | |
204 | guix-build-coordinator-agent-password-file-auth? | |
205 | (uuid guix-build-coordinator-agent-password-file-auth-uuid) | |
206 | (password-file | |
207 | guix-build-coordinator-agent-password-file-auth-password-file)) | |
208 | ||
8a7b4ce0 CB |
209 | (define-record-type* <guix-build-coordinator-agent-dynamic-auth> |
210 | guix-build-coordinator-agent-dynamic-auth | |
211 | make-guix-build-coordinator-agent-dynamic-auth | |
212 | guix-build-coordinator-agent-dynamic-auth? | |
213 | (agent-name guix-build-coordinator-agent-dynamic-auth-agent-name) | |
214 | (token guix-build-coordinator-agent-dynamic-auth-token)) | |
215 | ||
c6c48494 CB |
216 | (define-record-type* <guix-build-coordinator-agent-dynamic-auth-with-file> |
217 | guix-build-coordinator-agent-dynamic-auth-with-file | |
218 | make-guix-build-coordinator-agent-dynamic-auth-with-file | |
219 | guix-build-coordinator-agent-dynamic-auth-with-file? | |
220 | (agent-name guix-build-coordinator-agent-dynamic-auth-with-file-agent-name) | |
221 | (token-file guix-build-coordinator-agent-dynamic-auth-with-file-token-file)) | |
222 | ||
c14714cb CB |
223 | (define-record-type* <guix-build-coordinator-queue-builds-configuration> |
224 | guix-build-coordinator-queue-builds-configuration | |
225 | make-guix-build-coordinator-queue-builds-configuration | |
226 | guix-build-coordinator-queue-builds-configuration? | |
227 | (package guix-build-coordinator-queue-builds-configuration-package | |
228 | (default guix-build-coordinator)) | |
229 | (user guix-build-coordinator-queue-builds-configuration-user | |
230 | (default "guix-build-coordinator-queue-builds")) | |
231 | (coordinator guix-build-coordinator-queue-builds-coordinator | |
311e4b00 | 232 | (default "http://localhost:8746")) |
c14714cb CB |
233 | (systems guix-build-coordinator-queue-builds-configuration-systems |
234 | (default #f)) | |
235 | (systems-and-targets | |
236 | guix-build-coordinator-queue-builds-configuration-system-and-targets | |
237 | (default #f)) | |
238 | (guix-data-service | |
239 | guix-build-coordinator-queue-builds-configuration-guix-data-service | |
240 | (default "https://data.guix.gnu.org")) | |
c4ad2757 CB |
241 | (guix-data-service-build-server-id |
242 | guix-build-coordinator-queue-builds-configuration-guix-data-service-build-server-id | |
243 | (default #f)) | |
c14714cb CB |
244 | (processed-commits-file |
245 | guix-build-coordinator-queue-builds-configuration-processed-commits-file | |
246 | (default "/var/cache/guix-build-coordinator-queue-builds/processed-commits"))) | |
247 | ||
15955e9b CB |
248 | (define* (make-guix-build-coordinator-start-script database-uri-string |
249 | allocation-strategy | |
250 | pid-file | |
251 | guix-build-coordinator-package | |
252 | #:key | |
253 | agent-communication-uri-string | |
254 | client-communication-uri-string | |
255 | (hooks '()) | |
09aeabb9 | 256 | (parallel-hooks '()) |
15955e9b CB |
257 | (guile guile-3.0)) |
258 | (program-file | |
259 | "start-guix-build-coordinator" | |
260 | (with-extensions (cons guix-build-coordinator-package | |
261 | ;; This is a poorly constructed Guile load path, | |
262 | ;; since it contains things that aren't Guile | |
263 | ;; libraries, but it means that the Guile libraries | |
264 | ;; needed for the Guix Build Coordinator don't need | |
265 | ;; to be individually specified here. | |
b0d6098f CB |
266 | (append |
267 | (map second (package-inputs | |
268 | guix-build-coordinator-package)) | |
269 | (map second (package-propagated-inputs | |
270 | guix-build-coordinator-package)))) | |
15955e9b CB |
271 | #~(begin |
272 | (use-modules (srfi srfi-1) | |
273 | (ice-9 match) | |
274 | (web uri) | |
275 | (prometheus) | |
276 | (guix-build-coordinator hooks) | |
277 | (guix-build-coordinator datastore) | |
278 | (guix-build-coordinator build-allocator) | |
279 | (guix-build-coordinator coordinator)) | |
280 | ||
bdaaa6b3 CB |
281 | (setvbuf (current-output-port) 'line) |
282 | (setvbuf (current-error-port) 'line) | |
283 | ||
b9f8ce17 CB |
284 | (simple-format #t "starting the guix-build-coordinator:\n ~A\n" |
285 | (current-filename)) | |
15955e9b CB |
286 | (let* ((metrics-registry (make-metrics-registry |
287 | #:namespace | |
4b8acf71 | 288 | "guixbuildcoordinator")) |
15955e9b CB |
289 | (datastore (database-uri->datastore |
290 | #$database-uri-string | |
291 | #:metrics-registry metrics-registry)) | |
292 | (hooks | |
293 | (list #$@(map (match-lambda | |
294 | ((name . hook-gexp) | |
b34ac307 | 295 | #~(cons '#$name #$hook-gexp))) |
15955e9b CB |
296 | hooks))) |
297 | (hooks-with-defaults | |
298 | `(,@hooks | |
299 | ,@(remove (match-lambda | |
300 | ((name . _) (assq-ref hooks name))) | |
301 | %default-hooks))) | |
302 | (build-coordinator (make-build-coordinator | |
303 | #:datastore datastore | |
304 | #:hooks hooks-with-defaults | |
305 | #:metrics-registry metrics-registry | |
306 | #:allocation-strategy #$allocation-strategy))) | |
307 | ||
308 | (run-coordinator-service | |
309 | build-coordinator | |
310 | #:update-datastore? #t | |
311 | #:pid-file #$pid-file | |
312 | #:agent-communication-uri (string->uri | |
313 | #$agent-communication-uri-string) | |
314 | #:client-communication-uri (string->uri | |
09aeabb9 | 315 | #$client-communication-uri-string) |
e069de45 CB |
316 | #:parallel-hooks (list #$@(map (match-lambda |
317 | ((name . val) | |
318 | #~(cons '#$name #$val))) | |
319 | parallel-hooks)))))) | |
15955e9b CB |
320 | #:guile guile)) |
321 | ||
322 | (define (guix-build-coordinator-shepherd-services config) | |
323 | (match-record config <guix-build-coordinator-configuration> | |
324 | (package user group database-uri-string | |
325 | agent-communication-uri-string | |
326 | client-communication-uri-string | |
327 | allocation-strategy | |
328 | hooks | |
09aeabb9 | 329 | parallel-hooks |
15955e9b CB |
330 | guile) |
331 | (list | |
332 | (shepherd-service | |
333 | (documentation "Guix Build Coordinator") | |
334 | (provision '(guix-build-coordinator)) | |
335 | (requirement '(networking)) | |
336 | (start #~(make-forkexec-constructor | |
337 | (list #$(make-guix-build-coordinator-start-script | |
338 | database-uri-string | |
339 | allocation-strategy | |
340 | "/var/run/guix-build-coordinator/pid" | |
341 | package | |
342 | #:agent-communication-uri-string | |
343 | agent-communication-uri-string | |
344 | #:client-communication-uri-string | |
345 | client-communication-uri-string | |
346 | #:hooks hooks | |
09aeabb9 | 347 | #:parallel-hooks parallel-hooks |
15955e9b CB |
348 | #:guile guile)) |
349 | #:user #$user | |
350 | #:group #$group | |
351 | #:pid-file "/var/run/guix-build-coordinator/pid" | |
352 | ;; Allow time for migrations to run | |
353 | #:pid-file-timeout 60 | |
354 | #:environment-variables | |
355 | `(,(string-append | |
356 | "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale") | |
ced9da90 CB |
357 | "LC_ALL=en_US.utf8" |
358 | "PATH=/run/current-system/profile/bin") ; for hooks | |
15955e9b CB |
359 | #:log-file "/var/log/guix-build-coordinator/coordinator.log")) |
360 | (stop #~(make-kill-destructor)))))) | |
361 | ||
362 | (define (guix-build-coordinator-activation config) | |
363 | #~(begin | |
364 | (use-modules (guix build utils)) | |
365 | ||
51201d63 CB |
366 | (define %user |
367 | (getpw #$(guix-build-coordinator-configuration-user | |
368 | config))) | |
15955e9b CB |
369 | |
370 | (chmod "/var/lib/guix-build-coordinator" #o755) | |
371 | ||
372 | (mkdir-p "/var/log/guix-build-coordinator") | |
373 | ||
374 | ;; Allow writing the PID file | |
375 | (mkdir-p "/var/run/guix-build-coordinator") | |
376 | (chown "/var/run/guix-build-coordinator" | |
377 | (passwd:uid %user) | |
378 | (passwd:gid %user)))) | |
379 | ||
380 | (define (guix-build-coordinator-account config) | |
381 | (match-record config <guix-build-coordinator-configuration> | |
382 | (user group) | |
383 | (list (user-group | |
384 | (name group) | |
385 | (system? #t)) | |
386 | (user-account | |
387 | (name user) | |
388 | (group group) | |
389 | (system? #t) | |
390 | (comment "Guix Build Coordinator user") | |
391 | (home-directory "/var/lib/guix-build-coordinator") | |
392 | (shell (file-append shadow "/sbin/nologin")))))) | |
393 | ||
394 | (define guix-build-coordinator-service-type | |
395 | (service-type | |
396 | (name 'guix-build-coordinator) | |
397 | (extensions | |
398 | (list | |
399 | (service-extension shepherd-root-service-type | |
400 | guix-build-coordinator-shepherd-services) | |
401 | (service-extension activation-service-type | |
402 | guix-build-coordinator-activation) | |
403 | (service-extension account-service-type | |
404 | guix-build-coordinator-account))) | |
405 | (default-value | |
406 | (guix-build-coordinator-configuration)) | |
407 | (description | |
408 | "Run an instance of the Guix Build Coordinator."))) | |
409 | ||
98ab323a CB |
410 | (define (guix-build-coordinator-agent-shepherd-services config) |
411 | (match-record config <guix-build-coordinator-agent-configuration> | |
7556130c | 412 | (package user coordinator authentication max-parallel-builds |
e83b9fe4 | 413 | max-allocated-builds |
e2ab6fb0 | 414 | max-1min-load-average |
98ab323a CB |
415 | derivation-substitute-urls non-derivation-substitute-urls |
416 | systems) | |
417 | (list | |
418 | (shepherd-service | |
419 | (documentation "Guix Build Coordinator Agent") | |
420 | (provision '(guix-build-coordinator-agent)) | |
421 | (requirement '(networking)) | |
422 | (start #~(make-forkexec-constructor | |
423 | (list #$(file-append package "/bin/guix-build-coordinator-agent") | |
424 | #$(string-append "--coordinator=" coordinator) | |
7556130c CB |
425 | #$@(match authentication |
426 | (($ <guix-build-coordinator-agent-password-auth> | |
427 | uuid password) | |
428 | #~(#$(string-append "--uuid=" uuid) | |
429 | #$(string-append "--password=" password))) | |
430 | (($ <guix-build-coordinator-agent-password-file-auth> | |
431 | uuid password-file) | |
432 | #~(#$(string-append "--uuid=" uuid) | |
433 | #$(string-append "--password-file=" | |
8a7b4ce0 CB |
434 | password-file))) |
435 | (($ <guix-build-coordinator-agent-dynamic-auth> | |
436 | agent-name token) | |
437 | #~(#$(string-append "--name=" agent-name) | |
c6c48494 CB |
438 | #$(string-append "--dynamic-auth-token=" token))) |
439 | (($ | |
440 | <guix-build-coordinator-agent-dynamic-auth-with-file> | |
441 | agent-name token-file) | |
442 | #~(#$(string-append "--name=" agent-name) | |
443 | #$(string-append "--dynamic-auth-token-file=" | |
444 | token-file)))) | |
98ab323a CB |
445 | #$(simple-format #f "--max-parallel-builds=~A" |
446 | max-parallel-builds) | |
e83b9fe4 CB |
447 | #$@(if max-allocated-builds |
448 | #~(#$(simple-format #f "--max-allocated-builds=~A" | |
449 | max-allocated-builds)) | |
450 | #~()) | |
e2ab6fb0 CB |
451 | #$@(if max-1min-load-average |
452 | #~(#$(simple-format #f "--max-1min-load-average=~A" | |
453 | max-1min-load-average)) | |
454 | #~()) | |
98ab323a CB |
455 | #$@(if derivation-substitute-urls |
456 | #~(#$(string-append | |
457 | "--derivation-substitute-urls=" | |
458 | (string-join derivation-substitute-urls " "))) | |
459 | #~()) | |
460 | #$@(if non-derivation-substitute-urls | |
461 | #~(#$(string-append | |
462 | "--non-derivation-substitute-urls=" | |
f9000450 | 463 | (string-join non-derivation-substitute-urls " "))) |
98ab323a CB |
464 | #~()) |
465 | #$@(map (lambda (system) | |
466 | (string-append "--system=" system)) | |
467 | (or systems '()))) | |
468 | #:user #$user | |
98ab323a CB |
469 | #:environment-variables |
470 | `(,(string-append | |
471 | "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale") | |
b6ece1c2 CB |
472 | ;; XDG_CACHE_HOME is used by Guix when caching narinfo files |
473 | "XDG_CACHE_HOME=/var/cache/guix-build-coordinator-agent" | |
98ab323a CB |
474 | "LC_ALL=en_US.utf8") |
475 | #:log-file "/var/log/guix-build-coordinator/agent.log")) | |
476 | (stop #~(make-kill-destructor)))))) | |
477 | ||
478 | (define (guix-build-coordinator-agent-activation config) | |
479 | #~(begin | |
480 | (use-modules (guix build utils)) | |
481 | ||
51201d63 CB |
482 | (define %user |
483 | (getpw #$(guix-build-coordinator-agent-configuration-user | |
484 | config))) | |
922a5099 | 485 | |
98ab323a CB |
486 | (mkdir-p "/var/log/guix-build-coordinator") |
487 | ||
b6ece1c2 CB |
488 | ;; Create a cache directory for storing narinfo files if downloaded |
489 | (mkdir-p "/var/cache/guix-build-coordinator-agent") | |
490 | (chown "/var/cache/guix-build-coordinator-agent" | |
98ab323a CB |
491 | (passwd:uid %user) |
492 | (passwd:gid %user)))) | |
493 | ||
494 | (define (guix-build-coordinator-agent-account config) | |
495 | (list (user-account | |
496 | (name (guix-build-coordinator-agent-configuration-user config)) | |
497 | (group "nogroup") | |
498 | (system? #t) | |
499 | (comment "Guix Build Coordinator agent user") | |
500 | (home-directory "/var/empty") | |
501 | (shell (file-append shadow "/sbin/nologin"))))) | |
502 | ||
503 | (define guix-build-coordinator-agent-service-type | |
504 | (service-type | |
505 | (name 'guix-build-coordinator-agent) | |
506 | (extensions | |
507 | (list | |
508 | (service-extension shepherd-root-service-type | |
509 | guix-build-coordinator-agent-shepherd-services) | |
510 | (service-extension activation-service-type | |
511 | guix-build-coordinator-agent-activation) | |
512 | (service-extension account-service-type | |
513 | guix-build-coordinator-agent-account))) | |
514 | (description | |
515 | "Run a Guix Build Coordinator agent."))) | |
516 | ||
c14714cb CB |
517 | (define (guix-build-coordinator-queue-builds-shepherd-services config) |
518 | (match-record config <guix-build-coordinator-queue-builds-configuration> | |
519 | (package user coordinator systems systems-and-targets | |
c4ad2757 CB |
520 | guix-data-service |
521 | guix-data-service-build-server-id | |
522 | processed-commits-file) | |
c14714cb CB |
523 | (list |
524 | (shepherd-service | |
525 | (documentation "Guix Build Coordinator queue builds from Guix Data Service") | |
526 | (provision '(guix-build-coordinator-queue-builds)) | |
527 | (requirement '(networking)) | |
528 | (start | |
529 | #~(make-forkexec-constructor | |
530 | (list | |
531 | #$(file-append | |
532 | package | |
533 | "/bin/guix-build-coordinator-queue-builds-from-guix-data-service") | |
534 | #$(string-append "--coordinator=" coordinator) | |
535 | #$@(map (lambda (system) | |
536 | (string-append "--system=" system)) | |
537 | (or systems '())) | |
538 | #$@(map (match-lambda | |
539 | ((system . target) | |
540 | (string-append "--system-and-target=" system "=" target))) | |
541 | (or systems-and-targets '())) | |
542 | #$@(if guix-data-service | |
543 | #~(#$(string-append "--guix-data-service=" guix-data-service)) | |
544 | #~()) | |
c4ad2757 CB |
545 | #$@(if guix-data-service-build-server-id |
546 | #~(#$(simple-format | |
547 | #f | |
548 | "--guix-data-service-build-server-id=~A" | |
549 | guix-data-service-build-server-id)) | |
550 | #~()) | |
c14714cb CB |
551 | #$@(if processed-commits-file |
552 | #~(#$(string-append "--processed-commits-file=" | |
553 | processed-commits-file)) | |
554 | #~())) | |
555 | #:user #$user | |
c14714cb CB |
556 | #:environment-variables |
557 | `(,(string-append | |
558 | "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale") | |
559 | "LC_ALL=en_US.utf8") | |
560 | #:log-file "/var/log/guix-build-coordinator/queue-builds.log")) | |
561 | (stop #~(make-kill-destructor)))))) | |
562 | ||
563 | (define (guix-build-coordinator-queue-builds-activation config) | |
564 | #~(begin | |
565 | (use-modules (guix build utils)) | |
566 | ||
51201d63 CB |
567 | (define %user |
568 | (getpw #$(guix-build-coordinator-queue-builds-configuration-user | |
569 | config))) | |
570 | ||
c14714cb CB |
571 | (mkdir-p "/var/log/guix-build-coordinator") |
572 | ||
c1131911 CB |
573 | ;; Allow writing the processed commits file |
574 | (mkdir-p "/var/cache/guix-build-coordinator-queue-builds") | |
575 | (chown "/var/cache/guix-build-coordinator-queue-builds" | |
c14714cb CB |
576 | (passwd:uid %user) |
577 | (passwd:gid %user)))) | |
578 | ||
579 | (define (guix-build-coordinator-queue-builds-account config) | |
580 | (list (user-account | |
581 | (name (guix-build-coordinator-queue-builds-configuration-user config)) | |
582 | (group "nogroup") | |
583 | (system? #t) | |
584 | (comment "Guix Build Coordinator queue-builds user") | |
585 | (home-directory "/var/empty") | |
586 | (shell (file-append shadow "/sbin/nologin"))))) | |
587 | ||
588 | (define guix-build-coordinator-queue-builds-service-type | |
589 | (service-type | |
590 | (name 'guix-build-coordinator-queue-builds) | |
591 | (extensions | |
592 | (list | |
593 | (service-extension shepherd-root-service-type | |
594 | guix-build-coordinator-queue-builds-shepherd-services) | |
595 | (service-extension activation-service-type | |
596 | guix-build-coordinator-queue-builds-activation) | |
597 | (service-extension account-service-type | |
598 | guix-build-coordinator-queue-builds-account))) | |
599 | (description | |
600 | "Run the guix-build-coordinator-queue-builds-from-guix-data-service | |
601 | script. | |
602 | ||
603 | This is a script to assist in having the Guix Build Coordinator build | |
604 | derivations stored in an instance of the Guix Data Service."))) | |
605 | ||
15955e9b CB |
606 | \f |
607 | ;;; | |
608 | ;;; Guix Data Service | |
609 | ;;; | |
610 | ||
dd2a8327 CB |
611 | (define-record-type* <guix-data-service-configuration> |
612 | guix-data-service-configuration make-guix-data-service-configuration | |
613 | guix-data-service-configuration? | |
614 | (package guix-data-service-package | |
615 | (default guix-data-service)) | |
616 | (user guix-data-service-configuration-user | |
617 | (default "guix-data-service")) | |
618 | (group guix-data-service-configuration-group | |
619 | (default "guix-data-service")) | |
620 | (port guix-data-service-port | |
621 | (default 8765)) | |
622 | (host guix-data-service-host | |
623 | (default "127.0.0.1")) | |
624 | (getmail-idle-mailboxes | |
625 | guix-data-service-getmail-idle-mailboxes | |
626 | (default #f)) | |
627 | (commits-getmail-retriever-configuration | |
628 | guix-data-service-commits-getmail-retriever-configuration | |
d8ab68b9 CB |
629 | (default #f)) |
630 | (extra-options guix-data-service-extra-options | |
631 | (default '())) | |
632 | (extra-process-jobs-options | |
633 | guix-data-service-extra-process-jobs-options | |
634 | (default '()))) | |
dd2a8327 CB |
635 | |
636 | (define (guix-data-service-profile-packages config) | |
637 | "Return the guix-data-service package, this will populate the | |
638 | ca-certificates.crt file in the system profile." | |
639 | (list | |
640 | (guix-data-service-package config))) | |
641 | ||
642 | (define (guix-data-service-shepherd-services config) | |
643 | (match-record config <guix-data-service-configuration> | |
d8ab68b9 | 644 | (package user group port host extra-options extra-process-jobs-options) |
dd2a8327 CB |
645 | (list |
646 | (shepherd-service | |
647 | (documentation "Guix Data Service web server") | |
648 | (provision '(guix-data-service)) | |
649 | (requirement '(postgres networking)) | |
650 | (start #~(make-forkexec-constructor | |
651 | (list #$(file-append package | |
652 | "/bin/guix-data-service") | |
653 | "--pid-file=/var/run/guix-data-service/pid" | |
654 | #$(string-append "--port=" (number->string port)) | |
655 | #$(string-append "--host=" host) | |
656 | ;; Perform any database migrations when the | |
657 | ;; service is started | |
d8ab68b9 CB |
658 | "--update-database" |
659 | #$@extra-options) | |
dd2a8327 CB |
660 | |
661 | #:user #$user | |
662 | #:group #$group | |
663 | #:pid-file "/var/run/guix-data-service/pid" | |
dd2a8327 CB |
664 | #:environment-variables |
665 | `(,(string-append | |
666 | "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale") | |
65c9f07a | 667 | "LC_ALL=en_US.UTF-8") |
dd2a8327 CB |
668 | #:log-file "/var/log/guix-data-service/web.log")) |
669 | (stop #~(make-kill-destructor))) | |
670 | ||
671 | (shepherd-service | |
672 | (documentation "Guix Data Service process jobs") | |
673 | (provision '(guix-data-service-process-jobs)) | |
674 | (requirement '(postgres | |
675 | networking | |
676 | ;; Require guix-data-service, as that the database | |
677 | ;; migrations are handled through this service | |
678 | guix-data-service)) | |
679 | (start #~(make-forkexec-constructor | |
680 | (list | |
681 | #$(file-append package | |
d8ab68b9 CB |
682 | "/bin/guix-data-service-process-jobs") |
683 | #$@extra-process-jobs-options) | |
dd2a8327 CB |
684 | #:user #$user |
685 | #:group #$group | |
686 | #:environment-variables | |
687 | `("HOME=/var/lib/guix-data-service" | |
688 | "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt" | |
689 | ,(string-append | |
690 | "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale") | |
65c9f07a | 691 | "LC_ALL=en_US.UTF-8") |
dd2a8327 CB |
692 | #:log-file "/var/log/guix-data-service/process-jobs.log")) |
693 | (stop #~(make-kill-destructor)))))) | |
694 | ||
695 | (define (guix-data-service-activation config) | |
696 | #~(begin | |
697 | (use-modules (guix build utils)) | |
698 | ||
699 | (define %user (getpw "guix-data-service")) | |
700 | ||
701 | (chmod "/var/lib/guix-data-service" #o755) | |
702 | ||
703 | (mkdir-p "/var/log/guix-data-service") | |
704 | ||
705 | ;; Allow writing the PID file | |
706 | (mkdir-p "/var/run/guix-data-service") | |
707 | (chown "/var/run/guix-data-service" | |
708 | (passwd:uid %user) | |
709 | (passwd:gid %user)))) | |
710 | ||
711 | (define (guix-data-service-account config) | |
712 | (match-record config <guix-data-service-configuration> | |
713 | (user group) | |
714 | (list (user-group | |
715 | (name group) | |
716 | (system? #t)) | |
717 | (user-account | |
718 | (name user) | |
719 | (group group) | |
720 | (system? #t) | |
721 | (comment "Guix Data Service user") | |
722 | (home-directory "/var/lib/guix-data-service") | |
723 | (shell (file-append shadow "/sbin/nologin")))))) | |
724 | ||
725 | (define (guix-data-service-getmail-configuration config) | |
726 | (match config | |
727 | (($ <guix-data-service-configuration> package user group | |
728 | port host | |
729 | #f #f) | |
730 | '()) | |
731 | (($ <guix-data-service-configuration> package user group | |
732 | port host | |
733 | getmail-idle-mailboxes | |
734 | commits-getmail-retriever-configuration) | |
735 | (list | |
736 | (getmail-configuration | |
737 | (name 'guix-data-service) | |
738 | (user user) | |
739 | (group group) | |
740 | (directory "/var/lib/getmail/guix-data-service") | |
741 | (rcfile | |
742 | (getmail-configuration-file | |
743 | (retriever commits-getmail-retriever-configuration) | |
744 | (destination | |
745 | (getmail-destination-configuration | |
746 | (type "MDA_external") | |
747 | (path (file-append | |
748 | package | |
749 | "/bin/guix-data-service-process-branch-updated-email")))) | |
750 | (options | |
751 | (getmail-options-configuration | |
752 | (read-all #f) | |
753 | (delivered-to #f) | |
754 | (received #f))))) | |
755 | (idle getmail-idle-mailboxes)))))) | |
756 | ||
757 | (define guix-data-service-type | |
758 | (service-type | |
759 | (name 'guix-data-service) | |
760 | (extensions | |
761 | (list | |
762 | (service-extension profile-service-type | |
763 | guix-data-service-profile-packages) | |
764 | (service-extension shepherd-root-service-type | |
765 | guix-data-service-shepherd-services) | |
766 | (service-extension activation-service-type | |
767 | guix-data-service-activation) | |
768 | (service-extension account-service-type | |
769 | guix-data-service-account) | |
770 | (service-extension getmail-service-type | |
771 | guix-data-service-getmail-configuration))) | |
772 | (default-value | |
773 | (guix-data-service-configuration)) | |
774 | (description | |
775 | "Run an instance of the Guix Data Service."))) | |
087cdafc CB |
776 | |
777 | \f | |
778 | ;;; | |
779 | ;;; Nar Herder | |
780 | ;;; | |
781 | ||
782 | (define-record-type* <nar-herder-configuration> | |
783 | nar-herder-configuration make-nar-herder-configuration | |
784 | nar-herder-configuration? | |
785 | (package nar-herder-configuration-package | |
786 | (default nar-herder)) | |
787 | (user nar-herder-configuration-user | |
788 | (default "nar-herder")) | |
789 | (group nar-herder-configuration-group | |
790 | (default "nar-herder")) | |
791 | (mirror nar-herder-configuration-mirror | |
792 | (default #f)) | |
793 | (database nar-herder-configuration-database | |
794 | (default "/var/lib/nar-herder/nar_herder.db")) | |
795 | (database-dump nar-herder-configuration-database-dump | |
796 | (default "/var/lib/nar-herder/nar_herder_dump.db")) | |
797 | (host nar-herder-configuration-host | |
798 | (default "127.0.0.1")) | |
799 | (port nar-herder-configuration-port | |
800 | (default 8734)) | |
801 | (storage nar-herder-configuration-storage | |
802 | (default #f)) | |
803 | (storage-limit nar-herder-configuration-storage-limit | |
804 | (default "none")) | |
805 | (storage-nar-removal-criteria | |
806 | nar-herder-configuration-storage-nar-removal-criteria | |
71d2bdfa CB |
807 | (default '())) |
808 | (ttl nar-herder-configuration-ttl | |
809 | (default #f)) | |
810 | (negative-ttl nar-herder-configuration-negative-ttl | |
e32cc011 CB |
811 | (default #f)) |
812 | (log-level nar-herder-configuration-log-level | |
813 | (default 'DEBUG))) | |
71d2bdfa | 814 | |
087cdafc CB |
815 | |
816 | (define (nar-herder-shepherd-services config) | |
817 | (match-record config <nar-herder-configuration> | |
818 | (package user group | |
819 | mirror | |
820 | database database-dump | |
821 | host port | |
71d2bdfa | 822 | storage storage-limit storage-nar-removal-criteria |
e32cc011 | 823 | ttl negative-ttl log-level) |
087cdafc CB |
824 | |
825 | (unless (or mirror storage) | |
826 | (error "nar-herder: mirror or storage must be set")) | |
827 | ||
828 | (list | |
829 | (shepherd-service | |
830 | (documentation "Nar Herder") | |
831 | (provision '(nar-herder)) | |
832 | (requirement '(networking)) | |
833 | (start #~(make-forkexec-constructor | |
834 | (list #$(file-append package | |
835 | "/bin/nar-herder") | |
836 | "run-server" | |
837 | "--pid-file=/var/run/nar-herder/pid" | |
838 | #$(string-append "--port=" (number->string port)) | |
839 | #$(string-append "--host=" host) | |
840 | #$@(if mirror | |
841 | (list (string-append "--mirror=" mirror)) | |
842 | '()) | |
843 | #$(string-append "--database=" database) | |
844 | #$(string-append "--database-dump=" database-dump) | |
845 | #$@(if storage | |
846 | (list (string-append "--storage=" storage)) | |
847 | '()) | |
848 | #$(string-append "--storage-limit=" | |
849 | (if (number? storage-limit) | |
850 | (number->string storage-limit) | |
851 | storage-limit)) | |
852 | #$@(map (lambda (criteria) | |
853 | (string-append | |
854 | "--storage-nar-removal-criteria=" | |
855 | (match criteria | |
856 | ((k . v) (simple-format #f "~A=~A" k v)) | |
857 | (str str)))) | |
71d2bdfa CB |
858 | storage-nar-removal-criteria) |
859 | #$@(if ttl | |
860 | (list (string-append "--ttl=" ttl)) | |
861 | '()) | |
862 | #$@(if negative-ttl | |
863 | (list (string-append "--negative-ttl=" negative-ttl)) | |
e32cc011 CB |
864 | '()) |
865 | #$@(if log-level | |
866 | (list (simple-format #f "--log-level=~A" log-level)) | |
71d2bdfa | 867 | '())) |
087cdafc CB |
868 | #:user #$user |
869 | #:group #$group | |
870 | #:pid-file "/var/run/nar-herder/pid" | |
871 | #:environment-variables | |
872 | `(,(string-append | |
873 | "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale") | |
874 | "LC_ALL=en_US.utf8") | |
875 | #:log-file "/var/log/nar-herder/server.log")) | |
876 | (stop #~(make-kill-destructor)))))) | |
877 | ||
878 | (define (nar-herder-activation config) | |
879 | #~(begin | |
880 | (use-modules (guix build utils)) | |
881 | ||
882 | (define %user | |
883 | (getpw #$(nar-herder-configuration-user | |
884 | config))) | |
885 | ||
886 | (chmod "/var/lib/nar-herder" #o755) | |
887 | ||
888 | (mkdir-p "/var/log/nar-herder") | |
889 | ||
890 | ;; Allow writing the PID file | |
891 | (mkdir-p "/var/run/nar-herder") | |
892 | (chown "/var/run/nar-herder" | |
893 | (passwd:uid %user) | |
894 | (passwd:gid %user)))) | |
895 | ||
896 | (define (nar-herder-account config) | |
897 | (match-record config <nar-herder-configuration> | |
898 | (user group) | |
899 | (list (user-group | |
900 | (name group) | |
901 | (system? #t)) | |
902 | (user-account | |
903 | (name user) | |
904 | (group group) | |
905 | (system? #t) | |
906 | (comment "Nar Herder user") | |
907 | (home-directory "/var/lib/nar-herder") | |
908 | (shell (file-append shadow "/sbin/nologin")))))) | |
909 | ||
910 | (define nar-herder-service-type | |
911 | (service-type | |
912 | (name 'nar-herder) | |
913 | (extensions | |
914 | (list | |
915 | (service-extension shepherd-root-service-type | |
916 | nar-herder-shepherd-services) | |
917 | (service-extension activation-service-type | |
918 | nar-herder-activation) | |
919 | (service-extension account-service-type | |
920 | nar-herder-account))) | |
921 | (description | |
922 | "Run a Nar Herder server."))) |