projects/guix·blob java-team · refs

1306 lines · 54.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <[email protected]>
3;;; Copyright © 2024 Andrew Tropin <[email protected]>
4;;; Copyright © 2025 Edouard Klein <[email protected]>
5;;; Copyright © 2025 Rutherther <[email protected]>
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify
10;;; it under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation, either version 3 of the License, or
12;;; (at your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful,
15;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22(define-module (gnu services guix)
23 #:use-module (srfi srfi-1)
24 #:use-module (ice-9 match)
25 #:use-module (guix gexp)
26 #:use-module (guix records)
27 #:use-module (guix packages)
28 #:use-module ((gnu packages base)
29 #:select (libc-utf8-locales-for-target))
30 #:use-module (gnu packages admin)
31 #:use-module (gnu packages databases)
32 #:use-module (gnu packages web)
33 #:use-module (gnu packages guile)
34 #:use-module (gnu packages guile-xyz)
35 #:use-module (gnu packages package-management)
36 #:use-module (gnu packages file-systems)
37 #:use-module (gnu packages linux)
38 #:use-module (gnu services)
39 #:use-module (gnu services base)
40 #:use-module (gnu services admin)
41 #:use-module (gnu services configuration)
42 #:use-module (gnu services shepherd)
43 #:use-module (gnu services getmail)
44 #:use-module (gnu services linux)
45 #:use-module (gnu system shadow)
46 #:export (guix-build-coordinator-configuration
47 guix-build-coordinator-configuration?
48 guix-build-coordinator-configuration-package
49 guix-build-coordinator-configuration-user
50 guix-build-coordinator-configuration-group
51 guix-build-coordinator-configuration-datastore-uri-string
52 guix-build-coordinator-configuration-agent-communication-uri-string
53 guix-build-coordinator-configuration-client-communication-uri-string
54 guix-build-coordinator-configuration-allocation-strategy
55 guix-build-coordinator-configuration-hooks
56 guix-build-coordinator-configuration-parallel-hooks
57 guix-build-coordinator-configuration-listen-repl
58 guix-build-coordinator-configuration-guile
59 guix-build-coordinator-configuration-extra-environment-variables
60 guix-build-coordinator-configuration-extra-build-coordinator-arguments
61
62 guix-build-coordinator-service-type
63
64 guix-build-coordinator-agent-configuration
65 guix-build-coordinator-agent-configuration?
66 guix-build-coordinator-agent-configuration-package
67 guix-build-coordinator-agent-configuration-user
68 guix-build-coordinator-agent-configuration-coordinator
69 guix-build-coordinator-agent-configuration-authentication
70 guix-build-coordinator-agent-configuration-systems
71 guix-build-coordinator-agent-configuration-max-parallel-builds
72 guix-build-coordinator-agent-configuration-max-parallel-uploads
73 guix-build-coordinator-agent-configuration-max-allocated-builds
74 guix-build-coordinator-agent-configuration-max-1min-load-average
75 guix-build-coordinator-agent-configuration-derivation-substitute-urls
76 guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
77 guix-build-coordinator-agent-configuration-extra-options
78
79 guix-build-coordinator-agent-password-auth
80 guix-build-coordinator-agent-password-auth?
81 guix-build-coordinator-agent-password-auth-uuid
82 guix-build-coordinator-agent-password-auth-password
83
84 guix-build-coordinator-agent-password-file-auth
85 guix-build-coordinator-agent-password-file-auth?
86 guix-build-coordinator-agent-password-file-auth-uuid
87 guix-build-coordinator-agent-password-file-auth-password-file
88
89 guix-build-coordinator-agent-dynamic-auth
90 guix-build-coordinator-agent-dynamic-auth?
91 guix-build-coordinator-agent-dynamic-auth-agent-name
92 guix-build-coordinator-agent-dynamic-auth-token
93
94 guix-build-coordinator-agent-dynamic-auth-with-file
95 guix-build-coordinator-agent-dynamic-auth-with-file?
96 guix-build-coordinator-agent-dynamic-auth-with-file-agent-name
97 guix-build-coordinator-agent-dynamic-auth-with-file-token-file
98
99 guix-build-coordinator-agent-service-type
100
101 <guix-data-service-configuration>
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 guix-data-service-extra-options
112 guix-data-service-extra-process-jobs-options
113 guix-data-service-extra-environment-variables
114 guix-data-service-extra-process-jobs-environment-variables
115 guix-data-service-configuration-git-repositories
116 guix-data-service-configuration-build-servers
117
118 guix-data-service-type
119
120 guix-home-service-type
121
122 nar-herder-service-type
123 nar-herder-configuration
124 nar-herder-configuration?
125 nar-herder-configuration-package
126 nar-herder-configuration-user
127 nar-herder-configuration-group
128 nar-herder-configuration-mirror
129 nar-herder-configuration-database
130 nar-herder-configuration-database-dump
131 nar-herder-configuration-host
132 nar-herder-configuration-port
133 nar-herder-configuration-control-host
134 nar-herder-configuration-control-port
135 nar-herder-configuration-storage
136 nar-herder-configuration-storage-limit
137 nar-herder-configuration-storage-minimum-free-space
138 nar-herder-configuration-storage-nar-removal-criteria
139 nar-herder-configuration-log-level
140 nar-herder-configuration-cached-compressions
141 nar-herder-configuration-cached-compression-min-uses
142 nar-herder-configuration-cached-compression-workers
143 nar-herder-configuration-cached-compression-nar-source
144 nar-herder-configuration-extra-options
145 nar-herder-configuration-extra-environment-variables
146
147 nar-herder-cached-compression-configuration
148 nar-herder-cached-compression-configuration?
149 nar-herder-cached-compression-configuration-type
150 nar-herder-cached-compression-configuration-level
151 nar-herder-cached-compression-configuration-directory
152 nar-herder-cached-compression-configuration-directory-max-size
153
154 bffe-configuration
155 bffe-configuration?
156 bffe-configuration-package
157 bffe-configuration-user
158 bffe-configuration-group
159 bffe-configuration-arguments
160 bffe-configuration-extra-environment-variables
161
162 bffe-service-type
163
164 shared-cache-service-type
165 shared-cache-configuration
166 user-cache))
167
168;;;; Commentary:
169;;;
170;;; Services specifically related to GNU Guix.
171;;;
172;;;; Code:
173
174(define-record-type* <guix-build-coordinator-configuration>
175 guix-build-coordinator-configuration make-guix-build-coordinator-configuration
176 guix-build-coordinator-configuration?
177 (package guix-build-coordinator-configuration-package
178 (default guix-build-coordinator))
179 (user guix-build-coordinator-configuration-user
180 (default "guix-build-coordinator"))
181 (group guix-build-coordinator-configuration-group
182 (default "guix-build-coordinator"))
183 (database-uri-string
184 guix-build-coordinator-configuration-datastore-uri-string
185 (default "sqlite:///var/lib/guix-build-coordinator/guix_build_coordinator.db"))
186 (agent-communication-uri-string
187 guix-build-coordinator-configuration-agent-communication-uri-string
188 (default "http://0.0.0.0:8745"))
189 (client-communication-uri-string
190 guix-build-coordinator-configuration-client-communication-uri-string
191 (default "http://127.0.0.1:8746"))
192 (allocation-strategy
193 guix-build-coordinator-configuration-allocation-strategy
194 (default #~basic-build-allocation-strategy))
195 (hooks guix-build-coordinator-configuration-hooks
196 (default '()))
197 (parallel-hooks guix-build-coordinator-configuration-parallel-hooks
198 (default '()))
199 (listen-repl guix-build-coordinator-configuration-listen-repl
200 (default #f))
201 (guile guix-build-coordinator-configuration-guile
202 (default guile-3.0-latest))
203 (extra-environment-variables
204 guix-build-coordinator-configuration-extra-environment-variables
205 (default '()))
206 (extra-build-coordinator-arguments
207 guix-build-coordinator-configuration-extra-build-coordinator-arguments
208 (default '())))
209
210(define-record-type* <guix-build-coordinator-agent-configuration>
211 guix-build-coordinator-agent-configuration
212 make-guix-build-coordinator-agent-configuration
213 guix-build-coordinator-agent-configuration?
214 (package guix-build-coordinator-agent-configuration-package
215 (default guix-build-coordinator/agent-only))
216 (user guix-build-coordinator-agent-configuration-user
217 (default "guix-build-coordinator-agent"))
218 (coordinator guix-build-coordinator-agent-configuration-coordinator
219 (default "http://localhost:8745"))
220 (authentication guix-build-coordinator-agent-configuration-authentication)
221 (systems guix-build-coordinator-agent-configuration-systems
222 (default #f))
223 (max-parallel-builds
224 guix-build-coordinator-agent-configuration-max-parallel-builds
225 (default #f))
226 (max-parallel-uploads
227 guix-build-coordinator-agent-configuration-max-parallel-uploads
228 (default #f))
229 (max-allocated-builds
230 guix-build-coordinator-agent-configuration-max-allocated-builds
231 (default #f))
232 (max-1min-load-average
233 guix-build-coordinator-agent-configuration-max-1min-load-average
234 (default #f))
235 (derivation-substitute-urls
236 guix-build-coordinator-agent-configuration-derivation-substitute-urls
237 (default #f))
238 (non-derivation-substitute-urls
239 guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
240 (default #f))
241 (extra-options
242 guix-build-coordinator-agent-configuration-extra-options
243 (default '())))
244
245(define-record-type* <guix-build-coordinator-agent-password-auth>
246 guix-build-coordinator-agent-password-auth
247 make-guix-build-coordinator-agent-password-auth
248 guix-build-coordinator-agent-password-auth?
249 (uuid guix-build-coordinator-agent-password-auth-uuid)
250 (password guix-build-coordinator-agent-password-auth-password))
251
252(define-record-type* <guix-build-coordinator-agent-password-file-auth>
253 guix-build-coordinator-agent-password-file-auth
254 make-guix-build-coordinator-agent-password-file-auth
255 guix-build-coordinator-agent-password-file-auth?
256 (uuid guix-build-coordinator-agent-password-file-auth-uuid)
257 (password-file
258 guix-build-coordinator-agent-password-file-auth-password-file))
259
260(define-record-type* <guix-build-coordinator-agent-dynamic-auth>
261 guix-build-coordinator-agent-dynamic-auth
262 make-guix-build-coordinator-agent-dynamic-auth
263 guix-build-coordinator-agent-dynamic-auth?
264 (agent-name guix-build-coordinator-agent-dynamic-auth-agent-name)
265 (token guix-build-coordinator-agent-dynamic-auth-token))
266
267(define-record-type* <guix-build-coordinator-agent-dynamic-auth-with-file>
268 guix-build-coordinator-agent-dynamic-auth-with-file
269 make-guix-build-coordinator-agent-dynamic-auth-with-file
270 guix-build-coordinator-agent-dynamic-auth-with-file?
271 (agent-name guix-build-coordinator-agent-dynamic-auth-with-file-agent-name)
272 (token-file guix-build-coordinator-agent-dynamic-auth-with-file-token-file))
273
274(define* (make-guix-build-coordinator-start-script database-uri-string
275 allocation-strategy
276 pid-file
277 guix-build-coordinator-package
278 #:key
279 agent-communication-uri-string
280 client-communication-uri-string
281 (hooks '())
282 (parallel-hooks '())
283 (guile guile-3.0-latest)
284 listen-repl
285 (extra-build-coordinator-arguments
286 '()))
287 (program-file
288 "start-guix-build-coordinator"
289 (with-extensions (cons guix-build-coordinator-package
290 ;; This is a poorly constructed Guile load path,
291 ;; since it contains things that aren't Guile
292 ;; libraries, but it means that the Guile libraries
293 ;; needed for the Guix Build Coordinator don't need
294 ;; to be individually specified here.
295 (append
296 (map second (package-inputs
297 guix-build-coordinator-package))
298 (map second (package-propagated-inputs
299 guix-build-coordinator-package))))
300 #~(begin
301 (use-modules (srfi srfi-1)
302 (ice-9 match)
303 (web uri)
304 (prometheus)
305 (guix-build-coordinator hooks)
306 (guix-build-coordinator datastore)
307 (guix-build-coordinator build-allocator)
308 (guix-build-coordinator coordinator))
309
310 (simple-format #t "starting the guix-build-coordinator:\n ~A\n"
311 (current-filename))
312 (let* ((hooks
313 (list #$@(map (match-lambda
314 ((name . hook-gexp)
315 #~(cons '#$name #$hook-gexp)))
316 hooks)))
317 (hooks-with-defaults
318 `(,@hooks
319 ,@(remove (match-lambda
320 ((name . _) (assq-ref hooks name)))
321 %default-hooks)))
322 (build-coordinator (make-build-coordinator
323 #:database-uri-string #$database-uri-string
324 #:hooks hooks-with-defaults
325 #:allocation-strategy #$allocation-strategy
326 #:timestamp-log-output? #f
327 #$@extra-build-coordinator-arguments)))
328
329 (run-coordinator-service
330 build-coordinator
331 #:update-datastore? #t
332 #:pid-file #$pid-file
333 #:agent-communication-uri (string->uri
334 #$agent-communication-uri-string)
335 #:client-communication-uri (string->uri
336 #$client-communication-uri-string)
337 #:parallel-hooks (list #$@(map (match-lambda
338 ((name . val)
339 #~(cons '#$name #$val)))
340 parallel-hooks))
341 #:listen-repl #$listen-repl))))
342 #:guile guile))
343
344(define (guix-build-coordinator-shepherd-services config)
345 (match-record config <guix-build-coordinator-configuration>
346 (package user group database-uri-string
347 agent-communication-uri-string
348 client-communication-uri-string
349 allocation-strategy
350 hooks
351 parallel-hooks
352 listen-repl
353 guile
354 extra-environment-variables
355 extra-build-coordinator-arguments)
356 (list
357 (shepherd-service
358 (documentation "Guix Build Coordinator")
359 (provision '(guix-build-coordinator))
360 (requirement '(user-processes networking))
361 (start #~(lambda args
362 (parameterize ((%current-logfile-date-format ""))
363 (apply
364 (make-forkexec-constructor
365 (list #$(make-guix-build-coordinator-start-script
366 database-uri-string
367 allocation-strategy
368 "/var/run/guix-build-coordinator/pid"
369 package
370 #:agent-communication-uri-string
371 agent-communication-uri-string
372 #:client-communication-uri-string
373 client-communication-uri-string
374 #:hooks hooks
375 #:parallel-hooks parallel-hooks
376 #:listen-repl listen-repl
377 #:guile guile
378 #:extra-build-coordinator-arguments
379 extra-build-coordinator-arguments))
380 #:user #$user
381 #:group #$group
382 #:directory "/var/lib/guix-build-coordinator"
383 #:pid-file "/var/run/guix-build-coordinator/pid"
384 ;; Allow time for migrations to run
385 #:pid-file-timeout 240
386 #:environment-variables
387 `("LC_ALL=en_US.utf8"
388 "PATH=/run/current-system/profile/bin" ; for hooks
389 #$@extra-environment-variables)
390 #:log-file "/var/log/guix-build-coordinator/coordinator.log")
391 args))))
392 (stop #~(make-kill-destructor))
393 (modules
394 `((shepherd comm)
395 ,@%default-modules))))))
396
397(define (guix-build-coordinator-activation config)
398 #~(begin
399 (use-modules (guix build utils))
400
401 (define %user
402 (getpw #$(guix-build-coordinator-configuration-user
403 config)))
404
405 (chmod "/var/lib/guix-build-coordinator" #o755)
406
407 (mkdir-p "/var/log/guix-build-coordinator")
408
409 ;; Allow writing the PID file
410 (mkdir-p "/var/run/guix-build-coordinator")
411 (chown "/var/run/guix-build-coordinator"
412 (passwd:uid %user)
413 (passwd:gid %user))))
414
415(define (guix-build-coordinator-account config)
416 (match-record config <guix-build-coordinator-configuration>
417 (user group)
418 (list (user-group
419 (name group)
420 (system? #t))
421 (user-account
422 (name user)
423 (group group)
424 (system? #t)
425 (comment "Guix Build Coordinator user")
426 (home-directory "/var/lib/guix-build-coordinator")
427 (shell (file-append shadow "/sbin/nologin"))))))
428
429(define guix-build-coordinator-service-type
430 (service-type
431 (name 'guix-build-coordinator)
432 (extensions
433 (list
434 (service-extension shepherd-root-service-type
435 guix-build-coordinator-shepherd-services)
436 (service-extension activation-service-type
437 guix-build-coordinator-activation)
438 (service-extension account-service-type
439 guix-build-coordinator-account)))
440 (default-value
441 (guix-build-coordinator-configuration))
442 (description
443 "Run an instance of the Guix Build Coordinator.")))
444
445(define (guix-build-coordinator-agent-shepherd-services config)
446 (match-record config <guix-build-coordinator-agent-configuration>
447 (package user coordinator authentication
448 max-parallel-builds max-parallel-uploads
449 max-allocated-builds max-1min-load-average
450 derivation-substitute-urls non-derivation-substitute-urls
451 extra-options
452 systems)
453 (list
454 (shepherd-service
455 (documentation "Guix Build Coordinator Agent")
456 (provision '(guix-build-coordinator-agent))
457 (requirement '(networking user-processes))
458 (start
459 #~(lambda _
460 (parameterize ((%current-logfile-date-format ""))
461 (fork+exec-command
462 (list #$(file-append package "/bin/guix-build-coordinator-agent")
463 #$(string-append "--coordinator=" coordinator)
464 "--timestamp-log-output=false"
465 #$@(match authentication
466 (($ <guix-build-coordinator-agent-password-auth>
467 uuid password)
468 #~(#$(string-append "--uuid=" uuid)
469 #$(string-append "--password=" password)))
470 (($ <guix-build-coordinator-agent-password-file-auth>
471 uuid password-file)
472 #~(#$(string-append "--uuid=" uuid)
473 #$(string-append "--password-file="
474 password-file)))
475 (($ <guix-build-coordinator-agent-dynamic-auth>
476 agent-name token)
477 #~(#$(string-append "--name=" agent-name)
478 #$(string-append "--dynamic-auth-token=" token)))
479 (($
480 <guix-build-coordinator-agent-dynamic-auth-with-file>
481 agent-name token-file)
482 #~(#$(string-append "--name=" agent-name)
483 #$(string-append "--dynamic-auth-token-file="
484 token-file))))
485 #$@(if max-parallel-builds
486 #~(#$(simple-format #f "--max-parallel-builds=~A"
487 max-parallel-builds))
488 #~())
489 #$@(if max-parallel-uploads
490 #~(#$(simple-format #f "--max-parallel-uploads=~A"
491 max-parallel-uploads))
492 #~())
493 #$@(if max-allocated-builds
494 #~(#$(simple-format #f "--max-allocated-builds=~A"
495 max-allocated-builds))
496 #~())
497 #$@(if max-1min-load-average
498 #~(#$(simple-format #f "--max-1min-load-average=~A"
499 max-1min-load-average))
500 #~())
501 #$@(if derivation-substitute-urls
502 #~(#$(string-append
503 "--derivation-substitute-urls="
504 (string-join derivation-substitute-urls " ")))
505 #~())
506 #$@(if non-derivation-substitute-urls
507 #~(#$(string-append
508 "--non-derivation-substitute-urls="
509 (string-join non-derivation-substitute-urls " ")))
510 #~())
511 #$@extra-options
512 #$@(map (lambda (system)
513 (string-append "--system=" system))
514 (or systems '())))
515 #:user #$user
516 #:environment-variables
517 `(;; XDG_CACHE_HOME is used by Guix when caching narinfo files
518 "XDG_CACHE_HOME=/var/cache/guix-build-coordinator-agent"
519 "LC_ALL=en_US.utf8")
520 ;; Run from the log directory so core dumps can be written
521 #:directory "/var/log/guix-build-coordinator"
522 #:log-file "/var/log/guix-build-coordinator/agent.log"))))
523 (stop #~(make-kill-destructor))
524 (modules
525 `((shepherd comm)
526 ,@%default-modules))))))
527
528(define (guix-build-coordinator-agent-activation config)
529 #~(begin
530 (use-modules (guix build utils))
531
532 (define %user
533 (getpw #$(guix-build-coordinator-agent-configuration-user
534 config)))
535
536 (mkdir-p "/var/log/guix-build-coordinator")
537
538 ;; Create a cache directory for storing narinfo files if downloaded
539 (mkdir-p "/var/cache/guix-build-coordinator-agent")
540 (chown "/var/cache/guix-build-coordinator-agent"
541 (passwd:uid %user)
542 (passwd:gid %user))))
543
544(define (guix-build-coordinator-agent-account config)
545 (list (user-account
546 (name (guix-build-coordinator-agent-configuration-user config))
547 (group "nogroup")
548 (system? #t)
549 (comment "Guix Build Coordinator agent user")
550 (home-directory "/var/empty")
551 (shell (file-append shadow "/sbin/nologin")))))
552
553(define guix-build-coordinator-agent-service-type
554 (service-type
555 (name 'guix-build-coordinator-agent)
556 (extensions
557 (list
558 (service-extension shepherd-root-service-type
559 guix-build-coordinator-agent-shepherd-services)
560 (service-extension activation-service-type
561 guix-build-coordinator-agent-activation)
562 (service-extension account-service-type
563 guix-build-coordinator-agent-account)))
564 (description
565 "Run a Guix Build Coordinator agent.")))
566
567
568;;;
569;;; Guix Data Service
570;;;
571
572(define-record-type* <guix-data-service-configuration>
573 guix-data-service-configuration make-guix-data-service-configuration
574 guix-data-service-configuration?
575 (package guix-data-service-package
576 (default guix-data-service))
577 (user guix-data-service-configuration-user
578 (default "guix-data-service"))
579 (group guix-data-service-configuration-group
580 (default "guix-data-service"))
581 (port guix-data-service-port
582 (default 8765))
583 (host guix-data-service-host
584 (default "127.0.0.1"))
585 (getmail-idle-mailboxes
586 guix-data-service-getmail-idle-mailboxes
587 (default #f))
588 (commits-getmail-retriever-configuration
589 guix-data-service-commits-getmail-retriever-configuration
590 (default #f))
591 (extra-options guix-data-service-extra-options
592 (default '()))
593 (extra-process-jobs-options
594 guix-data-service-extra-process-jobs-options
595 (default '()))
596 (extra-environment-variables
597 guix-data-service-extra-environment-variables
598 (default '()))
599 (extra-process-jobs-environment-variables
600 guix-data-service-extra-process-jobs-environment-variables
601 (default '()))
602 (git-repositories guix-data-service-configuration-git-repositories
603 (default #f))
604 (build-servers guix-data-service-configuration-build-servers
605 (default #f)))
606
607(define (guix-data-service-profile-packages config)
608 "Return the guix-data-service package, this will populate the
609ca-certificates.crt file in the system profile."
610 (list
611 (guix-data-service-package config)))
612
613(define (guix-data-service-shepherd-services config)
614 (match-record config <guix-data-service-configuration>
615 (package user group port host extra-options extra-process-jobs-options
616 extra-environment-variables
617 extra-process-jobs-environment-variables
618 git-repositories build-servers)
619 (list
620 (shepherd-service
621 (documentation "Guix Data Service web server")
622 (provision '(guix-data-service))
623 (requirement '(user-processes postgres networking))
624 (start #~(make-forkexec-constructor
625 (list #$(file-append package
626 "/bin/guix-data-service")
627 "--pid-file=/var/run/guix-data-service/pid"
628 #$(string-append "--port=" (number->string port))
629 #$(string-append "--host=" host)
630 ;; Perform any database migrations when the
631 ;; service is started
632 "--update-database"
633 #$@extra-options)
634
635 #:user #$user
636 #:group #$group
637 #:directory "/var/lib/guix-data-service"
638 #:pid-file "/var/run/guix-data-service/pid"
639 #:environment-variables
640 `(,(string-append
641 "GUIX_LOCPATH="
642 #$(libc-utf8-locales-for-target) "/lib/locale")
643 "LC_ALL=en_US.UTF-8"
644 #$@extra-environment-variables)
645 #:log-file "/var/log/guix-data-service/web.log"))
646 (stop #~(make-kill-destructor)))
647
648 (shepherd-service
649 (documentation "Guix Data Service setup database")
650 (provision '(guix-data-service-setup-database))
651 (requirement '(user-processes postgres))
652 (one-shot? #t)
653 (start
654 #~(make-forkexec-constructor
655 (list
656 #$(program-file
657 "data-service-setup-database"
658 (with-extensions
659 (cons package
660 ;; This is a poorly constructed Guile load path, since
661 ;; it contains things that aren't Guile libraries, but
662 ;; it means that the Guile libraries needed for the
663 ;; Guix Data Service don't need to be individually
664 ;; specified here.
665 (append
666 (map second (package-inputs package))
667 (map second (package-propagated-inputs package))))
668 #~(begin
669 (use-modules (guix-data-service database)
670 (guix-data-service model git-repository)
671 (guix-data-service model build-server))
672
673 (simple-format #t "data-service-setup-database: ~A\n"
674 (current-filename))
675 (begin
676 ((@ (guix-data-service database) run-sqitch))
677
678 #$@(if git-repositories
679 #~(((@ (guix-data-service model git-repository)
680 specify-git-repositories)
681 '(#$@git-repositories)))
682 '())
683 #$@(if build-servers
684 #~(((@ (guix-data-service model build-server)
685 specify-build-servers)
686 '(#$@build-servers)))
687 '()))))
688 #:guile (lookup-package-input package "guile")))
689 #:user #$user
690 #:group #$group
691 #:directory "/var/lib/guix-data-service"
692 #:environment-variables
693 `(,(string-append
694 "GUIX_LOCPATH="
695 #$(libc-utf8-locales-for-target) "/lib/locale")
696 "LC_ALL=en_US.utf8"
697 #$@extra-environment-variables)
698 #:log-file "/var/log/guix-data-service/setup-database.log"))
699 (auto-start? #t))
700
701 (shepherd-service
702 (documentation "Guix Data Service process jobs")
703 (provision '(guix-data-service-process-jobs))
704 (requirement '(user-processes postgres networking))
705 (start #~(make-forkexec-constructor
706 (list
707 #$(file-append package
708 "/bin/guix-data-service-process-jobs")
709 #$@extra-process-jobs-options)
710 #:user #$user
711 #:group #$group
712 #:directory "/var/lib/guix-data-service"
713 #:environment-variables
714 `("HOME=/var/lib/guix-data-service"
715 "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
716 ,(string-append
717 "GUIX_LOCPATH="
718 #$(libc-utf8-locales-for-target) "/lib/locale")
719 "LC_ALL=en_US.UTF-8"
720 #$@extra-process-jobs-environment-variables)
721 #:log-file "/var/log/guix-data-service/process-jobs.log"))
722 (stop #~(make-kill-destructor))))))
723
724(define (guix-data-service-activation config)
725 #~(begin
726 (use-modules (guix build utils))
727
728 (define %user (getpw "guix-data-service"))
729
730 (chmod "/var/lib/guix-data-service" #o755)
731
732 (mkdir-p "/var/log/guix-data-service")
733
734 ;; Allow writing the PID file
735 (mkdir-p "/var/run/guix-data-service")
736 (chown "/var/run/guix-data-service"
737 (passwd:uid %user)
738 (passwd:gid %user))))
739
740(define (guix-data-service-account config)
741 (match-record config <guix-data-service-configuration>
742 (user group)
743 (list (user-group
744 (name group)
745 (system? #t))
746 (user-account
747 (name user)
748 (group group)
749 (system? #t)
750 (comment "Guix Data Service user")
751 (home-directory "/var/lib/guix-data-service")
752 (shell (file-append shadow "/sbin/nologin"))))))
753
754(define (guix-data-service-getmail-configuration config)
755 (match config
756 (($ <guix-data-service-configuration> package user group
757 port host
758 #f #f)
759 '())
760 (($ <guix-data-service-configuration> package user group
761 port host
762 getmail-idle-mailboxes
763 commits-getmail-retriever-configuration)
764 (list
765 (getmail-configuration
766 (name 'guix-data-service)
767 (user user)
768 (group group)
769 (directory "/var/lib/getmail/guix-data-service")
770 (rcfile
771 (getmail-configuration-file
772 (retriever commits-getmail-retriever-configuration)
773 (destination
774 (getmail-destination-configuration
775 (type "MDA_external")
776 (path (file-append
777 package
778 "/bin/guix-data-service-process-branch-updated-email"))))
779 (options
780 (getmail-options-configuration
781 (read-all #f)
782 (delivered-to #f)
783 (received #f)))))
784 (idle getmail-idle-mailboxes))))))
785
786(define guix-data-service-type
787 (service-type
788 (name 'guix-data-service)
789 (extensions
790 (list
791 (service-extension profile-service-type
792 guix-data-service-profile-packages)
793 (service-extension shepherd-root-service-type
794 guix-data-service-shepherd-services)
795 (service-extension activation-service-type
796 guix-data-service-activation)
797 (service-extension account-service-type
798 guix-data-service-account)
799 (service-extension getmail-service-type
800 guix-data-service-getmail-configuration)))
801 (default-value
802 (guix-data-service-configuration))
803 (description
804 "Run an instance of the Guix Data Service.")))
805
806
807;;;
808;;; Guix Home Service
809;;;
810
811(define (guix-home-shepherd-service config)
812 (map (match-lambda
813 ((user he)
814 (shepherd-service
815 (documentation "Activate Guix Home.")
816 (requirement '(user-processes))
817 (provision (list (symbol-append 'guix-home- (string->symbol user))))
818 (one-shot? #t)
819 (auto-start? #t)
820 (start #~(make-forkexec-constructor
821 '(#$(file-append he "/activate"))
822 #:user #$user
823 #:environment-variables
824 (list (string-append "HOME=" (passwd:dir (getpw #$user)))
825 "GUIX_SYSTEM_IS_RUNNING_HOME_ACTIVATE=t")
826 #:group (group:name (getgrgid (passwd:gid (getpw #$user))))))
827 (stop #~(make-kill-destructor)))))
828 config))
829
830(define guix-home-service-type
831 (service-type
832 (name 'guix-home)
833 (description "Sets up Guix Home for the specified user accounts.")
834 (extensions (list (service-extension
835 shepherd-root-service-type
836 guix-home-shepherd-service)))
837 (compose concatenate)
838 (extend append)
839 (default-value '())))
840
841
842;;;
843;;; Nar Herder
844;;;
845
846(define-record-type* <nar-herder-configuration>
847 nar-herder-configuration make-nar-herder-configuration
848 nar-herder-configuration?
849 (package nar-herder-configuration-package
850 (default nar-herder))
851 (user nar-herder-configuration-user
852 (default "nar-herder"))
853 (group nar-herder-configuration-group
854 (default "nar-herder"))
855 (mirror nar-herder-configuration-mirror
856 (default #f))
857 (database nar-herder-configuration-database
858 (default "/var/lib/nar-herder/nar_herder.db"))
859 (database-dump nar-herder-configuration-database-dump
860 (default "/var/lib/nar-herder/nar_herder_dump.db"))
861 (host nar-herder-configuration-host
862 (default "127.0.0.1"))
863 (port nar-herder-configuration-port
864 (default 8734))
865 (control-host nar-herder-configuration-control-host
866 (default "127.0.0.1"))
867 (control-port nar-herder-configuration-control-port
868 (default 8735))
869 (storage nar-herder-configuration-storage
870 (default #f))
871 (storage-limit nar-herder-configuration-storage-limit
872 (default "none"))
873 (storage-minimum-free-space
874 nar-herder-configuration-storage-minimum-free-space
875 (default "none"))
876 (storage-nar-removal-criteria
877 nar-herder-configuration-storage-nar-removal-criteria
878 (default '()))
879 (ttl nar-herder-configuration-ttl
880 (default #f))
881 (new-ttl nar-herder-configuration-new-ttl
882 (default #f))
883 (negative-ttl nar-herder-configuration-negative-ttl
884 (default #f))
885 (log-level nar-herder-configuration-log-level
886 (default 'DEBUG))
887 (cached-compressions
888 nar-herder-configuration-cached-compressions
889 (default '()))
890 (cached-compression-min-uses
891 nar-herder-configuration-cached-compression-min-uses
892 (default 3))
893 (cached-compression-workers
894 nar-herder-configuration-cached-compression-workers
895 (default 2))
896 (cached-compression-nar-source
897 nar-herder-configuration-cached-compression-nar-source
898 (default #f))
899 (extra-options
900 nar-herder-configuration-extra-options
901 (default '()))
902 (extra-environment-variables
903 nar-herder-configuration-extra-environment-variables
904 (default '())))
905
906(define-record-type* <nar-herder-cached-compression-configuration>
907 nar-herder-cached-compression-configuration
908 make-nar-herder-cached-compression-configuration
909 nar-herder-cached-compression-configuration?
910 (type nar-herder-cached-compression-configuration-type)
911 (level nar-herder-cached-compression-configuration-level
912 (default #f))
913 (directory nar-herder-cached-compression-configuration-directory
914 (default #f))
915 (directory-max-size
916 nar-herder-cached-compression-configuration-directory-max-size
917 (default #f))
918 (unused-removal-duration
919 nar-herder-cached-compression-configuration-unused-removal-duration
920 (default #f))
921 (ttl nar-herder-cached-compression-configuration-ttl
922 (default #f))
923 (new-ttl nar-herder-cached-compression-configuration-new-ttl
924 (default #f)))
925
926(define (nar-herder-shepherd-services config)
927 (define (cached-compression-configuration->options cached-compression)
928 (match-record
929 cached-compression
930 <nar-herder-cached-compression-configuration>
931 (type level directory directory-max-size
932 unused-removal-duration ttl new-ttl)
933
934 `(,(simple-format #f "--enable-cached-compression=~A~A"
935 type
936 (if level
937 (simple-format #f ":~A" level)
938 ""))
939 ,@(if directory
940 (list
941 (simple-format #f "--cached-compression-directory=~A=~A"
942 type
943 directory))
944 '())
945 ,@(if directory-max-size
946 (list
947 (simple-format #f "--cached-compression-directory-max-size=~A=~A"
948 type
949 directory-max-size))
950 '())
951 ,@(if unused-removal-duration
952 (list
953 (simple-format
954 #f "--cached-compression-unused-removal-duration=~A=~A"
955 type
956 unused-removal-duration))
957 '())
958 ,@(if ttl
959 (list
960 (simple-format
961 #f "--cached-compression-ttl=~A=~A"
962 type
963 ttl))
964 '())
965 ,@(if new-ttl
966 (list
967 (simple-format
968 #f "--cached-compression-new-ttl=~A=~A"
969 type
970 new-ttl))
971 '()))))
972
973 (match-record config <nar-herder-configuration>
974 (package user group
975 mirror
976 database database-dump
977 host port
978 control-host control-port
979 storage storage-limit storage-minimum-free-space
980 storage-nar-removal-criteria
981 ttl new-ttl negative-ttl log-level
982 cached-compressions cached-compression-min-uses
983 cached-compression-workers cached-compression-nar-source
984 extra-options
985 extra-environment-variables)
986
987 (unless (or mirror storage)
988 (error "nar-herder: mirror or storage must be set"))
989
990 (list
991 (shepherd-service
992 (documentation "Nar Herder")
993 (provision '(nar-herder))
994 (requirement '(user-processes networking))
995 (start #~(make-forkexec-constructor
996 (list #$(file-append package
997 "/bin/nar-herder")
998 "run-server"
999 "--pid-file=/var/run/nar-herder/pid"
1000 #$(string-append "--port=" (number->string port))
1001 #$(string-append "--host=" host)
1002 #$(string-append "--control-port="
1003 (number->string control-port))
1004 #$(string-append "--control-host="
1005 control-host)
1006 #$@(if mirror
1007 (list (string-append "--mirror=" mirror))
1008 '())
1009 #$(string-append "--database=" database)
1010 #$(string-append "--database-dump=" database-dump)
1011 #$@(if storage
1012 (list (string-append "--storage=" storage))
1013 '())
1014 #$(string-append "--storage-limit="
1015 (if (number? storage-limit)
1016 (number->string storage-limit)
1017 storage-limit))
1018 #$(string-append
1019 "--storage-minimum-free-space="
1020 (if (number? storage-minimum-free-space)
1021 (number->string storage-minimum-free-space)
1022 storage-minimum-free-space))
1023 #$@(map (lambda (criteria)
1024 (string-append
1025 "--storage-nar-removal-criteria="
1026 (match criteria
1027 ((k . v) (simple-format #f "~A=~A" k v))
1028 (str str))))
1029 storage-nar-removal-criteria)
1030 #$@(if ttl
1031 (list (string-append "--ttl=" ttl))
1032 '())
1033 #$@(if new-ttl
1034 (list (string-append "--new-ttl=" new-ttl))
1035 '())
1036 #$@(if negative-ttl
1037 (list (string-append "--negative-ttl=" negative-ttl))
1038 '())
1039 #$@(if log-level
1040 (list (simple-format #f "--log-level=~A" log-level))
1041 '())
1042 #$@(append-map
1043 cached-compression-configuration->options
1044 cached-compressions)
1045 #$@(if cached-compression-min-uses
1046 (list (simple-format
1047 #f "--cached-compression-min-uses=~A"
1048 cached-compression-min-uses))
1049 '())
1050 #$@(if cached-compression-workers
1051 (list (simple-format
1052 #f "--cached-compression-workers=~A"
1053 cached-compression-workers))
1054 '())
1055 #$@(if cached-compression-nar-source
1056 (list (simple-format
1057 #f "--cached-compression-nar-source=~A"
1058 cached-compression-nar-source))
1059 '())
1060 #$@extra-options)
1061 #:user #$user
1062 #:group #$group
1063 #:directory "/var/lib/nar-herder"
1064 #:pid-file "/var/run/nar-herder/pid"
1065 #:environment-variables
1066 `(,(string-append
1067 "GUIX_LOCPATH="
1068 #$(libc-utf8-locales-for-target) "/lib/locale")
1069 "LC_ALL=en_US.utf8"
1070 #$@extra-environment-variables)
1071 #:log-file "/var/log/nar-herder/server.log"))
1072 (stop #~(make-kill-destructor))))))
1073
1074(define (nar-herder-activation config)
1075 #~(begin
1076 (use-modules (guix build utils))
1077
1078 (define %user
1079 (getpw #$(nar-herder-configuration-user
1080 config)))
1081
1082 (chmod "/var/lib/nar-herder" #o755)
1083
1084 (mkdir-p "/var/log/nar-herder")
1085
1086 ;; Allow writing the PID file
1087 (mkdir-p "/var/run/nar-herder")
1088 (chown "/var/run/nar-herder"
1089 (passwd:uid %user)
1090 (passwd:gid %user))))
1091
1092(define (nar-herder-account config)
1093 (match-record config <nar-herder-configuration>
1094 (user group)
1095 (list (user-group
1096 (name group)
1097 (system? #t))
1098 (user-account
1099 (name user)
1100 (group group)
1101 (system? #t)
1102 (comment "Nar Herder user")
1103 (home-directory "/var/lib/nar-herder")
1104 (shell (file-append shadow "/sbin/nologin"))))))
1105
1106(define nar-herder-service-type
1107 (service-type
1108 (name 'nar-herder)
1109 (extensions
1110 (list
1111 (service-extension shepherd-root-service-type
1112 nar-herder-shepherd-services)
1113 (service-extension activation-service-type
1114 nar-herder-activation)
1115 (service-extension account-service-type
1116 nar-herder-account)))
1117 (description
1118 "Run a Nar Herder server.")))
1119
1120
1121;;;
1122;;; Build Farm Front-end (BFFE)
1123;;;
1124
1125(define-record-type* <bffe-configuration>
1126 bffe-configuration make-bffe-configuration
1127 bffe-configuration?
1128 (package bffe-configuration-package
1129 (default bffe))
1130 (user bffe-configuration-user
1131 (default "bffe"))
1132 (group bffe-configuration-group
1133 (default "bffe"))
1134 (arguments bffe-configuration-arguments)
1135 (extra-environment-variables
1136 bffe-configuration-extra-environment-variables
1137 (default '())))
1138
1139(define (bffe-shepherd-services config)
1140 (define bffe-package
1141 (bffe-configuration-package config))
1142
1143 (define start-script
1144 (program-file
1145 "run-bffe"
1146 (with-extensions (cons
1147 bffe-package
1148 ;; This is a poorly constructed Guile load path,
1149 ;; since it contains things that aren't Guile
1150 ;; libraries, but it means that the Guile
1151 ;; libraries needed for BFFE don't need to be
1152 ;; individually specified here.
1153 (map second (package-transitive-propagated-inputs
1154 bffe-package)))
1155 #~(begin
1156 (use-modules (bffe)
1157 (bffe manage-builds))
1158
1159 (simple-format #t "starting the bffe:\n ~A\n"
1160 (current-filename))
1161
1162 (apply run-bffe-service
1163 (append
1164 (list #:pid-file "/var/run/bffe/pid")
1165 #$(bffe-configuration-arguments config)))))
1166 #:guile (lookup-package-native-input bffe-package "guile")))
1167
1168 (match-record config <bffe-configuration>
1169 (package user group arguments extra-environment-variables)
1170
1171 (list
1172 (shepherd-service
1173 (documentation "Build Farm Front-end")
1174 (provision '(bffe))
1175 (requirement '(user-processes networking))
1176 (start #~(make-forkexec-constructor
1177 (list #$start-script)
1178 #:user #$user
1179 #:group #$group
1180 #:pid-file "/var/run/bffe/pid"
1181 #:directory "/var/lib/bffe"
1182 #:environment-variables
1183 `(,(string-append
1184 "GUIX_LOCPATH="
1185 #$(libc-utf8-locales-for-target) "/lib/locale")
1186 "LC_ALL=en_US.utf8"
1187 #$@extra-environment-variables)
1188 #:log-file "/var/log/bffe/server.log"))
1189 (stop #~(make-kill-destructor))))))
1190
1191(define (bffe-activation config)
1192 #~(begin
1193 (use-modules (guix build utils))
1194
1195 (define %user
1196 (getpw #$(bffe-configuration-user config)))
1197
1198 (chmod "/var/lib/bffe" #o755)
1199
1200 (mkdir-p "/var/log/bffe")
1201
1202 ;; Allow writing the PID file
1203 (mkdir-p "/var/run/bffe")
1204 (chown "/var/run/bffe" (passwd:uid %user) (passwd:gid %user))))
1205
1206(define (bffe-account config)
1207 (match-record config <bffe-configuration>
1208 (user group)
1209 (list (user-group
1210 (name group)
1211 (system? #t))
1212 (user-account
1213 (name user)
1214 (group group)
1215 (system? #t)
1216 (comment "BFFE user")
1217 (home-directory "/var/lib/bffe")
1218 (shell (file-append shadow "/sbin/nologin"))))))
1219
1220(define bffe-service-type
1221 (service-type
1222 (name 'bffe)
1223 (extensions
1224 (list (service-extension shepherd-root-service-type
1225 bffe-shepherd-services)
1226 (service-extension activation-service-type
1227 bffe-activation)
1228 (service-extension account-service-type
1229 bffe-account)))
1230 (description
1231 "Run the Build Farm Front-end.")))
1232
1233;;;
1234;;; Share .cache/ content between users
1235;;;
1236;;; On a system with multiple users, each $HOME/.cache/guix is
1237;;; ~700MB of data that is mostly the same between users. This service allows
1238;;; one to either:
1239;;
1240;;; - share this cache between users, with updates shared between users, which
1241;;; is suitable for a high trust environment, typically a single human user
1242;;; with multiple accounts on the same computer
1243;;;
1244;;; - or expose a single user's cache, read-only with a write overlay, to the
1245;;; other users, typically used in low-trust environments such as a public
1246;;; access guix system.
1247
1248(define-record-type* <user-cache>
1249 user-cache make-user-cache
1250 user-cache?
1251 (user user-cache-user)
1252 (location user-cache-location (default (string-append "/home/" (user-cache-user this-record) "/.cache")) (thunked))
1253 (group user-cache-group (default "users"))
1254 (directories user-cache-directories (default '("guix/checkouts"))))
1255
1256(define list-of-user-cache? (list-of user-cache?))
1257
1258(define (mount-type? x)
1259 (and (symbol? x)
1260 (or (eq? x 'share)
1261 (eq? x 'expose))))
1262
1263(define-configuration/no-serialization shared-cache-configuration
1264 (mode (mount-type 'expose) "Either 'share (read-write, dangerous) or 'expose (read-only, the default) the cache directory.")
1265 (shared-directory (string "/root/.cache") "The sharing user's cache directory (i.e. the source).")
1266 (users (list-of-user-cache '()) "The users that benefit from the shared directory. This is a list of user-cache records (i.e. the destinations)."))
1267
1268(define shared-cache-vfs-mappings
1269 (match-record-lambda <shared-cache-configuration>
1270 (mode shared-directory users)
1271 (apply
1272 append
1273 (map
1274 (match-record-lambda <user-cache>
1275 (location user group directories)
1276 (map
1277 (lambda (subdir)
1278 (vfs-mapping
1279 ;; Each subdir has its own service
1280 (name (string-append "shared-cache-" subdir "-" user))
1281 ;; Make sure the homes are already present
1282 (requirement '(file-systems user-file-systems user-homes))
1283 ;; Mount each shared dir over the target dir in the users' .cache/
1284 (source (string-append shared-directory "/" subdir))
1285 (destination (string-append location "/" subdir))
1286 (policy (match mode
1287 ('expose 'overlay)
1288 ('share 'translate)))
1289 (user user)
1290 (group group)))
1291 directories))
1292 users))))
1293
1294(define shared-cache-service-type
1295 (service-type
1296 (name 'shared-cache)
1297 (extensions (list
1298 (service-extension vfs-mapping-service-type
1299 shared-cache-vfs-mappings)))
1300 (compose concatenate)
1301 (extend (lambda (original extensions)
1302 (shared-cache-configuration
1303 (inherit original)
1304 (users (append (shared-cache-configuration-users original) extensions)))))
1305 (default-value (shared-cache-configuration))
1306 (description "Share or expose ~/.cache/ sub directories between multiple users.")))