1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 Andy Wingo <wingo@igalia.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 desktop)
21 #:use-module (gnu services)
22 #:use-module (gnu services base)
23 #:use-module (gnu services avahi)
24 #:use-module (gnu services xorg)
25 #:use-module (gnu services networking)
26 #:use-module (gnu system shadow)
27 #:use-module (gnu packages glib)
28 #:use-module (gnu packages admin)
29 #:use-module (gnu packages gnome)
30 #:use-module (gnu packages avahi)
31 #:use-module (gnu packages wicd)
32 #:use-module (guix monads)
33 #:use-module (guix store)
34 #:use-module (guix gexp)
35 #:use-module (ice-9 match)
36 #:export (dbus-service
43 ;;; This module contains service definitions for a "desktop" environment.
52 (define (dbus-configuration-directory dbus services)
53 "Return a configuration directory for @var{dbus} that includes the
54 @code{etc/dbus-1/system.d} directories of each package listed in
58 (use-modules (sxml simple)
61 (define (services->sxml services)
62 ;; Return the SXML 'includedir' clauses for DIRS.
64 ,@(append-map (lambda (dir)
66 ,(string-append dir "/etc/dbus-1/system.d"))
67 (servicedir ;for '.service' files
68 ,(string-append dir "/share/dbus-1/services"))))
72 (copy-file (string-append #$dbus "/etc/dbus-1/system.conf")
73 (string-append #$output "/system.conf"))
75 ;; The default 'system.conf' has an <includedir> clause for
76 ;; 'system.d', so create it.
77 (mkdir (string-append #$output "/system.d"))
79 ;; 'system-local.conf' is automatically included by the default
80 ;; 'system.conf', so this is where we stuff our own things.
81 (call-with-output-file (string-append #$output "/system-local.conf")
83 (sxml->xml (services->sxml (list #$@services))
86 (gexp->derivation "dbus-configuration" build))
88 (define* (dbus-service services #:key (dbus dbus))
89 "Return a service that runs the \"system bus\", using @var{dbus}, with
90 support for @var{services}.
92 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
93 facility. Its system bus is used to allow system services to communicate and
94 be notified of system-wide events.
96 @var{services} must be a list of packages that provide an
97 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
98 and policy files. For example, to allow avahi-daemon to use the system bus,
99 @var{services} must be equal to @code{(list avahi)}."
100 (mlet %store-monad ((conf (dbus-configuration-directory dbus services)))
103 (documentation "Run the D-Bus system daemon.")
104 (provision '(dbus-system))
105 (requirement '(user-processes))
106 (start #~(make-forkexec-constructor
107 (list (string-append #$dbus "/bin/dbus-daemon")
109 (string-append "--config-file=" #$conf "/system.conf"))))
110 (stop #~(make-kill-destructor))
111 (user-groups (list (user-group
114 (user-accounts (list (user-account
118 (comment "D-Bus system bus user")
119 (home-directory "/var/run/dbus")
121 #~(string-append #$shadow "/sbin/nologin")))))
123 (use-modules (guix build utils))
125 (mkdir-p "/var/run/dbus")
127 (let ((user (getpwnam "messagebus")))
128 (chown "/var/run/dbus"
129 (passwd:uid user) (passwd:gid user)))
131 (unless (file-exists? "/etc/machine-id")
132 (format #t "creating /etc/machine-id...~%")
133 (let ((prog (string-append #$dbus "/bin/dbus-uuidgen")))
134 ;; XXX: We can't use 'system' because the initrd's
135 ;; guile system(3) only works when 'sh' is in $PATH.
136 (let ((pid (primitive-fork)))
138 (call-with-output-file "/etc/machine-id"
141 (dup2 (port->fdes port) 1)
143 (waitpid pid)))))))))))
147 ;;; Upower D-Bus service.
150 (define* (upower-configuration-file #:key watts-up-pro? poll-batteries?
151 ignore-lid? use-percentage-for-policy?
152 percentage-low percentage-critical
153 percentage-action time-low
154 time-critical time-action
155 critical-power-action)
156 "Return an upower-daemon configuration file."
158 (if value "true\n" "false\n"))
160 (text-file "UPower.conf"
163 "EnableWattsUpPro=" (bool watts-up-pro?)
164 "NoPollBatteries=" (bool (not poll-batteries?))
165 "IgnoreLid=" (bool ignore-lid?)
166 "UsePercentageForPolicy=" (bool use-percentage-for-policy?)
167 "PercentageLow=" (number->string percentage-low) "\n"
168 "PercentageCritical=" (number->string percentage-critical) "\n"
169 "PercentageAction=" (number->string percentage-action) "\n"
170 "TimeLow=" (number->string time-low) "\n"
171 "TimeCritical=" (number->string time-critical) "\n"
172 "TimeAction=" (number->string time-action) "\n"
173 "CriticalPowerAction=" (match critical-power-action
174 ('hybrid-sleep "HybridSleep")
175 ('hibernate "Hibernate")
176 ('power-off "PowerOff"))
179 (define* (upower-service #:key (upower upower)
183 (use-percentage-for-policy? #f)
185 (percentage-critical 3)
186 (percentage-action 2)
190 (critical-power-action 'hybrid-sleep))
191 "Return a service that runs @uref{http://upower.freedesktop.org/,
192 @command{upowerd}}, a system-wide monitor for power consumption and battery
193 levels, with the given configuration settings. It implements the
194 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by GNOME."
195 (mlet %store-monad ((config (upower-configuration-file
196 #:watts-up-pro? watts-up-pro?
197 #:poll-batteries? poll-batteries?
198 #:ignore-lid? ignore-lid?
199 #:use-percentage-for-policy? use-percentage-for-policy?
200 #:percentage-low percentage-low
201 #:percentage-critical percentage-critical
202 #:percentage-action percentage-action
204 #:time-critical time-critical
205 #:time-action time-action
206 #:critical-power-action critical-power-action)))
209 (documentation "Run the UPower power and battery monitor.")
210 (provision '(upower-daemon))
211 (requirement '(dbus-system udev))
213 (start #~(make-forkexec-constructor
214 (list (string-append #$upower "/libexec/upowerd"))
215 #:environment-variables
216 (list (string-append "UPOWER_CONF_FILE_NAME=" #$config))))
217 (stop #~(make-kill-destructor))
219 (use-modules (guix build utils))
220 (mkdir-p "/var/lib/upower")
221 (let ((user (getpwnam "upower")))
222 (chown "/var/lib/upower"
223 (passwd:uid user) (passwd:gid user)))))
225 (user-groups (list (user-group
228 (user-accounts (list (user-account
232 (comment "UPower daemon user")
233 (home-directory "/var/empty")
235 #~(string-append #$shadow "/sbin/nologin")))))))))
239 ;;; Colord D-Bus service.
242 (define* (colord-service #:key (colord colord))
243 "Return a service that runs @command{colord}, a system service with a D-Bus
244 interface to manage the color profiles of input and output devices such as
245 screens and scanners. It is notably used by the GNOME Color Manager graphical
246 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
247 site} for more information."
248 (with-monad %store-monad
251 (documentation "Run the colord color management service.")
252 (provision '(colord-daemon))
253 (requirement '(dbus-system udev))
255 (start #~(make-forkexec-constructor
256 (list (string-append #$colord "/libexec/colord"))))
257 (stop #~(make-kill-destructor))
259 (use-modules (guix build utils))
260 (mkdir-p "/var/lib/colord")
261 (let ((user (getpwnam "colord")))
262 (chown "/var/lib/colord"
263 (passwd:uid user) (passwd:gid user)))))
265 (user-groups (list (user-group
268 (user-accounts (list (user-account
272 (comment "colord daemon user")
273 (home-directory "/var/empty")
275 #~(string-append #$shadow "/sbin/nologin")))))))))
277 (define %desktop-services
278 ;; List of services typically useful for a "desktop" use case.
279 (cons* (slim-service)
285 (dbus-service (list avahi wicd upower colord))
289 (map (lambda (mservice)
290 ;; Provide an nscd ready to use nss-mdns.
291 (mlet %store-monad ((service mservice))
292 (if (memq 'nscd (service-provision service))
293 (nscd-service (nscd-configuration)
294 #:name-services (list nss-mdns))
298 ;;; desktop.scm ends here