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