gnu: python-imap-tools: Update to 0.29.0.
[jackhill/guix/guix.git] / gnu / services / base.scm
CommitLineData
db4fdc04 1;;; GNU Guix --- Functional package management for GNU
24a4a635 2;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
34044d55 3;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
5f4a446d 4;;; Copyright © 2015, 2016 Mark H Weaver <mhw@netris.org>
e10964ef 5;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
93d32da9 6;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
b58cbf9a 7;;; Copyright © 2016 David Craven <david@craven.ch>
909147e4 8;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
2d9dace8 9;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
db903549 10;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
a9162155 11;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
74a98b5c 12;;; Copyright © 2019 John Soo <jsoo1@asu.edu>
022ad24c 13;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
00500449 14;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
2b0c0d93 15;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
db4fdc04
LC
16;;;
17;;; This file is part of GNU Guix.
18;;;
19;;; GNU Guix is free software; you can redistribute it and/or modify it
20;;; under the terms of the GNU General Public License as published by
21;;; the Free Software Foundation; either version 3 of the License, or (at
22;;; your option) any later version.
23;;;
24;;; GNU Guix is distributed in the hope that it will be useful, but
25;;; WITHOUT ANY WARRANTY; without even the implied warranty of
26;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27;;; GNU General Public License for more details.
28;;;
29;;; You should have received a copy of the GNU General Public License
30;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
31
32(define-module (gnu services base)
e87f0591 33 #:use-module (guix store)
65a67bf7 34 #:use-module (guix deprecation)
db4fdc04 35 #:use-module (gnu services)
4252dace 36 #:use-module (gnu services admin)
0190c1c0 37 #:use-module (gnu services shepherd)
6e828634 38 #:use-module (gnu system pam)
db4fdc04 39 #:use-module (gnu system shadow) ; 'user-account', etc.
d1ff5f9d 40 #:use-module (gnu system uuid)
0adfe95a 41 #:use-module (gnu system file-systems) ; 'file-system', etc.
060d62a7 42 #:use-module (gnu system mapped-devices)
278d486b
LC
43 #:use-module ((gnu system linux-initrd)
44 #:select (file-system-packages))
db4fdc04 45 #:use-module (gnu packages admin)
151a2c07 46 #:use-module ((gnu packages linux)
b58cbf9a 47 #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools))
3fe53f49 48 #:use-module (gnu packages bash)
a9162155 49 #:use-module ((gnu packages base)
dfc8ccbf 50 #:select (coreutils glibc glibc-utf8-locales))
db4fdc04 51 #:use-module (gnu packages package-management)
8b3ad455 52 #:use-module ((gnu packages gnupg) #:select (guile-gcrypt))
9ee4c9ab 53 #:use-module (gnu packages linux)
46ec2707 54 #:use-module (gnu packages terminals)
e2f4b305 55 #:use-module ((gnu build file-systems)
2c071ce9 56 #:select (mount-flags->bit-mask))
b5f4e686 57 #:use-module (guix gexp)
6454b333 58 #:use-module (guix records)
943e1b97 59 #:use-module (guix modules)
8b3ad455 60 #:use-module ((guix self) #:select (make-config.scm))
db4fdc04
LC
61 #:use-module (srfi srfi-1)
62 #:use-module (srfi srfi-26)
6454b333 63 #:use-module (ice-9 match)
db4fdc04 64 #:use-module (ice-9 format)
10c41368 65 #:re-export (user-processes-service-type) ;backwards compatibility
e43e84ba
LC
66 #:export (fstab-service-type
67 root-file-system-service
aa1145df 68 file-system-service-type
2a13d05e 69 swap-service
a00dd9fb 70 host-name-service
5eca9459 71 console-keymap-service
4a84a487
LC
72 %default-console-font
73 console-font-service-type
62ca0fdf 74 console-font-service
bb3062ad 75 virtual-terminal-service-type
c797fabe 76
c9436025
DM
77 static-networking
78
79 static-networking?
80 static-networking-interface
81 static-networking-ip
82 static-networking-netmask
83 static-networking-gateway
84 static-networking-requirement
85
86 static-networking-service
87 static-networking-service-type
88
c797fabe
RW
89 udev-configuration
90 udev-configuration?
91 udev-configuration-rules
0adfe95a 92 udev-service-type
151a2c07 93 udev-service
80e6f37e 94 udev-rule
6e644cfd 95 file->udev-rule
2b0c0d93 96 udev-rules-service
66e4f01c 97
317d3b47
DC
98 login-configuration
99 login-configuration?
100 login-service-type
101 login-service
102
9ee4c9ab
LF
103 agetty-configuration
104 agetty-configuration?
105 agetty-service
106 agetty-service-type
107
66e4f01c
LC
108 mingetty-configuration
109 mingetty-configuration?
db4fdc04 110 mingetty-service
cd6f6c22 111 mingetty-service-type
6454b333
LC
112
113 %nscd-default-caches
114 %nscd-default-configuration
115
116 nscd-configuration
117 nscd-configuration?
118
119 nscd-cache
120 nscd-cache?
121
0adfe95a 122 nscd-service-type
db4fdc04 123 nscd-service
ec2e2f6c
DC
124
125 syslog-configuration
126 syslog-configuration?
db4fdc04 127 syslog-service
9009538d 128 syslog-service-type
44abcb28 129 %default-syslog.conf
0adfe95a 130
5b58c28b 131 %default-authorized-guix-keys
0adfe95a
LC
132 guix-configuration
133 guix-configuration?
70dfa4e0
MO
134
135 guix-configuration-guix
136 guix-configuration-build-group
137 guix-configuration-build-accounts
138 guix-configuration-authorize-key?
139 guix-configuration-authorized-keys
140 guix-configuration-use-substitutes?
141 guix-configuration-substitute-urls
142 guix-configuration-extra-options
143 guix-configuration-log-file
70dfa4e0 144
8b198abe 145 guix-service
cd6f6c22 146 guix-service-type
1c52181f
LC
147 guix-publish-configuration
148 guix-publish-configuration?
f1e900a3
LC
149 guix-publish-configuration-guix
150 guix-publish-configuration-port
151 guix-publish-configuration-host
ee2691fa
LC
152 guix-publish-configuration-compression
153 guix-publish-configuration-compression-level ;deprecated
697ddb88 154 guix-publish-configuration-nar-path
a35136cb
LC
155 guix-publish-configuration-cache
156 guix-publish-configuration-ttl
1c52181f
LC
157 guix-publish-service
158 guix-publish-service-type
24e96431
159
160 gpm-configuration
161 gpm-configuration?
8664cc88
LC
162 gpm-service-type
163 gpm-service
0adfe95a 164
9009538d 165 urandom-seed-service-type
a535e122 166 urandom-seed-service
24e96431
167
168 rngd-configuration
169 rngd-configuration?
b58cbf9a
DC
170 rngd-service-type
171 rngd-service
46ec2707
DC
172
173 kmscon-configuration
174 kmscon-configuration?
175 kmscon-service-type
176
909147e4
RW
177 pam-limits-service-type
178 pam-limits-service
a535e122 179
cc339cd9
OP
180 references-file
181
8b198abe 182 %base-services))
db4fdc04
LC
183
184;;; Commentary:
185;;;
186;;; Base system services---i.e., services that 99% of the users will want to
187;;; use.
188;;;
189;;; Code:
190
206a28d8
LC
191
192\f
0adfe95a
LC
193;;;
194;;; File systems.
195;;;
a00dd9fb 196
e43e84ba
LC
197(define (file-system->fstab-entry file-system)
198 "Return a @file{/etc/fstab} entry for @var{file-system}."
a5acc17a
LC
199 (string-append (match (file-system-device file-system)
200 ((? file-system-label? label)
201 (string-append "LABEL="
0d56d9c7 202 (file-system-label->string label)))
a5acc17a
LC
203 ((? uuid? uuid)
204 (string-append "UUID=" (uuid->string uuid)))
205 ((? string? device)
206 device))
e43e84ba
LC
207 "\t"
208 (file-system-mount-point file-system) "\t"
209 (file-system-type file-system) "\t"
210 (or (file-system-options file-system) "defaults") "\t"
211
212 ;; XXX: Omit the 'fs_freq' and 'fs_passno' fields because we
213 ;; don't have anything sensible to put in there.
214 ))
215
216(define (file-systems->fstab file-systems)
217 "Return a @file{/etc} entry for an @file{fstab} describing
218@var{file-systems}."
219 `(("fstab" ,(plain-file "fstab"
220 (string-append
221 "\
59e80445 222# This file was generated from your Guix configuration. Any changes
e43e84ba
LC
223# will be lost upon reboot or reconfiguration.\n\n"
224 (string-join (map file-system->fstab-entry
225 file-systems)
226 "\n")
227 "\n")))))
228
229(define fstab-service-type
230 ;; The /etc/fstab service.
231 (service-type (name 'fstab)
232 (extensions
233 (list (service-extension etc-service-type
234 file-systems->fstab)))
aa1145df 235 (compose concatenate)
6b9e1fef
LC
236 (extend append)
237 (description
238 "Populate the @file{/etc/fstab} based on the given file
239system objects.")))
e43e84ba 240
d4053c71
AK
241(define %root-file-system-shepherd-service
242 (shepherd-service
be1c2c54
LC
243 (documentation "Take care of the root file system.")
244 (provision '(root-file-system))
245 (start #~(const #t))
246 (stop #~(lambda _
247 ;; Return #f if successfully stopped.
248 (sync)
249
250 (call-with-blocked-asyncs
251 (lambda ()
252 (let ((null (%make-void-port "w")))
34044d55 253 ;; Close 'shepherd.log'.
be1c2c54 254 (display "closing log\n")
34044d55 255 ((@ (shepherd comm) stop-logging))
be1c2c54
LC
256
257 ;; Redirect the default output ports..
258 (set-current-output-port null)
259 (set-current-error-port null)
260
261 ;; Close /dev/console.
262 (for-each close-fdes '(0 1 2))
263
264 ;; At this point, there are no open files left, so the
265 ;; root file system can be re-mounted read-only.
266 (mount #f "/" #f
267 (logior MS_REMOUNT MS_RDONLY)
268 #:update-mtab? #f)
269
270 #f)))))
271 (respawn? #f)))
a00dd9fb 272
0adfe95a 273(define root-file-system-service-type
d4053c71
AK
274 (shepherd-service-type 'root-file-system
275 (const %root-file-system-shepherd-service)))
0adfe95a
LC
276
277(define (root-file-system-service)
278 "Return a service whose sole purpose is to re-mount read-only the root file
279system upon shutdown (aka. cleanly \"umounting\" root.)
280
281This service must be the root of the service dependency graph so that its
d4053c71 282'stop' action is invoked when shepherd is the only process left."
0adfe95a
LC
283 (service root-file-system-service-type #f))
284
d4053c71 285(define (file-system->shepherd-service-name file-system)
0adfe95a
LC
286 "Return the symbol that denotes the service mounting and unmounting
287FILE-SYSTEM."
288 (symbol-append 'file-system-
289 (string->symbol (file-system-mount-point file-system))))
290
d4053c71
AK
291(define (mapped-device->shepherd-service-name md)
292 "Return the symbol that denotes the shepherd service of MD, a <mapped-device>."
e502bf89
LC
293 (symbol-append 'device-mapping-
294 (string->symbol (mapped-device-target md))))
295
d4053c71 296(define dependency->shepherd-service-name
e502bf89
LC
297 (match-lambda
298 ((? mapped-device? md)
d4053c71 299 (mapped-device->shepherd-service-name md))
e502bf89 300 ((? file-system? fs)
d4053c71 301 (file-system->shepherd-service-name fs))))
e502bf89 302
d4053c71 303(define (file-system-shepherd-service file-system)
aa1145df
LC
304 "Return the shepherd service for @var{file-system}, or @code{#f} if
305@var{file-system} is not auto-mounted upon boot."
e43e84ba 306 (let ((target (file-system-mount-point file-system))
e43e84ba 307 (create? (file-system-create-mount-point? file-system))
26e34e1e
DM
308 (dependencies (file-system-dependencies file-system))
309 (packages (file-system-packages (list file-system))))
aa1145df 310 (and (file-system-mount? file-system)
943e1b97
LC
311 (with-imported-modules (source-module-closure
312 '((gnu build file-systems)))
a91c3fc7
LC
313 (shepherd-service
314 (provision (list (file-system->shepherd-service-name file-system)))
c106d03b 315 (requirement `(root-file-system udev
a91c3fc7
LC
316 ,@(map dependency->shepherd-service-name dependencies)))
317 (documentation "Check, mount, and unmount the given file system.")
318 (start #~(lambda args
9970ef61 319 #$(if create?
bf7ef1bb
JD
320 #~(mkdir-p #$target)
321 #t)
9328eafb
LC
322
323 (let (($PATH (getenv "PATH")))
324 ;; Make sure fsck.ext2 & co. can be found.
325 (dynamic-wind
326 (lambda ()
26e34e1e
DM
327 ;; Don’t display the PATH settings.
328 (with-output-to-port (%make-void-port "w")
329 (lambda ()
330 (set-path-environment-variable "PATH"
331 '("bin" "sbin")
332 '#$packages))))
9328eafb
LC
333 (lambda ()
334 (mount-file-system
1c65cca5
LC
335 (spec->file-system
336 '#$(file-system->spec file-system))
9328eafb
LC
337 #:root "/"))
338 (lambda ()
339 (setenv "PATH" $PATH)))
340 #t)))
a91c3fc7
LC
341 (stop #~(lambda args
342 ;; Normally there are no processes left at this point, so
343 ;; TARGET can be safely unmounted.
344
345 ;; Make sure PID 1 doesn't keep TARGET busy.
346 (chdir "/")
347
348 (umount #$target)
349 #f))
350
1c65cca5 351 ;; We need additional modules.
a91c3fc7 352 (modules `(((gnu build file-systems)
bf7ef1bb 353 #:select (mount-file-system))
1c65cca5 354 (gnu system file-systems)
aa1145df 355 ,@%default-modules)))))))
e43e84ba 356
a43aca97
LC
357(define (file-system-shepherd-services file-systems)
358 "Return the list of Shepherd services for FILE-SYSTEMS."
359 (let* ((file-systems (filter file-system-mount? file-systems)))
360 (define sink
361 (shepherd-service
362 (provision '(file-systems))
363 (requirement (cons* 'root-file-system 'user-file-systems
364 (map file-system->shepherd-service-name
365 file-systems)))
366 (documentation "Target for all the initially-mounted file systems")
367 (start #~(const #t))
368 (stop #~(const #f))))
369
6c445817
LC
370 (define known-mount-points
371 (map file-system-mount-point file-systems))
372
373 (define user-unmount
374 (shepherd-service
375 (documentation "Unmount manually-mounted file systems.")
376 (provision '(user-file-systems))
377 (start #~(const #t))
378 (stop #~(lambda args
379 (define (known? mount-point)
380 (member mount-point
381 (cons* "/proc" "/sys" '#$known-mount-points)))
382
383 ;; Make sure we don't keep the user's mount points busy.
384 (chdir "/")
385
386 (for-each (lambda (mount-point)
387 (format #t "unmounting '~a'...~%" mount-point)
388 (catch 'system-error
389 (lambda ()
390 (umount mount-point))
391 (lambda args
392 (let ((errno (system-error-errno args)))
393 (format #t "failed to unmount '~a': ~a~%"
394 mount-point (strerror errno))))))
395 (filter (negate known?) (mount-points)))
396 #f))))
397
398 (cons* sink user-unmount
399 (map file-system-shepherd-service file-systems))))
a43aca97 400
74685a43
LC
401(define (file-system-fstab-entries file-systems)
402 "Return the subset of @var{file-systems} that should have an entry in
403@file{/etc/fstab}."
404 ;; /etc/fstab is about telling fsck(8), mount(8), and umount(8) about
405 ;; relevant file systems they'll have to deal with. That excludes "pseudo"
406 ;; file systems.
407 ;;
408 ;; In particular, things like GIO (part of GLib) use it to determine the set
409 ;; of mounts, which is then used by graphical file managers and desktop
410 ;; environments to display "volume" icons. Thus, we really need to exclude
411 ;; those pseudo file systems from the list.
412 (remove (lambda (file-system)
413 (or (member (file-system-type file-system)
414 %pseudo-file-system-types)
415 (memq 'bind-mount (file-system-flags file-system))))
416 file-systems))
417
0adfe95a 418(define file-system-service-type
aa1145df 419 (service-type (name 'file-systems)
e43e84ba 420 (extensions
d4053c71 421 (list (service-extension shepherd-root-service-type
a43aca97 422 file-system-shepherd-services)
e43e84ba 423 (service-extension fstab-service-type
74685a43 424 file-system-fstab-entries)
206a28d8
LC
425
426 ;; Have 'user-processes' depend on 'file-systems'.
427 (service-extension user-processes-service-type
428 (const '(file-systems)))))
aa1145df 429 (compose concatenate)
6b9e1fef
LC
430 (extend append)
431 (description
432 "Provide Shepherd services to mount and unmount the given
433file systems, as well as corresponding @file{/etc/fstab} entries.")))
0adfe95a 434
d6e2a622 435
0adfe95a 436\f
a535e122
LF
437;;;
438;;; Preserve entropy to seed /dev/urandom on boot.
439;;;
440
441(define %random-seed-file
442 "/var/lib/random-seed")
443
a535e122
LF
444(define (urandom-seed-shepherd-service _)
445 "Return a shepherd service for the /dev/urandom seed."
446 (list (shepherd-service
447 (documentation "Preserve entropy across reboots for /dev/urandom.")
448 (provision '(urandom-seed))
4a32f58a
LC
449
450 ;; Depend on udev so that /dev/hwrng is available.
451 (requirement '(file-systems udev))
452
a535e122
LF
453 (start #~(lambda _
454 ;; On boot, write random seed into /dev/urandom.
455 (when (file-exists? #$%random-seed-file)
456 (call-with-input-file #$%random-seed-file
457 (lambda (seed)
458 (call-with-output-file "/dev/urandom"
459 (lambda (urandom)
81bc4533
LC
460 (dump-port seed urandom)
461
462 ;; Writing SEED to URANDOM isn't enough: we must
463 ;; also tell the kernel to account for these
464 ;; extra bits of entropy.
465 (let ((bits (* 8 (stat:size (stat seed)))))
466 (add-to-entropy-count urandom bits)))))))
9a56cf2b
LF
467
468 ;; Try writing from /dev/hwrng into /dev/urandom.
469 ;; It seems that the file /dev/hwrng always exists, even
470 ;; when there is no hardware random number generator
471 ;; available. So, we handle a failed read or any other error
472 ;; reported by the operating system.
473 (let ((buf (catch 'system-error
474 (lambda ()
475 (call-with-input-file "/dev/hwrng"
476 (lambda (hwrng)
477 (get-bytevector-n hwrng 512))))
478 ;; Silence is golden...
479 (const #f))))
480 (when buf
481 (call-with-output-file "/dev/urandom"
482 (lambda (urandom)
81bc4533
LC
483 (put-bytevector urandom buf)
484 (let ((bits (* 8 (bytevector-length buf))))
485 (add-to-entropy-count urandom bits))))))
9a56cf2b 486
71cb237a
LF
487 ;; Immediately refresh the seed in case the system doesn't
488 ;; shut down cleanly.
489 (call-with-input-file "/dev/urandom"
490 (lambda (urandom)
491 (let ((previous-umask (umask #o077))
492 (buf (make-bytevector 512)))
493 (mkdir-p (dirname #$%random-seed-file))
494 (get-bytevector-n! urandom buf 0 512)
495 (call-with-output-file #$%random-seed-file
496 (lambda (seed)
497 (put-bytevector seed buf)))
498 (umask previous-umask))))
a535e122
LF
499 #t))
500 (stop #~(lambda _
501 ;; During shutdown, write from /dev/urandom into random seed.
502 (let ((buf (make-bytevector 512)))
503 (call-with-input-file "/dev/urandom"
504 (lambda (urandom)
8fe5d95e
LF
505 (let ((previous-umask (umask #o077)))
506 (get-bytevector-n! urandom buf 0 512)
71cb237a 507 (mkdir-p (dirname #$%random-seed-file))
8fe5d95e
LF
508 (call-with-output-file #$%random-seed-file
509 (lambda (seed)
510 (put-bytevector seed buf)))
511 (umask previous-umask))
a535e122
LF
512 #t)))))
513 (modules `((rnrs bytevectors)
514 (rnrs io ports)
515 ,@%default-modules)))))
516
517(define urandom-seed-service-type
518 (service-type (name 'urandom-seed)
519 (extensions
520 (list (service-extension shepherd-root-service-type
4e9fd508
LC
521 urandom-seed-shepherd-service)
522
523 ;; Have 'user-processes' depend on 'urandom-seed'.
524 ;; This ensures that user processes and daemons don't
525 ;; start until we have seeded the PRNG.
526 (service-extension user-processes-service-type
527 (const '(urandom-seed)))))
8faaf8d7 528 (default-value #f)
6b9e1fef
LC
529 (description
530 "Seed the @file{/dev/urandom} pseudo-random number
531generator (RNG) with the value recorded when the system was last shut
532down.")))
a535e122 533
65a67bf7
LC
534(define-deprecated (urandom-seed-service)
535 urandom-seed-service-type
536 (service urandom-seed-service-type))
a535e122 537
b58cbf9a
DC
538
539;;;
540;;; Add hardware random number generator to entropy pool.
541;;;
542
543(define-record-type* <rngd-configuration>
544 rngd-configuration make-rngd-configuration
545 rngd-configuration?
546 (rng-tools rngd-configuration-rng-tools) ;package
547 (device rngd-configuration-device)) ;string
548
549(define rngd-service-type
550 (shepherd-service-type
551 'rngd
552 (lambda (config)
553 (define rng-tools (rngd-configuration-rng-tools config))
554 (define device (rngd-configuration-device config))
555
556 (define rngd-command
9e41130b 557 (list (file-append rng-tools "/sbin/rngd")
b58cbf9a
DC
558 "-f" "-r" device))
559
560 (shepherd-service
561 (documentation "Add TRNG to entropy pool.")
562 (requirement '(udev))
563 (provision '(trng))
7d903d2f 564 (start #~(make-forkexec-constructor '#$rngd-command))
b58cbf9a
DC
565 (stop #~(make-kill-destructor))))))
566
567(define* (rngd-service #:key
568 (rng-tools rng-tools)
569 (device "/dev/hwrng"))
570 "Return a service that runs the @command{rngd} program from @var{rng-tools}
571to add @var{device} to the kernel's entropy pool. The service will fail if
572@var{device} does not exist."
573 (service rngd-service-type
574 (rngd-configuration
575 (rng-tools rng-tools)
576 (device device))))
577
e10964ef 578\f
0adfe95a
LC
579;;;
580;;; Console & co.
581;;;
582
583(define host-name-service-type
d4053c71 584 (shepherd-service-type
00184239 585 'host-name
0adfe95a 586 (lambda (name)
d4053c71 587 (shepherd-service
0adfe95a
LC
588 (documentation "Initialize the machine's host name.")
589 (provision '(host-name))
590 (start #~(lambda _
591 (sethostname #$name)))
71fc086a 592 (one-shot? #t)))))
a00dd9fb 593
db4fdc04 594(define (host-name-service name)
51da7ca0 595 "Return a service that sets the host name to @var{name}."
0adfe95a 596 (service host-name-service-type name))
db4fdc04 597
bb3062ad
LC
598(define virtual-terminal-service-type
599 ;; Ensure that virtual terminals run in UTF-8 mode. This is the case by
600 ;; default with recent Linux kernels, but this service allows us to ensure
601 ;; this. This service must start before any 'term-' service so that newly
602 ;; created terminals inherit this property. See
603 ;; <https://bugs.gnu.org/30505> for a discussion.
604 (shepherd-service-type
605 'virtual-terminal
606 (lambda (utf8?)
09b7300c
LC
607 (let ((knob "/sys/module/vt/parameters/default_utf8"))
608 (shepherd-service
609 (documentation "Set virtual terminals in UTF-8 module.")
610 (provision '(virtual-terminal))
611 (requirement '(root-file-system))
612 (start #~(lambda _
613 ;; In containers /sys is read-only so don't insist on
614 ;; writing to this file.
615 (unless (= 1 (call-with-input-file #$knob read))
616 (call-with-output-file #$knob
617 (lambda (port)
618 (display 1 port))))
619 #t))
620 (stop #~(const #f)))))
bb3062ad 621 #t)) ;default to UTF-8
62ca0fdf 622
0adfe95a 623(define console-keymap-service-type
d4053c71 624 (shepherd-service-type
00184239 625 'console-keymap
b3d05f48 626 (lambda (files)
d4053c71 627 (shepherd-service
0adfe95a
LC
628 (documentation (string-append "Load console keymap (loadkeys)."))
629 (provision '(console-keymap))
630 (start #~(lambda _
9fc037fe 631 (zero? (system* #$(file-append kbd "/bin/loadkeys")
b3d05f48 632 #$@files))))
0adfe95a
LC
633 (respawn? #f)))))
634
3a665637
LC
635(define-deprecated (console-keymap-service #:rest files)
636 #f
b3d05f48
AK
637 "Return a service to load console keymaps from @var{files}."
638 (service console-keymap-service-type files))
0adfe95a 639
4a84a487
LC
640(define %default-console-font
641 ;; Note: 'LatGrkCyr-8x16' has the advantage of providing three common
642 ;; scripts as well as glyphs for em dash, quotation marks, and other Unicode
643 ;; codepoints notably found in the UTF-8 manual.
644 "LatGrkCyr-8x16")
645
646(define (console-font-shepherd-services tty+font)
647 "Return a list of Shepherd services for each pair in TTY+FONT."
648 (map (match-lambda
649 ((tty . font)
650 (let ((device (string-append "/dev/" tty)))
651 (shepherd-service
652 (documentation "Load a Unicode console font.")
653 (provision (list (symbol-append 'console-font-
654 (string->symbol tty))))
655
656 ;; Start after mingetty has been started on TTY, otherwise the settings
657 ;; are ignored.
658 (requirement (list (symbol-append 'term-
659 (string->symbol tty))))
660
661 (start #~(lambda _
787e8a80
LC
662 ;; It could be that mingetty is not fully ready yet,
663 ;; which we check by calling 'ttyname'.
664 (let loop ((i 10))
665 (unless (or (zero? i)
666 (call-with-input-file #$device
667 (lambda (port)
668 (false-if-exception (ttyname port)))))
669 (usleep 500)
670 (loop (- i 1))))
671
bb3062ad
LC
672 ;; Assume the VT is already in UTF-8 mode, thanks to
673 ;; the 'virtual-terminal' service.
674 ;;
675 ;; 'setfont' returns EX_OSERR (71) when an
676 ;; KDFONTOP ioctl fails, for example. Like
677 ;; systemd's vconsole support, let's not treat
678 ;; this as an error.
679 (case (status:exit-val
680 (system* #$(file-append kbd "/bin/setfont")
681 "-C" #$device #$font))
682 ((0 71) #t)
683 (else #f))))
4a84a487
LC
684 (stop #~(const #t))
685 (respawn? #f)))))
686 tty+font))
0adfe95a 687
4a84a487
LC
688(define console-font-service-type
689 (service-type (name 'console-fonts)
690 (extensions
691 (list (service-extension shepherd-root-service-type
692 console-font-shepherd-services)))
693 (compose concatenate)
6b9e1fef
LC
694 (extend append)
695 (description
696 "Install the given fonts on the specified ttys (fonts are per
697virtual console on GNU/Linux). The value of this service is a list of
74a98b5c
JS
698tty/font pairs. The font can be the name of a font provided by the @code{kbd}
699package or any valid argument to @command{setfont}, as in this example:
6b9e1fef
LC
700
701@example
ae5c4a92
LC
702`((\"tty1\" . \"LatGrkCyr-8x16\")
703 (\"tty2\" . ,(file-append
704 font-tamzen
705 \"/share/kbd/consolefonts/TamzenForPowerline10x20.psf\"))
706 (\"tty3\" . ,(file-append
707 font-terminus
708 \"/share/consolefonts/ter-132n\"))) ; for HDPI
6b9e1fef 709@end example\n")))
5eca9459 710
62ca0fdf 711(define* (console-font-service tty #:optional (font "LatGrkCyr-8x16"))
4a84a487
LC
712 "This procedure is deprecated in favor of @code{console-font-service-type}.
713
714Return a service that sets up Unicode support in @var{tty} and loads
62ca0fdf 715@var{font} for that tty (fonts are per virtual console in Linux.)"
4a84a487
LC
716 (simple-service (symbol-append 'console-font- (string->symbol tty))
717 console-font-service-type `((,tty . ,font))))
62ca0fdf 718
317d3b47
DC
719(define %default-motd
720 (plain-file "motd" "This is the GNU operating system, welcome!\n\n"))
721
722(define-record-type* <login-configuration>
723 login-configuration make-login-configuration
724 login-configuration?
725 (motd login-configuration-motd ;file-like
726 (default %default-motd))
727 ;; Allow empty passwords by default so that first-time users can log in when
728 ;; the 'root' account has just been created.
729 (allow-empty-passwords? login-configuration-allow-empty-passwords?
730 (default #t))) ;Boolean
731
732(define (login-pam-service config)
733 "Return the list of PAM service needed for CONF."
734 ;; Let 'login' be known to PAM.
735 (list (unix-pam-service "login"
e6b1a224 736 #:login-uid? #t
317d3b47
DC
737 #:allow-empty-passwords?
738 (login-configuration-allow-empty-passwords? config)
739 #:motd
740 (login-configuration-motd config))))
741
742(define login-service-type
743 (service-type (name 'login)
744 (extensions (list (service-extension pam-root-service-type
6b9e1fef 745 login-pam-service)))
178bce41 746 (default-value (login-configuration))
6b9e1fef
LC
747 (description
748 "Provide a console log-in service as specified by its
749configuration value, a @code{login-configuration} object.")))
317d3b47
DC
750
751(define* (login-service #:optional (config (login-configuration)))
752 "Return a service configure login according to @var{config}, which specifies
753the message of the day, among other things."
754 (service login-service-type config))
755
9ee4c9ab
LF
756(define-record-type* <agetty-configuration>
757 agetty-configuration make-agetty-configuration
758 agetty-configuration?
759 (agetty agetty-configuration-agetty ;<package>
760 (default util-linux))
5a9902c8 761 (tty agetty-configuration-tty) ;string | #f
9ee4c9ab
LF
762 (term agetty-term ;string | #f
763 (default #f))
764 (baud-rate agetty-baud-rate ;string | #f
765 (default #f))
766 (auto-login agetty-auto-login ;list of strings | #f
767 (default #f))
768 (login-program agetty-login-program ;gexp
769 (default (file-append shadow "/bin/login")))
770 (login-pause? agetty-login-pause? ;Boolean
771 (default #f))
772 (eight-bits? agetty-eight-bits? ;Boolean
773 (default #f))
774 (no-reset? agetty-no-reset? ;Boolean
775 (default #f))
776 (remote? agetty-remote? ;Boolean
777 (default #f))
778 (flow-control? agetty-flow-control? ;Boolean
779 (default #f))
780 (host agetty-host ;string | #f
781 (default #f))
782 (no-issue? agetty-no-issue? ;Boolean
783 (default #f))
784 (init-string agetty-init-string ;string | #f
785 (default #f))
786 (no-clear? agetty-no-clear? ;Boolean
787 (default #f))
788 (local-line agetty-local-line ;always | never | auto
789 (default #f))
790 (extract-baud? agetty-extract-baud? ;Boolean
791 (default #f))
792 (skip-login? agetty-skip-login? ;Boolean
793 (default #f))
794 (no-newline? agetty-no-newline? ;Boolean
795 (default #f))
796 (login-options agetty-login-options ;string | #f
797 (default #f))
798 (chroot agetty-chroot ;string | #f
799 (default #f))
800 (hangup? agetty-hangup? ;Boolean
801 (default #f))
802 (keep-baud? agetty-keep-baud? ;Boolean
803 (default #f))
804 (timeout agetty-timeout ;integer | #f
805 (default #f))
806 (detect-case? agetty-detect-case? ;Boolean
807 (default #f))
808 (wait-cr? agetty-wait-cr? ;Boolean
809 (default #f))
810 (no-hints? agetty-no-hints? ;Boolean
811 (default #f))
812 (no-hostname? agetty-no hostname? ;Boolean
813 (default #f))
814 (long-hostname? agetty-long-hostname? ;Boolean
815 (default #f))
816 (erase-characters agetty-erase-characters ;string | #f
817 (default #f))
818 (kill-characters agetty-kill-characters ;string | #f
819 (default #f))
820 (chdir agetty-chdir ;string | #f
821 (default #f))
822 (delay agetty-delay ;integer | #f
823 (default #f))
824 (nice agetty-nice ;integer | #f
825 (default #f))
826 ;; "Escape hatch" for passing arbitrary command-line arguments.
827 (extra-options agetty-extra-options ;list of strings
828 (default '()))
829;;; XXX Unimplemented for now!
830;;; (issue-file agetty-issue-file ;file-like
831;;; (default #f))
832 )
833
5a9902c8
DM
834(define (default-serial-port)
835 "Return a gexp that determines a reasonable default serial port
836to use as the tty. This is primarily useful for headless systems."
62c22175
LC
837 (with-imported-modules (source-module-closure
838 '((gnu build linux-boot))) ;for 'find-long-options'
dac7dd1b
MO
839 #~(begin
840 ;; console=device,options
841 ;; device: can be tty0, ttyS0, lp0, ttyUSB0 (serial).
842 ;; options: BBBBPNF. P n|o|e, N number of bits,
843 ;; F flow control (r RTS)
844 (let* ((not-comma (char-set-complement (char-set #\,)))
845 (command (linux-command-line))
846 (agetty-specs (find-long-options "agetty.tty" command))
847 (console-specs (filter (lambda (spec)
848 (and (string-prefix? "tty" spec)
849 (not (or
850 (string-prefix? "tty0" spec)
851 (string-prefix? "tty1" spec)
852 (string-prefix? "tty2" spec)
853 (string-prefix? "tty3" spec)
854 (string-prefix? "tty4" spec)
855 (string-prefix? "tty5" spec)
856 (string-prefix? "tty6" spec)
857 (string-prefix? "tty7" spec)
858 (string-prefix? "tty8" spec)
859 (string-prefix? "tty9" spec)))))
860 (find-long-options "console" command)))
861 (specs (append agetty-specs console-specs)))
862 (match specs
863 (() #f)
864 ((spec _ ...)
865 ;; Extract device name from first spec.
866 (match (string-tokenize spec not-comma)
867 ((device-name _ ...)
868 device-name))))))))
5a9902c8 869
9ee4c9ab
LF
870(define agetty-shepherd-service
871 (match-lambda
872 (($ <agetty-configuration> agetty tty term baud-rate auto-login
873 login-program login-pause? eight-bits? no-reset? remote? flow-control?
874 host no-issue? init-string no-clear? local-line extract-baud?
875 skip-login? no-newline? login-options chroot hangup? keep-baud? timeout
876 detect-case? wait-cr? no-hints? no-hostname? long-hostname?
877 erase-characters kill-characters chdir delay nice extra-options)
878 (list
879 (shepherd-service
880 (documentation "Run agetty on a tty.")
5a9902c8 881 (provision (list (symbol-append 'term- (string->symbol (or tty "auto")))))
9ee4c9ab
LF
882
883 ;; Since the login prompt shows the host name, wait for the 'host-name'
884 ;; service to be done. Also wait for udev essentially so that the tty
885 ;; text is not lost in the middle of kernel messages (see also
886 ;; mingetty-shepherd-service).
887 (requirement '(user-processes host-name udev))
888
5f15b422
LC
889 (modules '((ice-9 match) (gnu build linux-boot)))
890 (start
891 (with-imported-modules (source-module-closure
892 '((gnu build linux-boot)))
dac7dd1b
MO
893 #~(lambda args
894 (let ((defaulted-tty #$(or tty (default-serial-port))))
895 (apply
896 (if defaulted-tty
897 (make-forkexec-constructor
898 (list #$(file-append util-linux "/sbin/agetty")
899 #$@extra-options
900 #$@(if eight-bits?
901 #~("--8bits")
902 #~())
903 #$@(if no-reset?
904 #~("--noreset")
905 #~())
906 #$@(if remote?
907 #~("--remote")
908 #~())
909 #$@(if flow-control?
910 #~("--flow-control")
911 #~())
912 #$@(if host
913 #~("--host" #$host)
914 #~())
915 #$@(if no-issue?
916 #~("--noissue")
917 #~())
918 #$@(if init-string
919 #~("--init-string" #$init-string)
920 #~())
921 #$@(if no-clear?
922 #~("--noclear")
923 #~())
924;;; FIXME This doesn't work as expected. According to agetty(8), if this option
925;;; is not passed, then the default is 'auto'. However, in my tests, when that
926;;; option is selected, agetty never presents the login prompt, and the
927;;; term-ttyS0 service respawns every few seconds.
928 #$@(if local-line
929 #~(#$(match local-line
930 ('auto "--local-line=auto")
931 ('always "--local-line=always")
932 ('never "-local-line=never")))
933 #~())
934 #$@(if tty
935 #~()
936 #~("--keep-baud"))
937 #$@(if extract-baud?
938 #~("--extract-baud")
939 #~())
940 #$@(if skip-login?
941 #~("--skip-login")
942 #~())
943 #$@(if no-newline?
944 #~("--nonewline")
945 #~())
946 #$@(if login-options
947 #~("--login-options" #$login-options)
948 #~())
949 #$@(if chroot
950 #~("--chroot" #$chroot)
951 #~())
952 #$@(if hangup?
953 #~("--hangup")
954 #~())
955 #$@(if keep-baud?
956 #~("--keep-baud")
957 #~())
958 #$@(if timeout
959 #~("--timeout" #$(number->string timeout))
960 #~())
961 #$@(if detect-case?
962 #~("--detect-case")
963 #~())
964 #$@(if wait-cr?
965 #~("--wait-cr")
966 #~())
967 #$@(if no-hints?
968 #~("--nohints?")
969 #~())
970 #$@(if no-hostname?
971 #~("--nohostname")
972 #~())
973 #$@(if long-hostname?
974 #~("--long-hostname")
975 #~())
976 #$@(if erase-characters
977 #~("--erase-chars" #$erase-characters)
978 #~())
979 #$@(if kill-characters
980 #~("--kill-chars" #$kill-characters)
981 #~())
982 #$@(if chdir
983 #~("--chdir" #$chdir)
984 #~())
985 #$@(if delay
986 #~("--delay" #$(number->string delay))
987 #~())
988 #$@(if nice
989 #~("--nice" #$(number->string nice))
990 #~())
991 #$@(if auto-login
992 (list "--autologin" auto-login)
993 '())
994 #$@(if login-program
995 #~("--login-program" #$login-program)
996 #~())
997 #$@(if login-pause?
998 #~("--login-pause")
999 #~())
1000 defaulted-tty
1001 #$@(if baud-rate
1002 #~(#$baud-rate)
1003 #~())
1004 #$@(if term
1005 #~(#$term)
1006 #~())))
1007 (const #f)) ; never start.
1008 args)))))
9ee4c9ab
LF
1009 (stop #~(make-kill-destructor)))))))
1010
1011(define agetty-service-type
1012 (service-type (name 'agetty)
1013 (extensions (list (service-extension shepherd-root-service-type
6b9e1fef
LC
1014 agetty-shepherd-service)))
1015 (description
1016 "Provide console login using the @command{agetty}
1017program.")))
9ee4c9ab
LF
1018
1019(define* (agetty-service config)
1020 "Return a service to run agetty according to @var{config}, which specifies
1021the tty to run, among other things."
1022 (service agetty-service-type config))
1023
66e4f01c
LC
1024(define-record-type* <mingetty-configuration>
1025 mingetty-configuration make-mingetty-configuration
1026 mingetty-configuration?
1027 (mingetty mingetty-configuration-mingetty ;<package>
1028 (default mingetty))
1029 (tty mingetty-configuration-tty) ;string
66e4f01c
LC
1030 (auto-login mingetty-auto-login ;string | #f
1031 (default #f))
1032 (login-program mingetty-login-program ;gexp
1033 (default #f))
1034 (login-pause? mingetty-login-pause? ;Boolean
317d3b47 1035 (default #f)))
0adfe95a 1036
d4053c71 1037(define mingetty-shepherd-service
0adfe95a 1038 (match-lambda
317d3b47
DC
1039 (($ <mingetty-configuration> mingetty tty auto-login login-program
1040 login-pause?)
0adfe95a 1041 (list
d4053c71 1042 (shepherd-service
0adfe95a
LC
1043 (documentation "Run mingetty on an tty.")
1044 (provision (list (symbol-append 'term- (string->symbol tty))))
1045
1046 ;; Since the login prompt shows the host name, wait for the 'host-name'
1047 ;; service to be done. Also wait for udev essentially so that the tty
1048 ;; text is not lost in the middle of kernel messages (XXX).
bb3062ad 1049 (requirement '(user-processes host-name udev virtual-terminal))
0adfe95a 1050
7e0a6fac
DM
1051 (start #~(make-forkexec-constructor
1052 (list #$(file-append mingetty "/sbin/mingetty")
a043b5b8
LC
1053 "--noclear"
1054
1055 ;; Avoiding 'vhangup' allows us to avoid 'setfont'
1056 ;; errors down the path where various ioctls get
1057 ;; EIO--see 'hung_up_tty_ioctl' in driver/tty/tty_io.c
1058 ;; in Linux.
1059 "--nohangup" #$tty
1060
7e0a6fac
DM
1061 #$@(if auto-login
1062 #~("--autologin" #$auto-login)
1063 #~())
1064 #$@(if login-program
1065 #~("--loginprog" #$login-program)
1066 #~())
1067 #$@(if login-pause?
1068 #~("--loginpause")
1069 #~()))))
0adfe95a
LC
1070 (stop #~(make-kill-destructor)))))))
1071
1072(define mingetty-service-type
1073 (service-type (name 'mingetty)
d4053c71 1074 (extensions (list (service-extension shepherd-root-service-type
6b9e1fef
LC
1075 mingetty-shepherd-service)))
1076 (description
1077 "Provide console login using the @command{mingetty}
1078program.")))
0adfe95a
LC
1079
1080(define* (mingetty-service config)
1081 "Return a service to run mingetty according to @var{config}, which specifies
1082the tty to run, among other things."
1083 (service mingetty-service-type config))
db4fdc04 1084
6454b333
LC
1085(define-record-type* <nscd-configuration> nscd-configuration
1086 make-nscd-configuration
1087 nscd-configuration?
1088 (log-file nscd-configuration-log-file ;string
1089 (default "/var/log/nscd.log"))
1090 (debug-level nscd-debug-level ;integer
1091 (default 0))
1092 ;; TODO: See nscd.conf in glibc for other options to add.
1093 (caches nscd-configuration-caches ;list of <nscd-cache>
b893f1ae
LC
1094 (default %nscd-default-caches))
1095 (name-services nscd-configuration-name-services ;list of <packages>
1096 (default '()))
1097 (glibc nscd-configuration-glibc ;<package>
dfc8ccbf 1098 (default glibc)))
6454b333
LC
1099
1100(define-record-type* <nscd-cache> nscd-cache make-nscd-cache
1101 nscd-cache?
1102 (database nscd-cache-database) ;symbol
1103 (positive-time-to-live nscd-cache-positive-time-to-live) ;integer
1104 (negative-time-to-live nscd-cache-negative-time-to-live
1105 (default 20)) ;integer
1106 (suggested-size nscd-cache-suggested-size ;integer ("default module
1107 ;of hash table")
1108 (default 211))
1109 (check-files? nscd-cache-check-files? ;Boolean
1110 (default #t))
1111 (persistent? nscd-cache-persistent? ;Boolean
1112 (default #t))
1113 (shared? nscd-cache-shared? ;Boolean
1114 (default #t))
1115 (max-database-size nscd-cache-max-database-size ;integer
1116 (default (* 32 (expt 2 20))))
1117 (auto-propagate? nscd-cache-auto-propagate? ;Boolean
1118 (default #t)))
1119
1120(define %nscd-default-caches
1121 ;; Caches that we want to enable by default. Note that when providing an
1122 ;; empty nscd.conf, all caches are disabled.
1123 (list (nscd-cache (database 'hosts)
1124
1125 ;; Aggressively cache the host name cache to improve
1126 ;; privacy and resilience.
1127 (positive-time-to-live (* 3600 12))
1128 (negative-time-to-live 20)
1129 (persistent? #t))
1130
1131 (nscd-cache (database 'services)
1132
1133 ;; Services are unlikely to change, so we can be even more
1134 ;; aggressive.
1135 (positive-time-to-live (* 3600 24))
1136 (negative-time-to-live 3600)
1137 (check-files? #t) ;check /etc/services changes
1138 (persistent? #t))))
1139
1140(define %nscd-default-configuration
1141 ;; Default nscd configuration.
1142 (nscd-configuration))
1143
1144(define (nscd.conf-file config)
1145 "Return the @file{nscd.conf} configuration file for @var{config}, an
1146@code{<nscd-configuration>} object."
1147 (define cache->config
1148 (match-lambda
be1c2c54
LC
1149 (($ <nscd-cache> (= symbol->string database)
1150 positive-ttl negative-ttl size check-files?
1151 persistent? shared? max-size propagate?)
1152 (string-append "\nenable-cache\t" database "\tyes\n"
1153
1154 "positive-time-to-live\t" database "\t"
1155 (number->string positive-ttl) "\n"
1156 "negative-time-to-live\t" database "\t"
1157 (number->string negative-ttl) "\n"
1158 "suggested-size\t" database "\t"
1159 (number->string size) "\n"
1160 "check-files\t" database "\t"
1161 (if check-files? "yes\n" "no\n")
1162 "persistent\t" database "\t"
1163 (if persistent? "yes\n" "no\n")
1164 "shared\t" database "\t"
1165 (if shared? "yes\n" "no\n")
1166 "max-db-size\t" database "\t"
1167 (number->string max-size) "\n"
1168 "auto-propagate\t" database "\t"
1169 (if propagate? "yes\n" "no\n")))))
6454b333
LC
1170
1171 (match config
1172 (($ <nscd-configuration> log-file debug-level caches)
be1c2c54
LC
1173 (plain-file "nscd.conf"
1174 (string-append "\
6454b333 1175# Configuration of libc's name service cache daemon (nscd).\n\n"
be1c2c54
LC
1176 (if log-file
1177 (string-append "logfile\t" log-file)
1178 "")
1179 "\n"
1180 (if debug-level
1181 (string-append "debug-level\t"
1182 (number->string debug-level))
1183 "")
1184 "\n"
1185 (string-concatenate
1186 (map cache->config caches)))))))
6454b333 1187
d3f75179
LC
1188(define (nscd-action-procedure nscd config option)
1189 ;; XXX: This is duplicated from mcron; factorize.
1190 #~(lambda (_ . args)
1191 ;; Run 'nscd' in a pipe so we can explicitly redirect its output to
1192 ;; 'current-output-port', which at this stage is bound to the client
1193 ;; connection.
1194 (let ((pipe (apply open-pipe* OPEN_READ #$nscd
1195 "-f" #$config #$option args)))
1196 (let loop ()
1197 (match (read-line pipe 'concat)
1198 ((? eof-object?)
1199 (catch 'system-error
1200 (lambda ()
1201 (zero? (close-pipe pipe)))
1202 (lambda args
1203 ;; There's a race with the SIGCHLD handler, which could
1204 ;; call 'waitpid' before 'close-pipe' above does. If we
33572a36
LC
1205 ;; get ECHILD, that means we lost the race; in that case, we
1206 ;; cannot tell what the exit code was (FIXME).
d3f75179
LC
1207 (or (= ECHILD (system-error-errno args))
1208 (apply throw args)))))
1209 (line
1210 (display line)
1211 (loop)))))))
1212
1213(define (nscd-actions nscd config)
1214 "Return Shepherd actions for NSCD."
1215 ;; Make this functionality available as actions because that's a simple way
1216 ;; to run the right 'nscd' binary with the right config file.
1217 (list (shepherd-action
1218 (name 'statistics)
1219 (documentation "Display statistics about nscd usage.")
1220 (procedure (nscd-action-procedure nscd config "--statistics")))
1221 (shepherd-action
1222 (name 'invalidate)
1223 (documentation
1224 "Invalidate the given cache--e.g., 'hosts' for host name lookups.")
1225 (procedure (nscd-action-procedure nscd config "--invalidate")))))
1226
d4053c71
AK
1227(define (nscd-shepherd-service config)
1228 "Return a shepherd service for CONFIG, an <nscd-configuration> object."
d3f75179
LC
1229 (let ((nscd (file-append (nscd-configuration-glibc config)
1230 "/sbin/nscd"))
1231 (nscd.conf (nscd.conf-file config))
0adfe95a 1232 (name-services (nscd-configuration-name-services config)))
d4053c71 1233 (list (shepherd-service
0adfe95a
LC
1234 (documentation "Run libc's name service cache daemon (nscd).")
1235 (provision '(nscd))
1236 (requirement '(user-processes))
1237 (start #~(make-forkexec-constructor
d3f75179 1238 (list #$nscd "-f" #$nscd.conf "--foreground")
0adfe95a 1239
04101d99
LC
1240 ;; Wait for the PID file. However, the PID file is
1241 ;; written before nscd is actually listening on its
1242 ;; socket (XXX).
1243 #:pid-file "/var/run/nscd/nscd.pid"
1244
0adfe95a
LC
1245 #:environment-variables
1246 (list (string-append "LD_LIBRARY_PATH="
1247 (string-join
1248 (map (lambda (dir)
1249 (string-append dir "/lib"))
1250 (list #$@name-services))
1251 ":")))))
d3f75179
LC
1252 (stop #~(make-kill-destructor))
1253 (modules `((ice-9 popen) ;for the actions
1254 (ice-9 rdelim)
1255 (ice-9 match)
1256 ,@%default-modules))
1257 (actions (nscd-actions nscd nscd.conf))))))
0adfe95a
LC
1258
1259(define nscd-activation
1260 ;; Actions to take before starting nscd.
1261 #~(begin
1262 (use-modules (guix build utils))
1263 (mkdir-p "/var/run/nscd")
49f9d7f6
LC
1264 (mkdir-p "/var/db/nscd") ;for the persistent cache
1265
1266 ;; In libc 2.25 nscd uses inotify to watch /etc/resolv.conf, but only if
c298fb13
LC
1267 ;; that file exists when it is started. Thus create it here. Note: on
1268 ;; some systems, such as when NetworkManager is used, /etc/resolv.conf
1269 ;; is a symlink, hence 'lstat'.
1270 (unless (false-if-exception (lstat "/etc/resolv.conf"))
49f9d7f6
LC
1271 (call-with-output-file "/etc/resolv.conf"
1272 (lambda (port)
1273 (display "# This is a placeholder.\n" port))))))
0adfe95a
LC
1274
1275(define nscd-service-type
1276 (service-type (name 'nscd)
1277 (extensions
1278 (list (service-extension activation-service-type
1279 (const nscd-activation))
d4053c71
AK
1280 (service-extension shepherd-root-service-type
1281 nscd-shepherd-service)))
0adfe95a
LC
1282
1283 ;; This can be extended by providing additional name services
1284 ;; such as nss-mdns.
1285 (compose concatenate)
1286 (extend (lambda (config name-services)
1287 (nscd-configuration
1288 (inherit config)
1289 (name-services (append
1290 (nscd-configuration-name-services config)
6b9e1fef 1291 name-services)))))
db903549 1292 (default-value %nscd-default-configuration)
6b9e1fef
LC
1293 (description
1294 "Runs libc's @dfn{name service cache daemon} (nscd) with the
1295given configuration---an @code{<nscd-configuration>} object. @xref{Name
1296Service Switch}, for an example.")))
0adfe95a 1297
b893f1ae 1298(define* (nscd-service #:optional (config %nscd-default-configuration))
6454b333 1299 "Return a service that runs libc's name service cache daemon (nscd) with the
b893f1ae
LC
1300given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
1301Service Switch}, for an example."
0adfe95a
LC
1302 (service nscd-service-type config))
1303
ec2e2f6c
DC
1304
1305(define-record-type* <syslog-configuration>
1306 syslog-configuration make-syslog-configuration
1307 syslog-configuration?
1308 (syslogd syslog-configuration-syslogd
9e41130b 1309 (default (file-append inetutils "/libexec/syslogd")))
ec2e2f6c
DC
1310 (config-file syslog-configuration-config-file
1311 (default %default-syslog.conf)))
1312
0adfe95a 1313(define syslog-service-type
d4053c71 1314 (shepherd-service-type
00184239 1315 'syslog
ec2e2f6c 1316 (lambda (config)
d4053c71 1317 (shepherd-service
0adfe95a
LC
1318 (documentation "Run the syslog daemon (syslogd).")
1319 (provision '(syslogd))
1320 (requirement '(user-processes))
5aa4d2dc
LC
1321 (start #~(let ((spawn (make-forkexec-constructor
1322 (list #$(syslog-configuration-syslogd config)
1323 "--rcfile"
1324 #$(syslog-configuration-config-file config))
1325 #:pid-file "/var/run/syslog.pid")))
1326 (lambda ()
1327 ;; Set the umask such that file permissions are #o640.
1328 (let ((mask (umask #o137))
1329 (pid (spawn)))
1330 (umask mask)
1331 pid))))
0adfe95a 1332 (stop #~(make-kill-destructor))))))
be1c2c54
LC
1333
1334;; Snippet adapted from the GNU inetutils manual.
1335(define %default-syslog.conf
1336 (plain-file "syslog.conf" "
1f3fc60d 1337 # Log all error messages, authentication messages of
db4fdc04
LC
1338 # level notice or higher and anything of level err or
1339 # higher to the console.
1340 # Don't log private authentication messages!
6a191274 1341 *.alert;auth.notice;authpriv.none /dev/console
db4fdc04
LC
1342
1343 # Log anything (except mail) of level info or higher.
1344 # Don't log private authentication messages!
1345 *.info;mail.none;authpriv.none /var/log/messages
1346
b6d8066d
AW
1347 # Like /var/log/messages, but also including \"debug\"-level logs.
1348 *.debug;mail.none;authpriv.none /var/log/debug
1349
db4fdc04
LC
1350 # Same, in a different place.
1351 *.info;mail.none;authpriv.none /dev/tty12
1352
1353 # The authpriv file has restricted access.
1354 authpriv.* /var/log/secure
1355
1356 # Log all the mail messages in one place.
1357 mail.* /var/log/maillog
be1c2c54 1358"))
0adfe95a 1359
ec2e2f6c
DC
1360(define* (syslog-service #:optional (config (syslog-configuration)))
1361 "Return a service that runs @command{syslogd} and takes
1362@var{<syslog-configuration>} as a parameter.
44abcb28
LC
1363
1364@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
1365information on the configuration file syntax."
ec2e2f6c
DC
1366 (service syslog-service-type config))
1367
db4fdc04 1368
909147e4
RW
1369(define pam-limits-service-type
1370 (let ((security-limits
1371 ;; Create /etc/security containing the provided "limits.conf" file.
1372 (lambda (limits-file)
1373 `(("security"
1374 ,(computed-file
1375 "security"
1376 #~(begin
1377 (mkdir #$output)
1378 (stat #$limits-file)
1379 (symlink #$limits-file
1380 (string-append #$output "/limits.conf"))))))))
1381 (pam-extension
1382 (lambda (pam)
1383 (let ((pam-limits (pam-entry
1384 (control "required")
1385 (module "pam_limits.so")
1386 (arguments '("conf=/etc/security/limits.conf")))))
1387 (if (member (pam-service-name pam)
ec4fea69 1388 '("login" "su" "slim" "gdm-password" "sddm"))
909147e4
RW
1389 (pam-service
1390 (inherit pam)
1391 (session (cons pam-limits
1392 (pam-service-session pam))))
1393 pam)))))
1394 (service-type
1395 (name 'limits)
1396 (extensions
1397 (list (service-extension etc-service-type security-limits)
1398 (service-extension pam-root-service-type
6b9e1fef
LC
1399 (lambda _ (list pam-extension)))))
1400 (description
1401 "Install the specified resource usage limits by populating
1402@file{/etc/security/limits.conf} and using the @code{pam_limits}
1403authentication module."))))
909147e4
RW
1404
1405(define* (pam-limits-service #:optional (limits '()))
1406 "Return a service that makes selected programs respect the list of
1407pam-limits-entry specified in LIMITS via pam_limits.so."
1408 (service pam-limits-service-type
1409 (plain-file "limits.conf"
1410 (string-join (map pam-limits-entry->string limits)
1411 "\n"))))
1412
1c52181f
LC
1413\f
1414;;;
1415;;; Guix services.
1416;;;
1417
db4fdc04 1418(define* (guix-build-accounts count #:key
ab6a279a 1419 (group "guixbuild")
db4fdc04 1420 (shadow shadow))
309d87c3
LC
1421 "Return a list of COUNT user accounts for Guix build users with the given
1422GID."
5250a4f2
LC
1423 (unfold (cut > <> count)
1424 (lambda (n)
1425 (user-account
1426 (name (format #f "guixbuilder~2,'0d" n))
1427 (system? #t)
5250a4f2
LC
1428 (group group)
1429
1430 ;; guix-daemon expects GROUP to be listed as a
1431 ;; supplementary group too:
1432 ;; <http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html>.
1433 (supplementary-groups (list group "kvm"))
1434
1435 (comment (format #f "Guix Build User ~2d" n))
1436 (home-directory "/var/empty")
9e41130b 1437 (shell (file-append shadow "/sbin/nologin"))))
5250a4f2
LC
1438 1+
1439 1))
db4fdc04 1440
8b3ad455
LC
1441(define not-config?
1442 ;; Select (guix …) and (gnu …) modules, except (guix config).
1443 (match-lambda
1444 (('guix 'config) #f)
1445 (('guix rest ...) #t)
1446 (('gnu rest ...) #t)
1447 (rest #f)))
1448
3a8bfebe 1449(define (substitute-key-authorization keys guix)
970ebdae
LC
1450 "Return a gexp with code to register KEYS, a list of files containing 'guix
1451archive' public keys, with GUIX."
8b3ad455
LC
1452 (define default-acl
1453 (with-extensions (list guile-gcrypt)
1454 (with-imported-modules `(((guix config) => ,(make-config.scm))
8b3ad455
LC
1455 ,@(source-module-closure '((guix pki))
1456 #:select? not-config?))
1457 (computed-file "acl"
1458 #~(begin
1459 (use-modules (guix pki)
1460 (gcrypt pk-crypto)
1461 (ice-9 rdelim))
1462
1463 (define keys
1464 (map (lambda (file)
1465 (call-with-input-file file
1466 (compose string->canonical-sexp
1467 read-string)))
1468 '(#$@keys)))
1469
1470 (call-with-output-file #$output
1471 (lambda (port)
1472 (write-acl (public-keys->acl keys)
1473 port))))))))
1474
1475 (with-imported-modules '((guix build utils))
1476 #~(begin
1477 (use-modules (guix build utils))
1478
1479 (unless (file-exists? "/etc/guix/acl")
1480 (mkdir-p "/etc/guix")
1481 (copy-file #+default-acl "/etc/guix/acl")
1482 (chmod "/etc/guix/acl" #o600)))))
2c5c696c 1483
5b58c28b
LC
1484(define %default-authorized-guix-keys
1485 ;; List of authorized substitute keys.
ea4915a7 1486 (list (file-append guix "/share/guix/berlin.guix.gnu.org.pub")))
5b58c28b 1487
0adfe95a
LC
1488(define-record-type* <guix-configuration>
1489 guix-configuration make-guix-configuration
1490 guix-configuration?
1491 (guix guix-configuration-guix ;<package>
1492 (default guix))
1493 (build-group guix-configuration-build-group ;string
1494 (default "guixbuild"))
1495 (build-accounts guix-configuration-build-accounts ;integer
1496 (default 10))
1497 (authorize-key? guix-configuration-authorize-key? ;Boolean
1498 (default #t))
5b58c28b
LC
1499 (authorized-keys guix-configuration-authorized-keys ;list of gexps
1500 (default %default-authorized-guix-keys))
0adfe95a
LC
1501 (use-substitutes? guix-configuration-use-substitutes? ;Boolean
1502 (default #t))
b0b9f6e0
LC
1503 (substitute-urls guix-configuration-substitute-urls ;list of strings
1504 (default %default-substitute-urls))
88554b5d
LC
1505 (chroot-directories guix-configuration-chroot-directories ;list of file-like/strings
1506 (default '()))
3bee4b61
LC
1507 (max-silent-time guix-configuration-max-silent-time ;integer
1508 (default 0))
1509 (timeout guix-configuration-timeout ;integer
1510 (default 0))
f4596f76
LC
1511 (log-compression guix-configuration-log-compression
1512 (default 'bzip2))
0adfe95a
LC
1513 (extra-options guix-configuration-extra-options ;list of strings
1514 (default '()))
dc0ef095
LC
1515 (log-file guix-configuration-log-file ;string
1516 (default "/var/log/guix-daemon.log"))
93d32da9 1517 (http-proxy guix-http-proxy ;string | #f
b191f0a6
LF
1518 (default #f))
1519 (tmpdir guix-tmpdir ;string | #f
93d32da9 1520 (default #f)))
0adfe95a
LC
1521
1522(define %default-guix-configuration
1523 (guix-configuration))
1524
3302e03b
LC
1525(define shepherd-set-http-proxy-action
1526 ;; Shepherd action to change the HTTP(S) proxy.
1527 (shepherd-action
1528 (name 'set-http-proxy)
1529 (documentation
1530 "Change the HTTP(S) proxy used by 'guix-daemon' and restart it.")
1531 (procedure #~(lambda* (_ #:optional proxy)
1532 (let ((environment (environ)))
1533 ;; A bit of a hack: communicate PROXY to the 'start'
1534 ;; method via environment variables.
1535 (if proxy
1536 (begin
1537 (format #t "changing HTTP/HTTPS \
1538proxy of 'guix-daemon' to ~s...~%"
1539 proxy)
1540 (setenv "http_proxy" proxy))
1541 (begin
1542 (format #t "clearing HTTP/HTTPS \
1543proxy of 'guix-daemon'...~%")
1544 (unsetenv "http_proxy")))
1545 (action 'guix-daemon 'restart)
1546 (environ environment)
1547 #t)))))
1548
d4053c71
AK
1549(define (guix-shepherd-service config)
1550 "Return a <shepherd-service> for the Guix daemon service with CONFIG."
f4596f76
LC
1551 (match-record config <guix-configuration>
1552 (guix build-group build-accounts authorize-key? authorized-keys
1553 use-substitutes? substitute-urls max-silent-time timeout
88554b5d
LC
1554 log-compression extra-options log-file http-proxy tmpdir
1555 chroot-directories)
f4596f76
LC
1556 (list (shepherd-service
1557 (documentation "Run the Guix daemon.")
1558 (provision '(guix-daemon))
1559 (requirement '(user-processes))
3302e03b 1560 (actions (list shepherd-set-http-proxy-action))
8ce6f4dc
MO
1561 (modules '((srfi srfi-1)
1562 (ice-9 match)
1563 (gnu build shepherd)))
f4596f76 1564 (start
8ce6f4dc
MO
1565 (with-imported-modules (source-module-closure
1566 '((gnu build shepherd)))
1567 #~(lambda args
1568 (define proxy
1569 ;; HTTP/HTTPS proxy. The 'http_proxy' variable is set by
1570 ;; the 'set-http-proxy' action.
1571 (or (getenv "http_proxy") #$http-proxy))
1572
1a0da8b4
MO
1573 ;; Start the guix-daemon from a container, when supported,
1574 ;; to solve an installation issue. See the comment below for
1575 ;; more details.
8ce6f4dc
MO
1576 (fork+exec-command/container
1577 (cons* #$(file-append guix "/bin/guix-daemon")
1578 "--build-users-group" #$build-group
1579 "--max-silent-time"
1580 #$(number->string max-silent-time)
1581 "--timeout" #$(number->string timeout)
1582 "--log-compression"
1583 #$(symbol->string log-compression)
1584 #$@(if use-substitutes?
1585 '()
1586 '("--no-substitutes"))
1587 "--substitute-urls" #$(string-join substitute-urls)
1588 #$@extra-options
1589
1590 ;; Add CHROOT-DIRECTORIES and all their dependencies
1591 ;; (if these are store items) to the chroot.
1592 (append-map
1593 (lambda (file)
1594 (append-map (lambda (directory)
1595 (list "--chroot-directory"
1596 directory))
1597 (call-with-input-file file
1598 read)))
1599 '#$(map references-file
1600 chroot-directories)))
1601
1602 ;; When running the installer, we need guix-daemon to
1603 ;; operate from within the same MNT namespace as the
1604 ;; installation container. In that case only, enter the
1605 ;; namespace of the process PID passed as start argument.
1a0da8b4
MO
1606 ;; Otherwise, for symmetry purposes enter the caller
1607 ;; namespaces which is a no-op.
8ce6f4dc
MO
1608 #:pid (match args
1609 ((pid) (string->number pid))
1610 (else (getpid)))
1611
1612 #:environment-variables
1613 (append (list #$@(if tmpdir
1614 (list (string-append "TMPDIR=" tmpdir))
1615 '())
1616
1617 ;; Make sure we run in a UTF-8 locale so that
1618 ;; 'guix offload' correctly restores nars
1619 ;; that contain UTF-8 file names such as
1620 ;; 'nss-certs'. See
1621 ;; <https://bugs.gnu.org/32942>.
1622 (string-append "GUIX_LOCPATH="
1623 #$glibc-utf8-locales
1624 "/lib/locale")
1625 "LC_ALL=en_US.utf8")
1626 (if proxy
1627 (list (string-append "http_proxy=" proxy)
1628 (string-append "https_proxy=" proxy))
1629 '()))
1630
1631 #:log-file #$log-file))))
f4596f76 1632 (stop #~(make-kill-destructor))))))
0adfe95a
LC
1633
1634(define (guix-accounts config)
1635 "Return the user accounts and user groups for CONFIG."
1636 (match config
1637 (($ <guix-configuration> _ build-group build-accounts)
1638 (cons (user-group
1639 (name build-group)
1640 (system? #t)
1641
1642 ;; Use a fixed GID so that we can create the store with the right
1643 ;; owner.
1644 (id 30000))
1645 (guix-build-accounts build-accounts
1646 #:group build-group)))))
1647
1648(define (guix-activation config)
1649 "Return the activation gexp for CONFIG."
1650 (match config
5b58c28b 1651 (($ <guix-configuration> guix build-group build-accounts authorize-key? keys)
0adfe95a 1652 ;; Assume that the store has BUILD-GROUP as its group. We could
0af94ad5 1653 ;; otherwise call 'chown' here, but the problem is that on a COW overlayfs,
0adfe95a
LC
1654 ;; chown leads to an entire copy of the tree, which is a bad idea.
1655
d367a7f3
LC
1656 ;; Generate a key pair and optionally authorize substitute server keys.
1657 #~(begin
1658 (unless (file-exists? "/etc/guix/signing-key.pub")
1659 (system* #$(file-append guix "/bin/guix") "archive"
1660 "--generate-key"))
1661
1662 #$(if authorize-key?
1663 (substitute-key-authorization keys guix)
1664 #~#f)))))
0adfe95a 1665
88554b5d
LC
1666(define* (references-file item #:optional (name "references"))
1667 "Return a file that contains the list of references of ITEM."
1668 (if (struct? item) ;lowerable object
1669 (computed-file name
1670 (with-imported-modules (source-module-closure
1671 '((guix build store-copy)))
1672 #~(begin
1673 (use-modules (guix build store-copy))
1674
1675 (call-with-output-file #$output
1676 (lambda (port)
6892f0a2
LC
1677 (write (map store-info-item
1678 (call-with-input-file "graph"
1679 read-reference-graph))
88554b5d
LC
1680 port)))))
1681 #:options `(#:local-build? #f
1682 #:references-graphs (("graph" ,item))))
1683 (plain-file name "()")))
1684
0adfe95a
LC
1685(define guix-service-type
1686 (service-type
1687 (name 'guix)
1688 (extensions
d4053c71 1689 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a 1690 (service-extension account-service-type guix-accounts)
9a8b9eb8
LC
1691 (service-extension activation-service-type guix-activation)
1692 (service-extension profile-service-type
3d3c5650 1693 (compose list guix-configuration-guix))))
88554b5d
LC
1694
1695 ;; Extensions can specify extra directories to add to the build chroot.
1696 (compose concatenate)
1697 (extend (lambda (config directories)
1698 (guix-configuration
1699 (inherit config)
1700 (chroot-directories
1701 (append (guix-configuration-chroot-directories config)
1702 directories)))))
1703
6b9e1fef
LC
1704 (default-value (guix-configuration))
1705 (description
1706 "Run the build daemon of GNU@tie{}Guix, aka. @command{guix-daemon}.")))
0adfe95a 1707
84a2de36
LC
1708(define-deprecated (guix-service #:optional
1709 (config %default-guix-configuration))
1710 guix-service-type
0adfe95a
LC
1711 "Return a service that runs the Guix build daemon according to
1712@var{config}."
1713 (service guix-service-type config))
1714
1c52181f
LC
1715
1716(define-record-type* <guix-publish-configuration>
1717 guix-publish-configuration make-guix-publish-configuration
1718 guix-publish-configuration?
1719 (guix guix-publish-configuration-guix ;package
1720 (default guix))
1721 (port guix-publish-configuration-port ;number
1722 (default 80))
1723 (host guix-publish-configuration-host ;string
697ddb88 1724 (default "localhost"))
ee2691fa
LC
1725 (compression guix-publish-configuration-compression
1726 (thunked)
1727 (default (default-compression this-record
1728 (current-source-location))))
1729 (compression-level %guix-publish-configuration-compression-level ;deprecated
1730 (default #f))
f2767d3e 1731 (nar-path guix-publish-configuration-nar-path ;string
a35136cb
LC
1732 (default "nar"))
1733 (cache guix-publish-configuration-cache ;#f | string
1734 (default #f))
1735 (workers guix-publish-configuration-workers ;#f | integer
1736 (default #f))
1737 (ttl guix-publish-configuration-ttl ;#f | integer
1738 (default #f)))
1c52181f 1739
ee2691fa
LC
1740(define-deprecated (guix-publish-configuration-compression-level config)
1741 "Return a compression level, the old way."
1742 (match (guix-publish-configuration-compression config)
1743 (((_ level) _ ...) level)))
1744
1745(define (default-compression config properties)
1746 "Return the default 'guix publish' compression according to CONFIG, and
1747raise a deprecation warning if the 'compression-level' field was used."
1748 (match (%guix-publish-configuration-compression-level config)
1749 (#f
1750 '(("gzip" 3)))
1751 (level
1752 (warn-about-deprecation 'compression-level properties
1753 #:replacement 'compression)
1754 `(("gzip" ,level)))))
1755
1756(define (guix-publish-shepherd-service config)
1757 (define (config->compression-options config)
1758 (match (guix-publish-configuration-compression config)
1759 (() ;empty list means "no compression"
1760 '("-C0"))
1761 (lst
1762 (append-map (match-lambda
1763 ((type level)
1764 `("-C" ,(string-append type ":"
1765 (number->string level)))))
1766 lst))))
1767
1768 (match-record config <guix-publish-configuration>
1769 (guix port host nar-path cache workers ttl)
1770 (list (shepherd-service
1771 (provision '(guix-publish))
1772 (requirement '(guix-daemon))
1773 (start #~(make-forkexec-constructor
1774 (list #$(file-append guix "/bin/guix")
1775 "publish" "-u" "guix-publish"
1776 "-p" #$(number->string port)
1777 #$@(config->compression-options config)
1778 (string-append "--nar-path=" #$nar-path)
1779 (string-append "--listen=" #$host)
1780 #$@(if workers
1781 #~((string-append "--workers="
1782 #$(number->string
1783 workers)))
1784 #~())
1785 #$@(if ttl
1786 #~((string-append "--ttl="
1787 #$(number->string ttl)
1788 "s"))
1789 #~())
1790 #$@(if cache
1791 #~((string-append "--cache=" #$cache))
1792 #~()))
1793
1794 ;; Make sure we run in a UTF-8 locale so we can produce
1795 ;; nars for packages that contain UTF-8 file names such
1796 ;; as 'nss-certs'. See <https://bugs.gnu.org/26948>.
1797 #:environment-variables
1798 (list (string-append "GUIX_LOCPATH="
1799 #$glibc-utf8-locales "/lib/locale")
b0979317
CB
1800 "LC_ALL=en_US.utf8")
1801 #:log-file "/var/log/guix-publish.log"))
ee2691fa 1802 (stop #~(make-kill-destructor))))))
1c52181f
LC
1803
1804(define %guix-publish-accounts
1805 (list (user-group (name "guix-publish") (system? #t))
1806 (user-account
1807 (name "guix-publish")
1808 (group "guix-publish")
1809 (system? #t)
1810 (comment "guix publish user")
1811 (home-directory "/var/empty")
9e41130b 1812 (shell (file-append shadow "/sbin/nologin")))))
1c52181f 1813
4252dace
CB
1814(define %guix-publish-log-rotations
1815 (list (log-rotation
1816 (files (list "/var/log/guix-publish.log")))))
1817
a35136cb
LC
1818(define (guix-publish-activation config)
1819 (let ((cache (guix-publish-configuration-cache config)))
1820 (if cache
1821 (with-imported-modules '((guix build utils))
1822 #~(begin
1823 (use-modules (guix build utils))
1824
1825 (mkdir-p #$cache)
1826 (let* ((pw (getpw "guix-publish"))
1827 (uid (passwd:uid pw))
1828 (gid (passwd:gid pw)))
1829 (chown #$cache uid gid))))
1830 #t)))
1831
1c52181f
LC
1832(define guix-publish-service-type
1833 (service-type (name 'guix-publish)
1834 (extensions
d4053c71
AK
1835 (list (service-extension shepherd-root-service-type
1836 guix-publish-shepherd-service)
1c52181f 1837 (service-extension account-service-type
a35136cb 1838 (const %guix-publish-accounts))
4252dace
CB
1839 (service-extension rottlog-service-type
1840 (const %guix-publish-log-rotations))
a35136cb
LC
1841 (service-extension activation-service-type
1842 guix-publish-activation)))
6b9e1fef
LC
1843 (default-value (guix-publish-configuration))
1844 (description
1845 "Add a Shepherd service running @command{guix publish}, a
1846command that allows you to share pre-built binaries with others over HTTP.")))
1c52181f 1847
84a2de36
LC
1848(define-deprecated (guix-publish-service #:key (guix guix)
1849 (port 80) (host "localhost"))
1850 guix-publish-service-type
1c52181f
LC
1851 "Return a service that runs @command{guix publish} listening on @var{host}
1852and @var{port} (@pxref{Invoking guix publish}).
1853
1854This assumes that @file{/etc/guix} already contains a signing key pair as
1855created by @command{guix archive --generate-key} (@pxref{Invoking guix
1856archive}). If that is not the case, the service will fail to start."
f1e900a3 1857 ;; Deprecated.
1c52181f
LC
1858 (service guix-publish-service-type
1859 (guix-publish-configuration (guix guix) (port port) (host host))))
1860
0adfe95a
LC
1861\f
1862;;;
1863;;; Udev.
1864;;;
1865
1866(define-record-type* <udev-configuration>
1867 udev-configuration make-udev-configuration
1868 udev-configuration?
1869 (udev udev-configuration-udev ;<package>
d5949638 1870 (default eudev))
0adfe95a
LC
1871 (rules udev-configuration-rules ;list of <package>
1872 (default '())))
db4fdc04 1873
ecd06ca9
LC
1874(define (udev-rules-union packages)
1875 "Return the union of the @code{lib/udev/rules.d} directories found in each
1876item of @var{packages}."
1877 (define build
4ee96a79
LC
1878 (with-imported-modules '((guix build union)
1879 (guix build utils))
1880 #~(begin
1881 (use-modules (guix build union)
1882 (guix build utils)
1883 (srfi srfi-1)
1884 (srfi srfi-26))
ecd06ca9 1885
4ee96a79
LC
1886 (define %standard-locations
1887 '("/lib/udev/rules.d" "/libexec/udev/rules.d"))
ecd06ca9 1888
4ee96a79
LC
1889 (define (rules-sub-directory directory)
1890 ;; Return the sub-directory of DIRECTORY containing udev rules, or
1891 ;; #f if none was found.
1892 (find directory-exists?
1893 (map (cut string-append directory <>) %standard-locations)))
ecd06ca9 1894
4ee96a79
LC
1895 (mkdir-p (string-append #$output "/lib/udev"))
1896 (union-build (string-append #$output "/lib/udev/rules.d")
1897 (filter-map rules-sub-directory '#$packages)))))
ecd06ca9 1898
4ee96a79 1899 (computed-file "udev-rules" build))
ecd06ca9 1900
80e6f37e
RW
1901(define (udev-rule file-name contents)
1902 "Return a directory with a udev rule file FILE-NAME containing CONTENTS."
1903 (computed-file file-name
4ee96a79
LC
1904 (with-imported-modules '((guix build utils))
1905 #~(begin
1906 (use-modules (guix build utils))
1907
1908 (define rules.d
1909 (string-append #$output "/lib/udev/rules.d"))
1910
1911 (mkdir-p rules.d)
1912 (call-with-output-file
1913 (string-append rules.d "/" #$file-name)
1914 (lambda (port)
1915 (display #$contents port)))))))
7f28bf9a 1916
6e644cfd
MC
1917(define (file->udev-rule file-name file)
1918 "Return a directory with a udev rule file FILE-NAME which is a copy of FILE."
1919 (computed-file file-name
1920 (with-imported-modules '((guix build utils))
1921 #~(begin
1922 (use-modules (guix build utils))
1923
1924 (define rules.d
1925 (string-append #$output "/lib/udev/rules.d"))
1926
1927 (define file-copy-dest
1928 (string-append rules.d "/" #$file-name))
1929
1930 (mkdir-p rules.d)
1931 (copy-file #$file file-copy-dest)))))
1932
80e6f37e
RW
1933(define kvm-udev-rule
1934 ;; Return a directory with a udev rule that changes the group of /dev/kvm to
1935 ;; "kvm" and makes it #o660. Apparently QEMU-KVM used to ship this rule,
1936 ;; but now we have to add it by ourselves.
1937
1938 ;; Build users are part of the "kvm" group, so we can fearlessly make
1939 ;; /dev/kvm 660 (see <http://bugs.gnu.org/18994>, for background.)
1940 (udev-rule "90-kvm.rules"
1941 "KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0660\"\n"))
1942
d4053c71
AK
1943(define udev-shepherd-service
1944 ;; Return a <shepherd-service> for UDEV with RULES.
0adfe95a
LC
1945 (match-lambda
1946 (($ <udev-configuration> udev rules)
80e6f37e 1947 (let* ((rules (udev-rules-union (cons* udev kvm-udev-rule rules)))
0adfe95a
LC
1948 (udev.conf (computed-file "udev.conf"
1949 #~(call-with-output-file #$output
1950 (lambda (port)
1951 (format port
1952 "udev_rules=\"~a/lib/udev/rules.d\"\n"
1953 #$rules))))))
1954 (list
d4053c71 1955 (shepherd-service
0adfe95a
LC
1956 (provision '(udev))
1957
1958 ;; Udev needs /dev to be a 'devtmpfs' mount so that new device nodes can
1959 ;; be added: see
1960 ;; <http://www.linuxfromscratch.org/lfs/view/development/chapter07/udev.html>.
1961 (requirement '(root-file-system))
1962
1963 (documentation "Populate the /dev directory, dynamically.")
38b1ea04
LC
1964 (start
1965 (with-imported-modules (source-module-closure
1966 '((gnu build linux-boot)))
dac7dd1b
MO
1967 #~(lambda ()
1968 (define udevd
1969 ;; 'udevd' from eudev.
1970 #$(file-append udev "/sbin/udevd"))
1971
1972 (define (wait-for-udevd)
1973 ;; Wait until someone's listening on udevd's control
1974 ;; socket.
1975 (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0)))
1976 (let try ()
1977 (catch 'system-error
1978 (lambda ()
1979 (connect sock PF_UNIX "/run/udev/control")
1980 (close-port sock))
1981 (lambda args
1982 (format #t "waiting for udevd...~%")
1983 (usleep 500000)
1984 (try))))))
1985
1986 ;; Allow udev to find the modules.
1987 (setenv "LINUX_MODULE_DIRECTORY"
1988 "/run/booted-system/kernel/lib/modules")
1989
1990 (let* ((kernel-release
1991 (utsname:release (uname)))
1992 (linux-module-directory
1993 (getenv "LINUX_MODULE_DIRECTORY"))
1994 (directory
1995 (string-append linux-module-directory "/"
1996 kernel-release))
1997 (old-umask (umask #o022)))
1998 ;; If we're in a container, DIRECTORY might not exist,
1999 ;; for instance because the host runs a different
2000 ;; kernel. In that case, skip it; we'll just miss a few
2001 ;; nodes like /dev/fuse.
2002 (when (file-exists? directory)
2003 (make-static-device-nodes directory))
2004 (umask old-umask))
2005
2006 (let ((pid (fork+exec-command (list udevd)
2007 #:environment-variables
2008 (cons*
2009 ;; The first one is for udev, the second one for
2010 ;; eudev.
2011 (string-append "UDEV_CONFIG_FILE=" #$udev.conf)
2012 (string-append "EUDEV_RULES_DIRECTORY="
2013 #$(file-append
2014 rules "/lib/udev/rules.d"))
2015 (string-append "LINUX_MODULE_DIRECTORY="
2016 (getenv "LINUX_MODULE_DIRECTORY"))
2017 (default-environment-variables)))))
2018 ;; Wait until udevd is up and running. This appears to
2019 ;; be needed so that the events triggered below are
2020 ;; actually handled.
2021 (wait-for-udevd)
2022
2023 ;; Trigger device node creation.
2024 (system* #$(file-append udev "/bin/udevadm")
2025 "trigger" "--action=add")
2026
2027 ;; Wait for things to settle down.
2028 (system* #$(file-append udev "/bin/udevadm")
2029 "settle")
2030 pid))))
0adfe95a
LC
2031 (stop #~(make-kill-destructor))
2032
2033 ;; When halting the system, 'udev' is actually killed by
2034 ;; 'user-processes', i.e., before its own 'stop' method was called.
2035 ;; Thus, make sure it is not respawned.
86e6b4c9
DM
2036 (respawn? #f)
2037 ;; We need additional modules.
38b1ea04 2038 (modules `((gnu build linux-boot) ;'make-static-device-nodes'
bafcf1f3
LC
2039 ,@%default-modules))
2040
2041 (actions (list (shepherd-action
2042 (name 'rules)
2043 (documentation "Display the directory containing
2044the udev rules in use.")
2045 (procedure #~(lambda (_)
2046 (display #$rules)
2047 (newline))))))))))))
0adfe95a
LC
2048
2049(define udev-service-type
2050 (service-type (name 'udev)
2051 (extensions
d4053c71
AK
2052 (list (service-extension shepherd-root-service-type
2053 udev-shepherd-service)))
0adfe95a
LC
2054
2055 (compose concatenate) ;concatenate the list of rules
2056 (extend (lambda (config rules)
2057 (match config
2058 (($ <udev-configuration> udev initial-rules)
2059 (udev-configuration
2060 (udev udev)
6b9e1fef 2061 (rules (append initial-rules rules)))))))
fd779db9 2062 (default-value (udev-configuration))
6b9e1fef
LC
2063 (description
2064 "Run @command{udev}, which populates the @file{/dev}
2065directory dynamically. Get extra rules from the packages listed in the
2066@code{rules} field of its value, @code{udev-configuration} object.")))
0adfe95a 2067
d5949638 2068(define* (udev-service #:key (udev eudev) (rules '()))
ecd06ca9
LC
2069 "Run @var{udev}, which populates the @file{/dev} directory dynamically. Get
2070extra rules from the packages listed in @var{rules}."
0adfe95a
LC
2071 (service udev-service-type
2072 (udev-configuration (udev udev) (rules rules))))
2073
2b0c0d93
BW
2074(define* (udev-rules-service name rules #:key (groups '()))
2075 "Return a service that extends udev-service-type with RULES and
2076account-service-type with GROUPS as system groups. This works by creating a
2077singleton service type NAME-udev-rules, of which the returned service is an
2078instance."
2079 (let* ((name (symbol-append name '-udev-rules))
2080 (account-extension
2081 (const (map (lambda (group)
2082 (user-group (name group) (system? #t)))
2083 groups)))
2084 (udev-extension (const (list rules)))
2085 (type (service-type
2086 (name name)
2087 (extensions (list
2088 (service-extension
2089 account-service-type account-extension)
2090 (service-extension
2091 udev-service-type udev-extension))))))
2092 (service type #f)))
2093
0adfe95a 2094(define swap-service-type
d4053c71 2095 (shepherd-service-type
00184239 2096 'swap
0adfe95a
LC
2097 (lambda (device)
2098 (define requirement
2099 (if (string-prefix? "/dev/mapper/" device)
2100 (list (symbol-append 'device-mapping-
2101 (string->symbol (basename device))))
2102 '()))
2103
d4053c71 2104 (shepherd-service
0adfe95a
LC
2105 (provision (list (symbol-append 'swap- (string->symbol device))))
2106 (requirement `(udev ,@requirement))
2107 (documentation "Enable the given swap device.")
2108 (start #~(lambda ()
2109 (restart-on-EINTR (swapon #$device))
2110 #t))
2111 (stop #~(lambda _
2112 (restart-on-EINTR (swapoff #$device))
2113 #f))
2114 (respawn? #f)))))
5dae0186 2115
2a13d05e
LC
2116(define (swap-service device)
2117 "Return a service that uses @var{device} as a swap device."
0adfe95a 2118 (service swap-service-type device))
2a13d05e 2119
5986e941
LC
2120(define %default-gpm-options
2121 ;; Default options for GPM.
2122 '("-m" "/dev/input/mice" "-t" "ps2"))
2123
8664cc88
LC
2124(define-record-type* <gpm-configuration>
2125 gpm-configuration make-gpm-configuration gpm-configuration?
5986e941
LC
2126 (gpm gpm-configuration-gpm ;package
2127 (default gpm))
2128 (options gpm-configuration-options ;list of strings
2129 (default %default-gpm-options)))
8664cc88 2130
d4053c71 2131(define gpm-shepherd-service
8664cc88 2132 (match-lambda
a907d997 2133 (($ <gpm-configuration> gpm options)
d4053c71 2134 (list (shepherd-service
8664cc88
LC
2135 (requirement '(udev))
2136 (provision '(gpm))
2137 (start #~(lambda ()
2138 ;; 'gpm' runs in the background and sets a PID file.
2139 ;; Note that it requires running as "root".
2140 (false-if-exception (delete-file "/var/run/gpm.pid"))
9fc037fe 2141 (fork+exec-command (list #$(file-append gpm "/sbin/gpm")
8664cc88
LC
2142 #$@options))
2143
2144 ;; Wait for the PID file to appear; declare failure if
2145 ;; it doesn't show up.
2146 (let loop ((i 3))
2147 (or (file-exists? "/var/run/gpm.pid")
2148 (if (zero? i)
2149 #f
2150 (begin
2151 (sleep 1)
2152 (loop (1- i))))))))
2153
2154 (stop #~(lambda (_)
2155 ;; Return #f if successfully stopped.
9fc037fe 2156 (not (zero? (system* #$(file-append gpm "/sbin/gpm")
8664cc88
LC
2157 "-k"))))))))))
2158
2159(define gpm-service-type
2160 (service-type (name 'gpm)
2161 (extensions
d4053c71 2162 (list (service-extension shepherd-root-service-type
6b9e1fef 2163 gpm-shepherd-service)))
5986e941 2164 (default-value (gpm-configuration))
6b9e1fef
LC
2165 (description
2166 "Run GPM, the general-purpose mouse daemon, with the given
2167command-line options. GPM allows users to use the mouse in the console,
2168notably to select, copy, and paste text. The default options use the
2169@code{ps2} protocol, which works for both USB and PS/2 mice.")))
8664cc88 2170
65a67bf7
LC
2171(define-deprecated (gpm-service #:key (gpm gpm)
2172 (options %default-gpm-options))
2173 gpm-service-type
8664cc88
LC
2174 "Run @var{gpm}, the general-purpose mouse daemon, with the given
2175command-line @var{options}. GPM allows users to use the mouse in the console,
2176notably to select, copy, and paste text. The default value of @var{options}
2177uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
2178
2179This service is not part of @var{%base-services}."
2180 ;; To test in QEMU, use "-usbdevice mouse" and then, in the monitor, use
2181 ;; "info mice" and "mouse_set X" to use the right mouse.
2182 (service gpm-service-type
2183 (gpm-configuration (gpm gpm) (options options))))
2184
46ec2707
DC
2185(define-record-type* <kmscon-configuration>
2186 kmscon-configuration make-kmscon-configuration
2187 kmscon-configuration?
2188 (kmscon kmscon-configuration-kmscon
2189 (default kmscon))
2190 (virtual-terminal kmscon-configuration-virtual-terminal)
2191 (login-program kmscon-configuration-login-program
9fc037fe 2192 (default (file-append shadow "/bin/login")))
46ec2707
DC
2193 (login-arguments kmscon-configuration-login-arguments
2194 (default '("-p")))
2d9dace8
MO
2195 (auto-login kmscon-configuration-auto-login
2196 (default #f))
46ec2707
DC
2197 (hardware-acceleration? kmscon-configuration-hardware-acceleration?
2198 (default #f))) ; #t causes failure
2199
2200(define kmscon-service-type
2201 (shepherd-service-type
2202 'kmscon
2203 (lambda (config)
2204 (let ((kmscon (kmscon-configuration-kmscon config))
2205 (virtual-terminal (kmscon-configuration-virtual-terminal config))
2206 (login-program (kmscon-configuration-login-program config))
2207 (login-arguments (kmscon-configuration-login-arguments config))
2d9dace8 2208 (auto-login (kmscon-configuration-auto-login config))
46ec2707
DC
2209 (hardware-acceleration? (kmscon-configuration-hardware-acceleration? config)))
2210
2211 (define kmscon-command
2212 #~(list
9fc037fe 2213 #$(file-append kmscon "/bin/kmscon") "--login"
46ec2707 2214 "--vt" #$virtual-terminal
f4e8bc5f 2215 "--no-switchvt" ;Prevent a switch to the virtual terminal.
46ec2707 2216 #$@(if hardware-acceleration? '("--hwaccel") '())
2d9dace8
MO
2217 "--login" "--"
2218 #$login-program #$@login-arguments
2219 #$@(if auto-login
2220 #~(#$auto-login)
2221 #~())))
46ec2707
DC
2222
2223 (shepherd-service
2224 (documentation "kmscon virtual terminal")
76421cf0 2225 (requirement '(user-processes udev dbus-system))
46ec2707
DC
2226 (provision (list (symbol-append 'term- (string->symbol virtual-terminal))))
2227 (start #~(make-forkexec-constructor #$kmscon-command))
2228 (stop #~(make-kill-destructor)))))))
2229
c9436025
DM
2230(define-record-type* <static-networking>
2231 static-networking make-static-networking
2232 static-networking?
2233 (interface static-networking-interface)
2234 (ip static-networking-ip)
2235 (netmask static-networking-netmask
2236 (default #f))
2237 (gateway static-networking-gateway ;FIXME: doesn't belong here
2238 (default #f))
2239 (provision static-networking-provision
2240 (default #f))
2241 (requirement static-networking-requirement
2242 (default '()))
2243 (name-servers static-networking-name-servers ;FIXME: doesn't belong here
2244 (default '())))
2245
2246(define static-networking-shepherd-service
2247 (match-lambda
2248 (($ <static-networking> interface ip netmask gateway provision
2249 requirement name-servers)
2250 (let ((loopback? (and provision (memq 'loopback provision))))
2251 (shepherd-service
2252
2253 (documentation
2254 "Bring up the networking interface using a static IP address.")
2255 (requirement requirement)
2256 (provision (or provision
2257 (list (symbol-append 'networking-
2258 (string->symbol interface)))))
2259
2260 (start #~(lambda _
2261 ;; Return #t if successfully started.
2262 (let* ((addr (inet-pton AF_INET #$ip))
2263 (sockaddr (make-socket-address AF_INET addr 0))
2264 (mask (and #$netmask
2265 (inet-pton AF_INET #$netmask)))
2266 (maskaddr (and mask
2267 (make-socket-address AF_INET
2268 mask 0)))
2269 (gateway (and #$gateway
2270 (inet-pton AF_INET #$gateway)))
2271 (gatewayaddr (and gateway
2272 (make-socket-address AF_INET
2273 gateway 0))))
2274 (configure-network-interface #$interface sockaddr
2275 (logior IFF_UP
2276 #$(if loopback?
2277 #~IFF_LOOPBACK
2278 0))
2279 #:netmask maskaddr)
2280 (when gateway
2281 (let ((sock (socket AF_INET SOCK_DGRAM 0)))
2282 (add-network-route/gateway sock gatewayaddr)
2283 (close-port sock))))))
2284 (stop #~(lambda _
2285 ;; Return #f is successfully stopped.
2286 (let ((sock (socket AF_INET SOCK_STREAM 0)))
2287 (when #$gateway
2288 (delete-network-route sock
2289 (make-socket-address
2290 AF_INET INADDR_ANY 0)))
2291 (set-network-interface-flags sock #$interface 0)
2292 (close-port sock)
241358dc 2293 #f)))
c9436025
DM
2294 (respawn? #f))))))
2295
2296(define (static-networking-etc-files interfaces)
2297 "Return a /etc/resolv.conf entry for INTERFACES or the empty list."
2298 (match (delete-duplicates
2299 (append-map static-networking-name-servers
2300 interfaces))
2301 (()
2302 '())
2303 ((name-servers ...)
2304 (let ((content (string-join
2305 (map (cut string-append "nameserver " <>)
2306 name-servers)
2307 "\n" 'suffix)))
2308 `(("resolv.conf"
2309 ,(plain-file "resolv.conf"
2310 (string-append "\
2311# Generated by 'static-networking-service'.\n"
2312 content))))))))
2313
2314(define (static-networking-shepherd-services interfaces)
2315 "Return the list of Shepherd services to bring up INTERFACES, a list of
2316<static-networking> objects."
2317 (define (loopback? service)
2318 (memq 'loopback (shepherd-service-provision service)))
2319
2320 (let ((services (map static-networking-shepherd-service interfaces)))
2321 (match (remove loopback? services)
2322 (()
2323 ;; There's no interface other than 'loopback', so we assume that the
2324 ;; 'networking' service will be provided by dhclient or similar.
2325 services)
2326 ((non-loopback ...)
2327 ;; Assume we're providing all the interfaces, and thus, provide a
2328 ;; 'networking' service.
2329 (cons (shepherd-service
2330 (provision '(networking))
2331 (requirement (append-map shepherd-service-provision
2332 services))
2333 (start #~(const #t))
2334 (stop #~(const #f))
2335 (documentation "Bring up all the networking interfaces."))
2336 services)))))
2337
2338(define static-networking-service-type
2339 ;; The service type for statically-defined network interfaces.
2340 (service-type (name 'static-networking)
2341 (extensions
2342 (list
2343 (service-extension shepherd-root-service-type
2344 static-networking-shepherd-services)
2345 (service-extension etc-service-type
2346 static-networking-etc-files)))
2347 (compose concatenate)
2348 (extend append)
2349 (description
2350 "Turn up the specified network interfaces upon startup,
2351with the given IP address, gateway, netmask, and so on. The value for
2352services of this type is a list of @code{static-networking} objects, one per
2353network interface.")))
2354
2355(define* (static-networking-service interface ip
2356 #:key
2357 netmask gateway provision
2358 ;; Most interfaces require udev to be usable.
2359 (requirement '(udev))
2360 (name-servers '()))
2361 "Return a service that starts @var{interface} with address @var{ip}. If
2362@var{netmask} is true, use it as the network mask. If @var{gateway} is true,
2363it must be a string specifying the default network gateway.
2364
2365This procedure can be called several times, one for each network
2366interface of interest. Behind the scenes what it does is extend
2367@code{static-networking-service-type} with additional network interfaces
2368to handle."
2369 (simple-service 'static-network-interface
2370 static-networking-service-type
2371 (list (static-networking (interface interface) (ip ip)
2372 (netmask netmask) (gateway gateway)
2373 (provision provision)
2374 (requirement requirement)
2375 (name-servers name-servers)))))
2376
8664cc88 2377\f
8b198abe
LC
2378(define %base-services
2379 ;; Convenience variable holding the basic services.
178bce41 2380 (list (service login-service-type)
317d3b47 2381
bb3062ad 2382 (service virtual-terminal-service-type)
4a84a487
LC
2383 (service console-font-service-type
2384 (map (lambda (tty)
2385 (cons tty %default-console-font))
2386 '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
317d3b47 2387
76a2b2db
EF
2388 (service agetty-service-type (agetty-configuration
2389 (extra-options '("-L")) ; no carrier detect
2390 (term "vt100")
2391 (tty #f))) ; automatic
2392
2393 (service mingetty-service-type (mingetty-configuration
2394 (tty "tty1")))
2395 (service mingetty-service-type (mingetty-configuration
2396 (tty "tty2")))
2397 (service mingetty-service-type (mingetty-configuration
2398 (tty "tty3")))
2399 (service mingetty-service-type (mingetty-configuration
2400 (tty "tty4")))
2401 (service mingetty-service-type (mingetty-configuration
2402 (tty "tty5")))
2403 (service mingetty-service-type (mingetty-configuration
2404 (tty "tty6")))
317d3b47 2405
8de3e4b3
LC
2406 (service static-networking-service-type
2407 (list (static-networking (interface "lo")
2408 (ip "127.0.0.1")
db8ed7ce 2409 (requirement '())
8de3e4b3 2410 (provision '(loopback)))))
317d3b47 2411 (syslog-service)
8faaf8d7 2412 (service urandom-seed-service-type)
7194745a 2413 (service guix-service-type)
db903549 2414 (service nscd-service-type)
317d3b47 2415
0468455e
LC
2416 (service rottlog-service-type)
2417
317d3b47
DC
2418 ;; The LVM2 rules are needed as soon as LVM2 or the device-mapper is
2419 ;; used, so enable them by default. The FUSE and ALSA rules are
2420 ;; less critical, but handy.
fd779db9
EF
2421 (service udev-service-type
2422 (udev-configuration
2423 (rules (list lvm2 fuse alsa-utils crda))))
387e1754
LC
2424
2425 (service special-files-service-type
dfc8ccbf
MO
2426 `(("/bin/sh" ,(file-append bash "/bin/sh"))
2427 ("/usr/bin/env" ,(file-append coreutils "/bin/env"))))))
8b198abe 2428
db4fdc04 2429;;; base.scm ends here