1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu services dbus)
20 #:use-module (gnu services)
21 #:use-module (gnu system shadow)
22 #:use-module (gnu packages glib)
23 #:use-module (guix monads)
24 #:use-module (guix store)
25 #:use-module (guix gexp)
26 #:export (dbus-service))
30 ;;; This module supports the configuration of the D-Bus message bus
31 ;;; (http://dbus.freedesktop.org/). D-Bus is an inter-process communication
32 ;;; facility. Its "system bus" is used to allow system services to
33 ;;; communicate and be notified of system-wide events.
37 (define (dbus-configuration-directory dbus services)
38 "Return a configuration directory for @var{dbus} that includes the
39 @code{etc/dbus-1/system.d} directories of each package listed in
43 (use-modules (sxml simple)
46 (define (services->sxml services)
47 ;; Return the SXML 'includedir' clauses for DIRS.
49 ,@(append-map (lambda (dir)
51 ,(string-append dir "/etc/dbus-1/system.d"))
52 (servicedir ;for '.service' files
53 ,(string-append dir "/share/dbus-1/services"))))
57 (copy-file (string-append #$dbus "/etc/dbus-1/system.conf")
58 (string-append #$output "/system.conf"))
60 ;; The default 'system.conf' has an <includedir> clause for
61 ;; 'system.d', so create it.
62 (mkdir (string-append #$output "/system.d"))
64 ;; 'system-local.conf' is automatically included by the default
65 ;; 'system.conf', so this is where we stuff our own things.
66 (call-with-output-file (string-append #$output "/system-local.conf")
68 (sxml->xml (services->sxml (list #$@services))
71 (gexp->derivation "dbus-configuration" build))
73 (define* (dbus-service services #:key (dbus dbus))
74 "Return a service that runs the system bus, using @var{dbus}, with support
77 @var{services} must be a list of packages that provide an
78 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
79 and policy files. For example, to allow avahi-daemon to use the system bus,
80 @var{services} must be equal to @code{(list avahi)}."
81 (mlet %store-monad ((conf (dbus-configuration-directory dbus services)))
84 (documentation "Run the D-Bus system daemon.")
85 (provision '(dbus-system))
86 (requirement '(user-processes))
87 (start #~(make-forkexec-constructor
88 (list (string-append #$dbus "/bin/dbus-daemon")
90 (string-append "--config-file=" #$conf "/system.conf"))))
91 (stop #~(make-kill-destructor))
92 (user-groups (list (user-group
95 (user-accounts (list (user-account
99 (comment "D-Bus system bus user")
100 (home-directory "/var/run/dbus")
102 "/run/current-system/profile/sbin/nologin"))))
104 (use-modules (guix build utils))
106 (mkdir-p "/var/run/dbus")
108 (let ((user (getpwnam "messagebus")))
109 (chown "/var/run/dbus"
110 (passwd:uid user) (passwd:gid user)))
112 (unless (file-exists? "/etc/machine-id")
113 (format #t "creating /etc/machine-id...~%")
114 (let ((prog (string-append #$dbus "/bin/dbus-uuidgen")))
115 ;; XXX: We can't use 'system' because the initrd's
116 ;; guile system(3) only works when 'sh' is in $PATH.
117 (let ((pid (primitive-fork)))
119 (call-with-output-file "/etc/machine-id"
122 (dup2 (port->fdes port) 1)
124 (waitpid pid)))))))))))
126 ;;; dbus.scm ends here