container: Allow 'container-excursion' to the same namespaces.
[jackhill/guix/guix.git] / gnu / services / desktop.scm
CommitLineData
fe1a39d3 1;;; GNU Guix --- Functional package management for GNU
edc891fa 2;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
fe1a39d3 3;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
4307c476 4;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
922e21f4 5;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
fe1a39d3
LC
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify it
10;;; under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 3 of the License, or (at
12;;; your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful, but
15;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22(define-module (gnu services desktop)
23 #:use-module (gnu services)
0190c1c0 24 #:use-module (gnu services shepherd)
4467be21 25 #:use-module (gnu services base)
0adfe95a 26 #:use-module (gnu services dbus)
4467be21
LC
27 #:use-module (gnu services avahi)
28 #:use-module (gnu services xorg)
29 #:use-module (gnu services networking)
38c2b503
LC
30 #:use-module ((gnu system file-systems)
31 #:select (%elogind-file-systems))
fe1a39d3 32 #:use-module (gnu system shadow)
6e828634 33 #:use-module (gnu system pam)
fe1a39d3
LC
34 #:use-module (gnu packages glib)
35 #:use-module (gnu packages admin)
04463bb0 36 #:use-module (gnu packages freedesktop)
fe1a39d3 37 #:use-module (gnu packages gnome)
7a2413e4 38 #:use-module (gnu packages xfce)
4467be21 39 #:use-module (gnu packages avahi)
0071c789 40 #:use-module (gnu packages polkit)
6726282b
LC
41 #:use-module (gnu packages xdisorg)
42 #:use-module (gnu packages suckless)
922e21f4 43 #:use-module (gnu packages linux)
04463bb0 44 #:use-module (guix records)
0adfe95a 45 #:use-module (guix packages)
fe1a39d3
LC
46 #:use-module (guix store)
47 #:use-module (guix gexp)
0adfe95a 48 #:use-module (srfi srfi-1)
fe1a39d3 49 #:use-module (ice-9 match)
24e96431
50 #:export (upower-configuration
51 upower-configuration?
52 upower-service
53 upower-service-type
54
55 udisks-configuration
56 udisks-configuration?
2b9e0a94 57 udisks-service
24e96431
58 udisks-service-type
59
4467be21 60 colord-service
24e96431 61
cee32ee4 62 geoclue-application
24e96431
63 geoclue-configuration
64 geoclue-configuration?
cee32ee4
AW
65 %standard-geoclue-applications
66 geoclue-service
24e96431
67 geoclue-service-type
68
922e21f4 69 bluetooth-service
24e96431
70
71 polkit-configuration
72 polkit-configuration?
0071c789 73 polkit-service
24e96431
74 polkit-service-type
75
04463bb0 76 elogind-configuration
24e96431 77 elogind-configuration?
04463bb0 78 elogind-service
24e96431
79 elogind-service-type
80
81 gnome-desktop-configuration
82 gnome-desktop-configuration?
7a2413e4 83 gnome-desktop-service
24e96431
84 gnome-desktop-service-type
85
86 xfce-desktop-configuration
87 xfce-desktop-configuration?
7a2413e4 88 xfce-desktop-service
24e96431
89 xfce-desktop-service-type
90
4467be21 91 %desktop-services))
fe1a39d3
LC
92
93;;; Commentary:
94;;;
95;;; This module contains service definitions for a "desktop" environment.
96;;;
97;;; Code:
98
99\f
cee32ee4
AW
100;;;
101;;; Helpers.
102;;;
103
104(define (bool value)
105 (if value "true\n" "false\n"))
106
7a2413e4
AW
107(define (package-direct-input-selector input)
108 (lambda (package)
109 (match (assoc-ref (package-direct-inputs package) input)
110 ((package . _) package))))
111
fe1a39d3 112
0adfe95a
LC
113(define (wrapped-dbus-service service program variable value)
114 "Return a wrapper for @var{service}, a package containing a D-Bus service,
115where @var{program} is wrapped such that environment variable @var{variable}
116is set to @var{value} when the bus daemon launches it."
117 (define wrapper
118 (program-file (string-append (package-name service) "-program-wrapper")
119 #~(begin
120 (setenv #$variable #$value)
121 (apply execl (string-append #$service "/" #$program)
122 (string-append #$service "/" #$program)
123 (cdr (command-line))))))
124
4ee96a79
LC
125 (define build
126 (with-imported-modules '((guix build utils))
127 #~(begin
128 (use-modules (guix build utils))
129
130 (define service-directory
131 "/share/dbus-1/system-services")
132
133 (mkdir-p (dirname (string-append #$output
134 service-directory)))
135 (copy-recursively (string-append #$service
136 service-directory)
137 (string-append #$output
138 service-directory))
139 (symlink (string-append #$service "/etc") ;for etc/dbus-1
140 (string-append #$output "/etc"))
141
142 (for-each (lambda (file)
143 (substitute* file
144 (("Exec[[:blank:]]*=[[:blank:]]*([[:graph:]]+)(.*)$"
145 _ original-program arguments)
146 (string-append "Exec=" #$wrapper arguments
147 "\n"))))
148 (find-files #$output "\\.service$")))))
149
0adfe95a 150 (computed-file (string-append (package-name service) "-wrapper")
4ee96a79 151 build))
fe1a39d3
LC
152
153\f
154;;;
155;;; Upower D-Bus service.
156;;;
157
0adfe95a
LC
158;; TODO: Export.
159(define-record-type* <upower-configuration>
160 upower-configuration make-upower-configuration
161 upower-configuration?
162 (upower upower-configuration-upower
163 (default upower))
164 (watts-up-pro? upower-configuration-watts-up-pro?)
165 (poll-batteries? upower-configuration-poll-batteries?)
166 (ignore-lid? upower-configuration-ignore-lid?)
167 (use-percentage-for-policy? upower-configuration-use-percentage-for-policy?)
168 (percentage-low upower-configuration-percentage-low)
169 (percentage-critical upower-configuration-percentage-critical)
170 (percentage-action upower-configuration-percentage-action)
171 (time-low upower-configuration-time-low)
172 (time-critical upower-configuration-time-critical)
173 (time-action upower-configuration-time-action)
174 (critical-power-action upower-configuration-critical-power-action))
175
176(define* upower-configuration-file
177 ;; Return an upower-daemon configuration file.
178 (match-lambda
179 (($ <upower-configuration> upower
180 watts-up-pro? poll-batteries? ignore-lid? use-percentage-for-policy?
181 percentage-low percentage-critical percentage-action time-low
182 time-critical time-action critical-power-action)
183 (plain-file "UPower.conf"
184 (string-append
185 "[UPower]\n"
186 "EnableWattsUpPro=" (bool watts-up-pro?)
187 "NoPollBatteries=" (bool (not poll-batteries?))
188 "IgnoreLid=" (bool ignore-lid?)
189 "UsePercentageForPolicy=" (bool use-percentage-for-policy?)
190 "PercentageLow=" (number->string percentage-low) "\n"
191 "PercentageCritical=" (number->string percentage-critical) "\n"
192 "PercentageAction=" (number->string percentage-action) "\n"
193 "TimeLow=" (number->string time-low) "\n"
194 "TimeCritical=" (number->string time-critical) "\n"
195 "TimeAction=" (number->string time-action) "\n"
196 "CriticalPowerAction=" (match critical-power-action
197 ('hybrid-sleep "HybridSleep")
198 ('hibernate "Hibernate")
199 ('power-off "PowerOff"))
200 "\n")))))
201
0adfe95a
LC
202(define %upower-activation
203 #~(begin
204 (use-modules (guix build utils))
2da4f2dd 205 (mkdir-p "/var/lib/upower")))
0adfe95a
LC
206
207(define (upower-dbus-service config)
208 (list (wrapped-dbus-service (upower-configuration-upower config)
209 "libexec/upowerd"
210 "UPOWER_CONF_FILE_NAME"
211 (upower-configuration-file config))))
212
d4053c71
AK
213(define (upower-shepherd-service config)
214 "Return a shepherd service for UPower with CONFIG."
0adfe95a
LC
215 (let ((upower (upower-configuration-upower config))
216 (config (upower-configuration-file config)))
d4053c71 217 (list (shepherd-service
0adfe95a
LC
218 (documentation "Run the UPower power and battery monitor.")
219 (provision '(upower-daemon))
220 (requirement '(dbus-system udev))
221
222 (start #~(make-forkexec-constructor
223 (list (string-append #$upower "/libexec/upowerd"))
224 #:environment-variables
225 (list (string-append "UPOWER_CONF_FILE_NAME="
226 #$config))))
227 (stop #~(make-kill-destructor))))))
228
229(define upower-service-type
edc891fa
LC
230 (let ((upower-package (compose list upower-configuration-upower)))
231 (service-type (name 'upower)
232 (extensions
233 (list (service-extension dbus-root-service-type
234 upower-dbus-service)
235 (service-extension shepherd-root-service-type
236 upower-shepherd-service)
237 (service-extension activation-service-type
238 (const %upower-activation))
239 (service-extension udev-service-type
240 upower-package)
241
242 ;; Make the 'upower' command visible.
243 (service-extension profile-service-type
244 upower-package))))))
fe1a39d3
LC
245
246(define* (upower-service #:key (upower upower)
247 (watts-up-pro? #f)
248 (poll-batteries? #t)
249 (ignore-lid? #f)
250 (use-percentage-for-policy? #f)
251 (percentage-low 10)
252 (percentage-critical 3)
253 (percentage-action 2)
254 (time-low 1200)
255 (time-critical 300)
256 (time-action 120)
257 (critical-power-action 'hybrid-sleep))
258 "Return a service that runs @uref{http://upower.freedesktop.org/,
259@command{upowerd}}, a system-wide monitor for power consumption and battery
260levels, with the given configuration settings. It implements the
261@code{org.freedesktop.UPower} D-Bus interface, and is notably used by GNOME."
0adfe95a
LC
262 (let ((config (upower-configuration
263 (watts-up-pro? watts-up-pro?)
264 (poll-batteries? poll-batteries?)
265 (ignore-lid? ignore-lid?)
266 (use-percentage-for-policy? use-percentage-for-policy?)
267 (percentage-low percentage-low)
268 (percentage-critical percentage-critical)
269 (percentage-action percentage-action)
270 (time-low time-low)
271 (time-critical time-critical)
272 (time-action time-action)
273 (critical-power-action critical-power-action))))
274 (service upower-service-type config)))
fe1a39d3
LC
275
276\f
cee32ee4
AW
277;;;
278;;; GeoClue D-Bus service.
279;;;
280
0adfe95a
LC
281;; TODO: Export.
282(define-record-type* <geoclue-configuration>
283 geoclue-configuration make-geoclue-configuration
284 geoclue-configuration?
285 (geoclue geoclue-configuration-geoclue
286 (default geoclue))
287 (whitelist geoclue-configuration-whitelist)
288 (wifi-geolocation-url geoclue-configuration-wifi-geolocation-url)
289 (submit-data? geoclue-configuration-submit-data?)
290 (wifi-submission-url geoclue-configuration-wifi-submission-url)
291 (submission-nick geoclue-configuration-submission-nick)
292 (applications geoclue-configuration-applications))
293
cee32ee4
AW
294(define* (geoclue-application name #:key (allowed? #t) system? (users '()))
295 "Configure default GeoClue access permissions for an application. NAME is
296the Desktop ID of the application, without the .desktop part. If ALLOWED? is
297true, the application will have access to location information by default.
298The boolean SYSTEM? value indicates that an application is a system component
299or not. Finally USERS is a list of UIDs of all users for which this
300application is allowed location info access. An empty users list means all
301users are allowed."
302 (string-append
303 "[" name "]\n"
304 "allowed=" (bool allowed?)
305 "system=" (bool system?)
306 "users=" (string-join users ";") "\n"))
307
308(define %standard-geoclue-applications
309 (list (geoclue-application "gnome-datetime-panel" #:system? #t)
310 (geoclue-application "epiphany" #:system? #f)
311 (geoclue-application "firefox" #:system? #f)))
312
0adfe95a 313(define* (geoclue-configuration-file config)
cee32ee4 314 "Return a geoclue configuration file."
be1c2c54
LC
315 (plain-file "geoclue.conf"
316 (string-append
317 "[agent]\n"
0adfe95a
LC
318 "whitelist="
319 (string-join (geoclue-configuration-whitelist config)
320 ";") "\n"
be1c2c54 321 "[wifi]\n"
0adfe95a
LC
322 "url=" (geoclue-configuration-wifi-geolocation-url config) "\n"
323 "submit-data=" (bool (geoclue-configuration-submit-data? config))
324 "submission-url="
325 (geoclue-configuration-wifi-submission-url config) "\n"
326 "submission-nick="
327 (geoclue-configuration-submission-nick config)
328 "\n"
329 (string-join (geoclue-configuration-applications config)
330 "\n"))))
331
332(define (geoclue-dbus-service config)
333 (list (wrapped-dbus-service (geoclue-configuration-geoclue config)
334 "libexec/geoclue"
335 "GEOCLUE_CONFIG_FILE"
336 (geoclue-configuration-file config))))
337
0adfe95a
LC
338(define %geoclue-accounts
339 (list (user-group (name "geoclue") (system? #t))
340 (user-account
341 (name "geoclue")
342 (group "geoclue")
343 (system? #t)
344 (comment "GeoClue daemon user")
345 (home-directory "/var/empty")
346 (shell "/run/current-system/profile/sbin/nologin"))))
347
348(define geoclue-service-type
349 (service-type (name 'geoclue)
350 (extensions
351 (list (service-extension dbus-root-service-type
352 geoclue-dbus-service)
0adfe95a
LC
353 (service-extension account-service-type
354 (const %geoclue-accounts))))))
cee32ee4
AW
355
356(define* (geoclue-service #:key (geoclue geoclue)
357 (whitelist '())
358 (wifi-geolocation-url
359 ;; Mozilla geolocation service:
360 "https://location.services.mozilla.com/v1/geolocate?key=geoclue")
361 (submit-data? #f)
362 (wifi-submission-url
363 "https://location.services.mozilla.com/v1/submit?key=geoclue")
364 (submission-nick "geoclue")
365 (applications %standard-geoclue-applications))
366 "Return a service that runs the @command{geoclue} location service. This
367service provides a D-Bus interface to allow applications to request access to
368a user's physical location, and optionally to add information to online
369location databases. By default, only the GNOME date-time panel and the Icecat
370and Epiphany web browsers are able to ask for the user's location, and in the
371case of Icecat and Epiphany, both will ask the user for permission first. See
372@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the geoclue web
373site} for more information."
0adfe95a
LC
374 (service geoclue-service-type
375 (geoclue-configuration
376 (geoclue geoclue)
377 (whitelist whitelist)
378 (wifi-geolocation-url wifi-geolocation-url)
379 (submit-data? submit-data?)
380 (wifi-submission-url wifi-submission-url)
381 (submission-nick submission-nick)
382 (applications applications))))
cee32ee4
AW
383
384\f
922e21f4
SB
385;;;
386;;; Bluetooth.
387;;;
388
389(define (bluetooth-shepherd-service bluez)
390 "Return a shepherd service for @command{bluetoothd}."
391 (shepherd-service
392 (provision '(bluetooth))
393 (requirement '(dbus-system udev))
394 (documentation "Run the bluetoothd daemon.")
395 (start #~(make-forkexec-constructor
396 (string-append #$bluez "/libexec/bluetooth/bluetoothd")))
397 (stop #~(make-kill-destructor))))
398
399(define bluetooth-service-type
400 (service-type
401 (name 'bluetooth)
402 (extensions
403 (list (service-extension dbus-root-service-type list)
404 (service-extension udev-service-type list)
405 (service-extension shepherd-root-service-type
406 (compose list bluetooth-shepherd-service))))))
407
408(define* (bluetooth-service #:key (bluez bluez))
409 "Return a service that runs the @command{bluetoothd} daemon, which manages
410all the Bluetooth devices and provides a number of D-Bus interfaces.
411
412Users need to be in the @code{lp} group to access the D-Bus service.
413"
414 (service bluetooth-service-type bluez))
415
416\f
0071c789
AW
417;;;
418;;; Polkit privilege management service.
419;;;
420
222e3319
LC
421(define-record-type* <polkit-configuration>
422 polkit-configuration make-polkit-configuration
423 polkit-configuration?
424 (polkit polkit-configuration-polkit ;<package>
425 (default polkit))
426 (actions polkit-configuration-actions ;list of <package>
427 (default '())))
428
0adfe95a
LC
429(define %polkit-accounts
430 (list (user-group (name "polkitd") (system? #t))
431 (user-account
432 (name "polkitd")
433 (group "polkitd")
434 (system? #t)
435 (comment "Polkit daemon user")
436 (home-directory "/var/empty")
437 (shell "/run/current-system/profile/sbin/nologin"))))
438
439(define %polkit-pam-services
7824d445 440 (list (unix-pam-service "polkit-1")))
0adfe95a 441
222e3319
LC
442(define (polkit-directory packages)
443 "Return a directory containing an @file{actions} and possibly a
444@file{rules.d} sub-directory, for use as @file{/etc/polkit-1}."
4ee96a79
LC
445 (with-imported-modules '((guix build union))
446 (computed-file "etc-polkit-1"
447 #~(begin
448 (use-modules (guix build union) (srfi srfi-26))
449
450 (union-build #$output
451 (map (cut string-append <>
452 "/share/polkit-1")
453 (list #$@packages)))))))
222e3319
LC
454
455(define polkit-etc-files
456 (match-lambda
457 (($ <polkit-configuration> polkit packages)
ea84bd88 458 `(("polkit-1" ,(polkit-directory (cons polkit packages)))))))
222e3319
LC
459
460(define polkit-setuid-programs
461 (match-lambda
462 (($ <polkit-configuration> polkit)
9e41130b
LC
463 (list (file-append polkit "/lib/polkit-1/polkit-agent-helper-1")
464 (file-append polkit "/bin/pkexec")))))
222e3319 465
0adfe95a 466(define polkit-service-type
0adfe95a
LC
467 (service-type (name 'polkit)
468 (extensions
469 (list (service-extension account-service-type
470 (const %polkit-accounts))
471 (service-extension pam-root-service-type
472 (const %polkit-pam-services))
473 (service-extension dbus-root-service-type
222e3319
LC
474 (compose
475 list
476 polkit-configuration-polkit))
477 (service-extension etc-service-type
478 polkit-etc-files)
479 (service-extension setuid-program-service-type
480 polkit-setuid-programs)))
481
482 ;; Extensions are lists of packages that provide polkit rules
483 ;; or actions under share/polkit-1/{actions,rules.d}.
484 (compose concatenate)
485 (extend (lambda (config actions)
486 (polkit-configuration
487 (inherit config)
488 (actions
489 (append (polkit-configuration-actions config)
490 actions)))))))
0adfe95a 491
0071c789 492(define* (polkit-service #:key (polkit polkit))
222e3319
LC
493 "Return a service that runs the
494@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
495management service}, which allows system administrators to grant access to
496privileged operations in a structured way. By querying the Polkit service, a
497privileged system component can know when it should grant additional
498capabilities to ordinary users. For example, an ordinary user can be granted
499the capability to suspend the system if the user is logged in locally."
500 (service polkit-service-type
501 (polkit-configuration (polkit polkit))))
502
503\f
504;;;
505;;; Colord D-Bus service.
506;;;
507
508(define %colord-activation
509 #~(begin
510 (use-modules (guix build utils))
511 (mkdir-p "/var/lib/colord")
512 (let ((user (getpwnam "colord")))
513 (chown "/var/lib/colord"
514 (passwd:uid user) (passwd:gid user)))))
515
516(define %colord-accounts
517 (list (user-group (name "colord") (system? #t))
518 (user-account
519 (name "colord")
520 (group "colord")
521 (system? #t)
522 (comment "colord daemon user")
523 (home-directory "/var/empty")
9e41130b 524 (shell (file-append shadow "/sbin/nologin")))))
222e3319
LC
525
526(define colord-service-type
527 (service-type (name 'colord)
528 (extensions
529 (list (service-extension account-service-type
530 (const %colord-accounts))
531 (service-extension activation-service-type
532 (const %colord-activation))
533
534 ;; Colord is a D-Bus service that dbus-daemon can
535 ;; activate.
536 (service-extension dbus-root-service-type list)
537
538 ;; Colord provides "color device" rules for udev.
539 (service-extension udev-service-type list)
540
541 ;; It provides polkit "actions".
542 (service-extension polkit-service-type list)))))
543
544(define* (colord-service #:key (colord colord))
545 "Return a service that runs @command{colord}, a system service with a D-Bus
546interface to manage the color profiles of input and output devices such as
547screens and scanners. It is notably used by the GNOME Color Manager graphical
548tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
549site} for more information."
550 (service colord-service-type colord))
0071c789
AW
551
552\f
2b9e0a94
LC
553;;;
554;;; UDisks.
555;;;
556
557(define-record-type* <udisks-configuration>
558 udisks-configuration make-udisks-configuration
559 udisks-configuration?
560 (udisks udisks-configuration-udisks
561 (default udisks)))
562
563(define udisks-service-type
564 (let ((udisks-package (lambda (config)
565 (list (udisks-configuration-udisks config)))))
566 (service-type (name 'udisks)
567 (extensions
568 (list (service-extension polkit-service-type
569 udisks-package)
570 (service-extension dbus-root-service-type
571 udisks-package)
572 (service-extension udev-service-type
beca0807
LC
573 udisks-package)
574
575 ;; Profile 'udisksctl' & co. in the system profile.
576 (service-extension profile-service-type
2b9e0a94
LC
577 udisks-package))))))
578
579(define* (udisks-service #:key (udisks udisks))
580 "Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
581UDisks}, a @dfn{disk management} daemon that provides user interfaces with
582notifications and ways to mount/unmount disks. Programs that talk to UDisks
583include the @command{udisksctl} command, part of UDisks, and GNOME Disks."
584 (service udisks-service-type
585 (udisks-configuration (udisks udisks))))
586
587\f
04463bb0
AW
588;;;
589;;; Elogind login and seat management service.
590;;;
591
592(define-record-type* <elogind-configuration> elogind-configuration
593 make-elogind-configuration
594 elogind-configuration
0adfe95a
LC
595 (elogind elogind-package
596 (default elogind))
04463bb0
AW
597 (kill-user-processes? elogind-kill-user-processes?
598 (default #f))
599 (kill-only-users elogind-kill-only-users
600 (default '()))
601 (kill-exclude-users elogind-kill-exclude-users
602 (default '("root")))
603 (inhibit-delay-max-seconds elogind-inhibit-delay-max-seconds
604 (default 5))
605 (handle-power-key elogind-handle-power-key
606 (default 'poweroff))
607 (handle-suspend-key elogind-handle-suspend-key
608 (default 'suspend))
609 (handle-hibernate-key elogind-handle-hibernate-key
574d9db2
MW
610 ;; (default 'hibernate)
611 ;; XXX Ignore it for now, since we don't
612 ;; yet handle resume-from-hibernation in
613 ;; our initrd.
614 (default 'ignore))
04463bb0
AW
615 (handle-lid-switch elogind-handle-lid-switch
616 (default 'suspend))
617 (handle-lid-switch-docked elogind-handle-lid-switch-docked
618 (default 'ignore))
619 (power-key-ignore-inhibited? elogind-power-key-ignore-inhibited?
620 (default #f))
621 (suspend-key-ignore-inhibited? elogind-suspend-key-ignore-inhibited?
622 (default #f))
623 (hibernate-key-ignore-inhibited? elogind-hibernate-key-ignore-inhibited?
624 (default #f))
625 (lid-switch-ignore-inhibited? elogind-lid-switch-ignore-inhibited?
626 (default #t))
627 (holdoff-timeout-seconds elogind-holdoff-timeout-seconds
628 (default 30))
629 (idle-action elogind-idle-action
630 (default 'ignore))
631 (idle-action-seconds elogind-idle-action-seconds
632 (default (* 30 60)))
633 (runtime-directory-size-percent elogind-runtime-directory-size-percent
634 (default 10))
635 (runtime-directory-size elogind-runtime-directory-size
636 (default #f))
637 (remove-ipc? elogind-remove-ipc?
638 (default #t))
639
640 (suspend-state elogind-suspend-state
641 (default '("mem" "standby" "freeze")))
642 (suspend-mode elogind-suspend-mode
643 (default '()))
644 (hibernate-state elogind-hibernate-state
645 (default '("disk")))
646 (hibernate-mode elogind-hibernate-mode
647 (default '("platform" "shutdown")))
648 (hybrid-sleep-state elogind-hybrid-sleep-state
649 (default '("disk")))
650 (hybrid-sleep-mode elogind-hybrid-sleep-mode
651 (default
652 '("suspend" "platform" "shutdown"))))
653
654(define (elogind-configuration-file config)
655 (define (yesno x)
656 (match x
657 (#t "yes")
658 (#f "no")
659 (_ (error "expected #t or #f, instead got:" x))))
660 (define char-set:user-name
661 (string->char-set "abcdefghijklmnopqrstuvwxyz0123456789_-"))
662 (define (valid-list? l pred)
663 (and-map (lambda (x) (string-every pred x)) l))
664 (define (user-name-list users)
665 (unless (valid-list? users char-set:user-name)
666 (error "invalid user list" users))
667 (string-join users " "))
668 (define (enum val allowed)
669 (unless (memq val allowed)
670 (error "invalid value" val allowed))
671 (symbol->string val))
672 (define (non-negative-integer x)
673 (unless (exact-integer? x) (error "not an integer" x))
674 (when (negative? x) (error "negative number not allowed" x))
675 (number->string x))
676 (define handle-actions
677 '(ignore poweroff reboot halt kexec suspend hibernate hybrid-sleep lock))
678 (define (handle-action x)
679 (enum x handle-actions))
680 (define (sleep-list tokens)
681 (unless (valid-list? tokens char-set:user-name)
682 (error "invalid sleep list" tokens))
683 (string-join tokens " "))
684 (define-syntax ini-file-clause
685 (syntax-rules ()
686 ((_ config (prop (parser getter)))
687 (string-append prop "=" (parser (getter config)) "\n"))
688 ((_ config str)
689 (string-append str "\n"))))
690 (define-syntax-rule (ini-file config file clause ...)
be1c2c54 691 (plain-file file (string-append (ini-file-clause config clause) ...)))
04463bb0
AW
692 (ini-file
693 config "logind.conf"
694 "[Login]"
695 ("KillUserProcesses" (yesno elogind-kill-user-processes?))
696 ("KillOnlyUsers" (user-name-list elogind-kill-only-users))
697 ("KillExcludeUsers" (user-name-list elogind-kill-exclude-users))
698 ("InhibitDelayMaxSecs" (non-negative-integer elogind-inhibit-delay-max-seconds))
699 ("HandlePowerKey" (handle-action elogind-handle-power-key))
700 ("HandleSuspendKey" (handle-action elogind-handle-suspend-key))
701 ("HandleHibernateKey" (handle-action elogind-handle-hibernate-key))
702 ("HandleLidSwitch" (handle-action elogind-handle-lid-switch))
703 ("HandleLidSwitchDocked" (handle-action elogind-handle-lid-switch-docked))
704 ("PowerKeyIgnoreInhibited" (yesno elogind-power-key-ignore-inhibited?))
705 ("SuspendKeyIgnoreInhibited" (yesno elogind-suspend-key-ignore-inhibited?))
706 ("HibernateKeyIgnoreInhibited" (yesno elogind-hibernate-key-ignore-inhibited?))
707 ("LidSwitchIgnoreInhibited" (yesno elogind-lid-switch-ignore-inhibited?))
708 ("HoldoffTimeoutSecs" (non-negative-integer elogind-holdoff-timeout-seconds))
709 ("IdleAction" (handle-action elogind-idle-action))
710 ("IdleActionSeconds" (non-negative-integer elogind-idle-action-seconds))
711 ("RuntimeDirectorySize"
712 (identity
713 (lambda (config)
714 (match (elogind-runtime-directory-size-percent config)
715 (#f (non-negative-integer (elogind-runtime-directory-size config)))
716 (percent (string-append (non-negative-integer percent) "%"))))))
717 ("RemoveIpc" (yesno elogind-remove-ipc?))
718 "[Sleep]"
719 ("SuspendState" (sleep-list elogind-suspend-state))
720 ("SuspendMode" (sleep-list elogind-suspend-mode))
721 ("HibernateState" (sleep-list elogind-hibernate-state))
722 ("HibernateMode" (sleep-list elogind-hibernate-mode))
723 ("HybridSleepState" (sleep-list elogind-hybrid-sleep-state))
724 ("HybridSleepMode" (sleep-list elogind-hybrid-sleep-mode))))
725
956ad60c
LC
726(define (elogind-dbus-service config)
727 (list (wrapped-dbus-service (elogind-package config)
728 "libexec/elogind/elogind"
729 "ELOGIND_CONF_FILE"
730 (elogind-configuration-file config))))
0adfe95a 731
e7ad0d58
LC
732(define (pam-extension-procedure config)
733 "Return an extension for PAM-ROOT-SERVICE-TYPE that ensures that all the PAM
734services use 'pam_elogind.so', a module that allows elogind to keep track of
735logged-in users (run 'loginctl' to see elogind's world view of users and
736seats.)"
737 (define pam-elogind
738 (pam-entry
739 (control "required")
9e41130b
LC
740 (module (file-append (elogind-package config)
741 "/lib/security/pam_elogind.so"))))
e7ad0d58
LC
742
743 (list (lambda (pam)
744 (pam-service
745 (inherit pam)
746 (session (cons pam-elogind (pam-service-session pam)))))))
747
0adfe95a
LC
748(define elogind-service-type
749 (service-type (name 'elogind)
750 (extensions
956ad60c
LC
751 (list (service-extension dbus-root-service-type
752 elogind-dbus-service)
0adfe95a
LC
753 (service-extension udev-service-type
754 (compose list elogind-package))
222e3319
LC
755 (service-extension polkit-service-type
756 (compose list elogind-package))
05c5b165
LC
757
758 ;; Provide the 'loginctl' command.
759 (service-extension profile-service-type
760 (compose list elogind-package))
761
e7ad0d58
LC
762 ;; Extend PAM with pam_elogind.so.
763 (service-extension pam-root-service-type
38c2b503
LC
764 pam-extension-procedure)
765
766 ;; We need /run/user, /run/systemd, etc.
767 (service-extension file-system-service-type
768 (const %elogind-file-systems))))))
0adfe95a
LC
769
770(define* (elogind-service #:key (config (elogind-configuration)))
04463bb0
AW
771 "Return a service that runs the @command{elogind} login and seat management
772service. The @command{elogind} service integrates with PAM to allow other
773system components to know the set of logged-in users as well as their session
774types (graphical, console, remote, etc.). It can also clean up after users
775when they log out."
0adfe95a 776 (service elogind-service-type config))
04463bb0
AW
777
778\f
7a2413e4
AW
779;;;
780;;; GNOME desktop service.
781;;;
782
783(define-record-type* <gnome-desktop-configuration> gnome-desktop-configuration
784 make-gnome-desktop-configuration
785 gnome-desktop-configuration
786 (gnome-package gnome-package (default gnome)))
787
788(define gnome-desktop-service-type
789 (service-type
790 (name 'gnome-desktop)
791 (extensions
792 (list (service-extension polkit-service-type
793 (compose list
794 (package-direct-input-selector
795 "gnome-settings-daemon")
796 gnome-package))
797 (service-extension profile-service-type
798 (compose list
799 gnome-package))))))
800
801(define* (gnome-desktop-service #:key (config (gnome-desktop-configuration)))
802 "Return a service that adds the @code{gnome} package to the system profile,
803and extends polkit with the actions from @code{gnome-settings-daemon}."
804 (service gnome-desktop-service-type config))
805
806\f
807;;;
808;;; XFCE desktop service.
809;;;
810
811(define-record-type* <xfce-desktop-configuration> xfce-desktop-configuration
812 make-xfce-desktop-configuration
813 xfce-desktop-configuration
814 (xfce xfce-package (default xfce)))
815
816(define xfce-desktop-service-type
817 (service-type
818 (name 'xfce-desktop)
819 (extensions
820 (list (service-extension polkit-service-type
821 (compose list
822 (package-direct-input-selector
823 "thunar")
824 xfce-package))
825 (service-extension profile-service-type
826 (compose list
827 xfce-package))))))
828
829(define* (xfce-desktop-service #:key (config (xfce-desktop-configuration)))
830 "Return a service that adds the @code{xfce} package to the system profile,
705b9714 831and extends polkit with the ability for @code{thunar} to manipulate the file
7a2413e4
AW
832system as root from within a user session, after the user has authenticated
833with the administrator's password."
834 (service xfce-desktop-service-type config))
835
836\f
cee32ee4
AW
837;;;
838;;; The default set of desktop services.
839;;;
0adfe95a 840
4467be21
LC
841(define %desktop-services
842 ;; List of services typically useful for a "desktop" use case.
843 (cons* (slim-service)
844
6726282b
LC
845 ;; Screen lockers are a pretty useful thing and these are small.
846 (screen-locker-service slock)
847 (screen-locker-service xlockmore "xlock")
848
0adfe95a 849 ;; The D-Bus clique.
4467be21
LC
850 (avahi-service)
851 (wicd-service)
2b9e0a94 852 (udisks-service)
4467be21
LC
853 (upower-service)
854 (colord-service)
cee32ee4 855 (geoclue-service)
0071c789 856 (polkit-service)
04463bb0 857 (elogind-service)
0adfe95a 858 (dbus-service)
4467be21
LC
859
860 (ntp-service)
4467be21 861
0adfe95a 862 %base-services))
4467be21 863
fe1a39d3 864;;; desktop.scm ends here