1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu services base)
21 #:use-module (guix store)
22 #:use-module (gnu services)
23 #:use-module (gnu services networking)
24 #:use-module (gnu system shadow) ; 'user-account', etc.
25 #:use-module (gnu system linux) ; 'pam-service', etc.
26 #:use-module (gnu packages admin)
27 #:use-module ((gnu packages linux)
28 #:select (eudev kbd e2fsprogs lvm2 fuse alsa-utils))
29 #:use-module ((gnu packages base)
30 #:select (canonical-package glibc))
31 #:use-module (gnu packages package-management)
32 #:use-module (gnu packages lsh)
33 #:use-module (gnu packages lsof)
34 #:use-module ((gnu build file-systems)
35 #:select (mount-flags->bit-mask))
36 #:use-module (guix gexp)
37 #:use-module (guix monads)
38 #:use-module (guix records)
39 #:use-module (srfi srfi-1)
40 #:use-module (srfi srfi-26)
41 #:use-module (ice-9 match)
42 #:use-module (ice-9 format)
43 #:export (root-file-system-service
46 device-mapping-service
48 user-processes-service
50 console-keymap-service
56 %nscd-default-configuration
71 ;;; Base system services---i.e., services that 99% of the users will want to
76 (define (root-file-system-service)
77 "Return a service whose sole purpose is to re-mount read-only the root file
78 system upon shutdown (aka. cleanly \"umounting\" root.)
80 This service must be the root of the service dependency graph so that its
81 'stop' action is invoked when dmd is the only process left."
82 (with-monad %store-monad
85 (documentation "Take care of the root file system.")
86 (provision '(root-file-system))
89 ;; Return #f if successfully stopped.
92 (call-with-blocked-asyncs
94 (let ((null (%make-void-port "w")))
96 (display "closing log\n")
97 ;; XXX: Ideally we'd use 'stop-logging', but that one
98 ;; doesn't actually close the port as of dmd 0.1.
99 (close-port (@@ (dmd comm) log-output-port))
100 (set! (@@ (dmd comm) log-output-port) null)
102 ;; Redirect the default output ports..
103 (set-current-output-port null)
104 (set-current-error-port null)
106 ;; Close /dev/console.
107 (for-each close-fdes '(0 1 2))
109 ;; At this point, there are no open files left, so the
110 ;; root file system can be re-mounted read-only.
112 (logior MS_REMOUNT MS_RDONLY)
118 (define* (file-system-service device target type
119 #:key (flags '()) (check? #t)
120 create-mount-point? options (title 'any)
122 "Return a service that mounts DEVICE on TARGET as a file system TYPE with
123 OPTIONS. TITLE is a symbol specifying what kind of name DEVICE is: 'label for
124 a partition label, 'device for a device file name, or 'any. When CHECK? is
125 true, check the file system before mounting it. When CREATE-MOUNT-POINT? is
126 true, create TARGET if it does not exist yet. FLAGS is a list of symbols,
127 such as 'read-only' etc. Optionally, REQUIREMENTS may be a list of service
128 names such as device-mapping services."
129 (with-monad %store-monad
132 (provision (list (symbol-append 'file-system- (string->symbol target))))
133 (requirement `(root-file-system ,@requirements))
134 (documentation "Check, mount, and unmount the given file system.")
135 (start #~(lambda args
136 ;; FIXME: Use or factorize with 'mount-file-system'.
137 (let ((device (canonicalize-device-spec #$device '#$title))
138 (flags #$(mount-flags->bit-mask flags)))
139 #$(if create-mount-point?
144 ;; Make sure fsck.ext2 & co. can be found.
148 "/run/current-system/profile/sbin:"
150 (check-file-system device #$type))
153 (mount device #$target #$type flags #$options)
155 ;; For read-only bind mounts, an extra remount is needed,
156 ;; as per <http://lwn.net/Articles/281157/>, which still
157 ;; applies to Linux 4.0.
158 (when (and (= MS_BIND (logand flags MS_BIND))
159 (= MS_RDONLY (logand flags MS_RDONLY)))
160 (mount device #$target #$type
161 (logior MS_BIND MS_REMOUNT MS_RDONLY))))
164 ;; Normally there are no processes left at this point, so
165 ;; TARGET can be safely unmounted.
167 ;; Make sure PID 1 doesn't keep TARGET busy.
173 (define (user-unmount-service known-mount-points)
174 "Return a service whose sole purpose is to unmount file systems not listed
175 in KNOWN-MOUNT-POINTS when it is stopped."
176 (with-monad %store-monad
179 (documentation "Unmount manually-mounted file systems.")
180 (provision '(user-unmount))
183 (define (known? mount-point)
185 (cons* "/proc" "/sys"
186 '#$known-mount-points)))
188 ;; Make sure we don't keep the user's mount points busy.
191 (for-each (lambda (mount-point)
192 (format #t "unmounting '~a'...~%" mount-point)
195 (umount mount-point))
197 (let ((errno (system-error-errno args)))
198 (format #t "failed to unmount '~a': ~a~%"
199 mount-point (strerror errno))))))
200 (filter (negate known?) (mount-points)))
203 (define %do-not-kill-file
204 ;; Name of the file listing PIDs of processes that must survive when halting
205 ;; the system. Typical example is user-space file systems.
206 "/etc/dmd/do-not-kill")
208 (define* (user-processes-service requirements #:key (grace-delay 4))
209 "Return the service that is responsible for terminating all the processes so
210 that the root file system can be re-mounted read-only, just before
211 rebooting/halting. Processes still running GRACE-DELAY seconds after SIGTERM
212 has been sent are terminated with SIGKILL.
214 The returned service will depend on 'root-file-system' and on all the services
215 listed in REQUIREMENTS.
217 All the services that spawn processes must depend on this one so that they are
218 stopped before 'kill' is called."
219 (with-monad %store-monad
221 (documentation "When stopped, terminate all user processes.")
222 (provision '(user-processes))
223 (requirement (cons 'root-file-system requirements))
226 (define (kill-except omit signal)
227 ;; Kill all the processes with SIGNAL except those
228 ;; listed in OMIT and the current process.
229 (let ((omit (cons (getpid) omit)))
230 (for-each (lambda (pid)
231 (unless (memv pid omit)
237 ;; List of PIDs that must not be killed.
238 (if (file-exists? #$%do-not-kill-file)
240 (call-with-input-file #$%do-not-kill-file
241 (compose string-tokenize
242 (@ (ice-9 rdelim) read-string))))
246 (car (gettimeofday)))
249 ;; Really sleep N seconds.
250 ;; Work around <http://bugs.gnu.org/19581>.
252 (let loop ((elapsed 0))
254 (sleep (- n elapsed))
255 (loop (- (now) start)))))
257 (define lset= (@ (srfi srfi-1) lset=))
259 (display "sending all processes the TERM signal\n")
261 (if (null? omitted-pids)
263 ;; Easy: terminate all of them.
265 (sleep* #$grace-delay)
268 ;; Kill them all except OMITTED-PIDS. XXX: We
269 ;; would like to (kill -1 SIGSTOP) to get a fixed
270 ;; list of processes, like 'killall5' does, but
271 ;; that seems unreliable.
272 (kill-except omitted-pids SIGTERM)
273 (sleep* #$grace-delay)
274 (kill-except omitted-pids SIGKILL)
275 (delete-file #$%do-not-kill-file)))
278 (let ((pids (processes)))
279 (unless (lset= = pids (cons 1 omitted-pids))
280 (format #t "waiting for process termination\
281 (processes left: ~s)~%"
286 (display "all processes have been terminated\n")
290 (define (host-name-service name)
291 "Return a service that sets the host name to @var{name}."
292 (with-monad %store-monad
294 (documentation "Initialize the machine's host name.")
295 (provision '(host-name))
297 (sethostname #$name)))
300 (define (unicode-start tty)
301 "Return a gexp to start Unicode support on @var{tty}."
303 ;; We have to run 'unicode_start' in a pipe so that when it invokes the
304 ;; 'tty' command, that command returns TTY.
306 (let ((pid (primitive-fork)))
310 (dup2 (open-fdes #$tty O_RDONLY) 0)
312 (dup2 (open-fdes #$tty O_WRONLY) 1)
313 (execl (string-append #$kbd "/bin/unicode_start")
316 (zero? (cdr (waitpid pid))))))))
318 (define (console-keymap-service file)
319 "Return a service to load console keymap from @var{file}."
320 (with-monad %store-monad
324 (string-append "Load console keymap (loadkeys)."))
325 (provision '(console-keymap))
327 (zero? (system* (string-append #$kbd "/bin/loadkeys")
331 (define* (console-font-service tty #:optional (font "LatGrkCyr-8x16"))
332 "Return a service that sets up Unicode support in @var{tty} and loads
333 @var{font} for that tty (fonts are per virtual console in Linux.)"
334 ;; Note: 'LatGrkCyr-8x16' has the advantage of providing three common
335 ;; scripts as well as glyphs for em dash, quotation marks, and other Unicode
336 ;; codepoints notably found in the UTF-8 manual.
337 (let ((device (string-append "/dev/" tty)))
338 (with-monad %store-monad
340 (documentation "Load a Unicode console font.")
341 (provision (list (symbol-append 'console-font-
342 (string->symbol tty))))
344 ;; Start after mingetty has been started on TTY, otherwise the
345 ;; settings are ignored.
346 (requirement (list (symbol-append 'term-
347 (string->symbol tty))))
350 (and #$(unicode-start device)
352 (system* (string-append #$kbd "/bin/setfont")
353 "-C" #$device #$font)))))
357 (define* (mingetty-service tty
359 (motd (text-file "motd" "Welcome.\n"))
364 ;; Allow empty passwords by default so that
365 ;; first-time users can log in when the 'root'
366 ;; account has just been created.
367 (allow-empty-passwords? #t))
368 "Return a service to run mingetty on @var{tty}.
370 When @var{allow-empty-passwords?} is true, allow empty log-in password. When
371 @var{auto-login} is true, it must be a user name under which to log-in
372 automatically. @var{login-pause?} can be set to @code{#t} in conjunction with
373 @var{auto-login}, in which case the user will have to press a key before the
374 login shell is launched.
376 When true, @var{login-program} is a gexp or a monadic gexp denoting the name
377 of the log-in program (the default is the @code{login} program from the Shadow
380 @var{motd} is a monadic value containing a text file to use as
381 the ``message of the day''."
382 (mlet %store-monad ((motd motd)
383 (login-program (cond ((gexp? login-program)
384 (return login-program))
391 (documentation (string-append "Run mingetty on " tty "."))
392 (provision (list (symbol-append 'term- (string->symbol tty))))
394 ;; Since the login prompt shows the host name, wait for the 'host-name'
395 ;; service to be done. Also wait for udev essentially so that the tty
396 ;; text is not lost in the middle of kernel messages (XXX).
397 (requirement '(user-processes host-name udev))
399 (start #~(make-forkexec-constructor
400 (list (string-append #$mingetty "/sbin/mingetty")
403 #~("--autologin" #$auto-login)
406 #~("--loginprog" #$login-program)
411 (stop #~(make-kill-destructor))
414 ;; Let 'login' be known to PAM. All the mingetty services will have
415 ;; that PAM service, but that's fine because they're all identical and
416 ;; duplicates are removed.
417 (list (unix-pam-service "login"
418 #:allow-empty-passwords? allow-empty-passwords?
421 (define-record-type* <nscd-configuration> nscd-configuration
422 make-nscd-configuration
424 (log-file nscd-configuration-log-file ;string
425 (default "/var/log/nscd.log"))
426 (debug-level nscd-debug-level ;integer
428 ;; TODO: See nscd.conf in glibc for other options to add.
429 (caches nscd-configuration-caches ;list of <nscd-cache>
430 (default %nscd-default-caches)))
432 (define-record-type* <nscd-cache> nscd-cache make-nscd-cache
434 (database nscd-cache-database) ;symbol
435 (positive-time-to-live nscd-cache-positive-time-to-live) ;integer
436 (negative-time-to-live nscd-cache-negative-time-to-live
437 (default 20)) ;integer
438 (suggested-size nscd-cache-suggested-size ;integer ("default module
441 (check-files? nscd-cache-check-files? ;Boolean
443 (persistent? nscd-cache-persistent? ;Boolean
445 (shared? nscd-cache-shared? ;Boolean
447 (max-database-size nscd-cache-max-database-size ;integer
448 (default (* 32 (expt 2 20))))
449 (auto-propagate? nscd-cache-auto-propagate? ;Boolean
452 (define %nscd-default-caches
453 ;; Caches that we want to enable by default. Note that when providing an
454 ;; empty nscd.conf, all caches are disabled.
455 (list (nscd-cache (database 'hosts)
457 ;; Aggressively cache the host name cache to improve
458 ;; privacy and resilience.
459 (positive-time-to-live (* 3600 12))
460 (negative-time-to-live 20)
463 (nscd-cache (database 'services)
465 ;; Services are unlikely to change, so we can be even more
467 (positive-time-to-live (* 3600 24))
468 (negative-time-to-live 3600)
469 (check-files? #t) ;check /etc/services changes
472 (define %nscd-default-configuration
473 ;; Default nscd configuration.
474 (nscd-configuration))
476 (define (nscd.conf-file config)
477 "Return the @file{nscd.conf} configuration file for @var{config}, an
478 @code{<nscd-configuration>} object."
479 (define cache->config
481 (($ <nscd-cache> (= symbol->string database)
482 positive-ttl negative-ttl size check-files?
483 persistent? shared? max-size propagate?)
484 (string-append "\nenable-cache\t" database "\tyes\n"
486 "positive-time-to-live\t" database "\t"
487 (number->string positive-ttl) "\n"
488 "negative-time-to-live\t" database "\t"
489 (number->string negative-ttl) "\n"
490 "suggested-size\t" database "\t"
491 (number->string size) "\n"
492 "check-files\t" database "\t"
493 (if check-files? "yes\n" "no\n")
494 "persistent\t" database "\t"
495 (if persistent? "yes\n" "no\n")
496 "shared\t" database "\t"
497 (if shared? "yes\n" "no\n")
498 "max-db-size\t" database "\t"
499 (number->string max-size) "\n"
500 "auto-propagate\t" database "\t"
501 (if propagate? "yes\n" "no\n")))))
504 (($ <nscd-configuration> log-file debug-level caches)
505 (text-file "nscd.conf"
507 # Configuration of libc's name service cache daemon (nscd).\n\n"
509 (string-append "logfile\t" log-file)
513 (string-append "debug-level\t"
514 (number->string debug-level))
518 (map cache->config caches)))))))
520 (define* (nscd-service #:optional (config %nscd-default-configuration)
521 #:key (glibc (canonical-package glibc))
523 "Return a service that runs libc's name service cache daemon (nscd) with the
524 given @var{config}---an @code{<nscd-configuration>} object. Optionally,
525 @code{#:name-services} is a list of packages that provide name service switch
526 (NSS) modules needed by nscd. @xref{Name Service Switch}, for an example."
527 (mlet %store-monad ((nscd.conf (nscd.conf-file config)))
529 (documentation "Run libc's name service cache daemon (nscd).")
531 (requirement '(user-processes))
534 (use-modules (guix build utils))
535 (mkdir-p "/var/run/nscd")
536 (mkdir-p "/var/db/nscd"))) ;for the persistent cache
538 (start #~(make-forkexec-constructor
539 (list (string-append #$glibc "/sbin/nscd")
540 "-f" #$nscd.conf "--foreground")
542 #:environment-variables
543 (list (string-append "LD_LIBRARY_PATH="
546 (string-append dir "/lib"))
547 (list #$@name-services))
549 (stop #~(make-kill-destructor))
553 (define* (syslog-service #:key config-file)
554 "Return a service that runs @code{syslogd}.
555 If configuration file name @var{config-file} is not specified, use some
556 reasonable default settings."
558 ;; Snippet adapted from the GNU inetutils manual.
560 # Log all error messages, authentication messages of
561 # level notice or higher and anything of level err or
562 # higher to the console.
563 # Don't log private authentication messages!
564 *.alert;auth.notice;authpriv.none /dev/console
566 # Log anything (except mail) of level info or higher.
567 # Don't log private authentication messages!
568 *.info;mail.none;authpriv.none /var/log/messages
570 # Same, in a different place.
571 *.info;mail.none;authpriv.none /dev/tty12
573 # The authpriv file has restricted access.
574 authpriv.* /var/log/secure
576 # Log all the mail messages in one place.
577 mail.* /var/log/maillog
581 ((syslog.conf (text-file "syslog.conf" contents)))
584 (documentation "Run the syslog daemon (syslogd).")
585 (provision '(syslogd))
586 (requirement '(user-processes))
588 #~(make-forkexec-constructor
589 (list (string-append #$inetutils "/libexec/syslogd")
590 "--no-detach" "--rcfile" #$(or config-file syslog.conf))))
591 (stop #~(make-kill-destructor))))))
593 (define* (guix-build-accounts count #:key
597 "Return a list of COUNT user accounts for Guix build users, with UIDs
598 starting at FIRST-UID, and under GID."
599 (unfold (cut > <> count)
602 (name (format #f "guixbuilder~2,'0d" n))
604 (uid (+ first-uid n -1))
607 ;; guix-daemon expects GROUP to be listed as a
608 ;; supplementary group too:
609 ;; <http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html>.
610 (supplementary-groups (list group "kvm"))
612 (comment (format #f "Guix Build User ~2d" n))
613 (home-directory "/var/empty")
614 (shell #~(string-append #$shadow "/sbin/nologin"))))
618 (define (hydra-key-authorization guix)
619 "Return a gexp with code to register the hydra.gnu.org public key with
621 #~(unless (file-exists? "/etc/guix/acl")
622 (let ((pid (primitive-fork)))
625 (let* ((key (string-append #$guix
626 "/share/guix/hydra.gnu.org.pub"))
627 (port (open-file key "r0b")))
628 (format #t "registering public key '~a'...~%" key)
629 (close-port (current-input-port))
631 (execl (string-append #$guix "/bin/guix")
632 "guix" "archive" "--authorize")
635 (let ((status (cdr (waitpid pid))))
636 (unless (zero? status)
637 (format (current-error-port) "warning: \
638 failed to register hydra.gnu.org public key: ~a~%" status))))))))
640 (define* (guix-service #:key (guix guix) (builder-group "guixbuild")
641 (build-accounts 10) (authorize-hydra-key? #t)
642 (use-substitutes? #t)
644 (lsof lsof) (lsh lsh))
645 "Return a service that runs the build daemon from @var{guix}, and has
646 @var{build-accounts} user accounts available under @var{builder-group}.
648 When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key
649 provided by @var{guix} is authorized upon activation, meaning that substitutes
650 from @code{hydra.gnu.org} are used by default.
652 If @var{use-substitutes?} is false, the daemon is run with
653 @option{--no-substitutes} (@pxref{Invoking guix-daemon,
654 @option{--no-substitutes}}).
656 Finally, @var{extra-options} is a list of additional command-line options
657 passed to @command{guix-daemon}."
659 ;; Assume that the store has BUILDER-GROUP as its group. We could
660 ;; otherwise call 'chown' here, but the problem is that on a COW unionfs,
661 ;; chown leads to an entire copy of the tree, which is a bad idea.
663 ;; Optionally authorize hydra.gnu.org's key.
664 (and authorize-hydra-key?
665 (hydra-key-authorization guix)))
667 (with-monad %store-monad
669 (documentation "Run the Guix daemon.")
670 (provision '(guix-daemon))
671 (requirement '(user-processes))
673 #~(make-forkexec-constructor
674 (list (string-append #$guix "/bin/guix-daemon")
675 "--build-users-group" #$builder-group
676 #$@(if use-substitutes?
678 '("--no-substitutes"))
681 ;; Add 'lsof' (for the GC) and 'lsh' (for offloading) to the
683 #:environment-variables
684 (list (string-append "PATH=" #$lsof "/bin:"
686 (stop #~(make-kill-destructor))
687 (user-accounts (guix-build-accounts build-accounts
688 #:group builder-group))
689 (user-groups (list (user-group
693 ;; Use a fixed GID so that we can create the
694 ;; store with the right owner.
696 (activate activate)))))
698 (define (udev-rules-union packages)
699 "Return the union of the @code{lib/udev/rules.d} directories found in each
700 item of @var{packages}."
703 (use-modules (guix build union)
708 (define %standard-locations
709 '("/lib/udev/rules.d" "/libexec/udev/rules.d"))
711 (define (rules-sub-directory directory)
712 ;; Return the sub-directory of DIRECTORY containing udev rules, or
713 ;; #f if none was found.
714 (find directory-exists?
715 (map (cut string-append directory <>) %standard-locations)))
717 (mkdir-p (string-append #$output "/lib/udev"))
718 (union-build (string-append #$output "/lib/udev/rules.d")
719 (filter-map rules-sub-directory '#$packages))))
721 (gexp->derivation "udev-rules" build
722 #:modules '((guix build union)
726 (define* (kvm-udev-rule)
727 "Return a directory with a udev rule that changes the group of
728 @file{/dev/kvm} to \"kvm\" and makes it #o660."
729 ;; Apparently QEMU-KVM used to ship this rule, but now we have to add it by
731 (gexp->derivation "kvm-udev-rules"
733 (use-modules (guix build utils))
736 (string-append #$output "/lib/udev/rules.d"))
739 (call-with-output-file
740 (string-append rules.d "/90-kvm.rules")
742 ;; FIXME: As a workaround for
743 ;; <http://bugs.gnu.org/18994>, make /dev/kvm 666
746 KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0666\"\n" port))))
747 #:modules '((guix build utils))))
749 (define* (udev-service #:key (udev eudev) (rules '()))
750 "Run @var{udev}, which populates the @file{/dev} directory dynamically. Get
751 extra rules from the packages listed in @var{rules}."
752 (mlet* %store-monad ((kvm (kvm-udev-rule))
753 (rules (udev-rules-union (cons* udev kvm rules)))
754 (udev.conf (text-file* "udev.conf"
755 "udev_rules=\"" rules
756 "/lib/udev/rules.d\"\n")))
760 ;; Udev needs /dev to be a 'devtmpfs' mount so that new device
761 ;; nodes can be added: see
762 ;; <http://www.linuxfromscratch.org/lfs/view/development/chapter07/udev.html>.
763 (requirement '(root-file-system))
765 (documentation "Populate the /dev directory, dynamically.")
768 (@ (srfi srfi-1) find))
771 ;; Choose the right 'udevd'.
773 (map (lambda (suffix)
774 (string-append #$udev suffix))
775 '("/libexec/udev/udevd" ;udev
776 "/sbin/udevd")))) ;eudev
778 (define (wait-for-udevd)
779 ;; Wait until someone's listening on udevd's control
781 (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0)))
785 (connect sock PF_UNIX "/run/udev/control")
788 (format #t "waiting for udevd...~%")
792 ;; Allow udev to find the modules.
793 (setenv "LINUX_MODULE_DIRECTORY"
794 "/run/booted-system/kernel/lib/modules")
796 ;; The first one is for udev, the second one for eudev.
797 (setenv "UDEV_CONFIG_FILE" #$udev.conf)
798 (setenv "EUDEV_RULES_DIRECTORY"
799 (string-append #$rules "/lib/udev/rules.d"))
801 (let ((pid (primitive-fork)))
804 (exec-command (list udevd)))
806 ;; Wait until udevd is up and running. This
807 ;; appears to be needed so that the events
808 ;; triggered below are actually handled.
811 ;; Trigger device node creation.
812 (system* (string-append #$udev "/bin/udevadm")
813 "trigger" "--action=add")
815 ;; Wait for things to settle down.
816 (system* (string-append #$udev "/bin/udevadm")
819 (stop #~(make-kill-destructor))
821 ;; When halting the system, 'udev' is actually killed by
822 ;; 'user-processes', i.e., before its own 'stop' method was
823 ;; called. Thus, make sure it is not respawned.
826 (define (device-mapping-service target open close)
827 "Return a service that maps device @var{target}, a string such as
828 @code{\"home\"} (meaning @code{/dev/mapper/home}). Evaluate @var{open}, a
829 gexp, to open it, and evaluate @var{close} to close it."
830 (with-monad %store-monad
832 (provision (list (symbol-append 'device-mapping-
833 (string->symbol target))))
834 (requirement '(udev))
835 (documentation "Map a device node using Linux's device mapper.")
836 (start #~(lambda () #$open))
837 (stop #~(lambda _ (not #$close)))
840 (define (swap-service device)
841 "Return a service that uses @var{device} as a swap device."
843 (if (string-prefix? "/dev/mapper/" device)
844 (list (symbol-append 'device-mapping-
845 (string->symbol (basename device))))
848 (with-monad %store-monad
850 (provision (list (symbol-append 'swap- (string->symbol device))))
851 (requirement `(udev ,@requirement))
852 (documentation "Enable the given swap device.")
854 (restart-on-EINTR (swapon #$device))
857 (restart-on-EINTR (swapoff #$device))
861 (define %base-services
862 ;; Convenience variable holding the basic services.
863 (let ((motd (text-file "motd" "
864 This is the GNU operating system, welcome!\n\n")))
865 (list (console-font-service "tty1")
866 (console-font-service "tty2")
867 (console-font-service "tty3")
868 (console-font-service "tty4")
869 (console-font-service "tty5")
870 (console-font-service "tty6")
872 (mingetty-service "tty1" #:motd motd)
873 (mingetty-service "tty2" #:motd motd)
874 (mingetty-service "tty3" #:motd motd)
875 (mingetty-service "tty4" #:motd motd)
876 (mingetty-service "tty5" #:motd motd)
877 (mingetty-service "tty6" #:motd motd)
878 (static-networking-service "lo" "127.0.0.1"
879 #:provision '(loopback))
884 ;; The LVM2 rules are needed as soon as LVM2 or the device-mapper is
885 ;; used, so enable them by default. The FUSE and ALSA rules are
886 ;; less critical, but handy.
887 (udev-service #:rules (list lvm2 fuse alsa-utils)))))
889 ;;; base.scm ends here