services: elogind, gnome, mate, xfce: Fix config type predicate identifiers.
[jackhill/guix/guix.git] / gnu / services / desktop.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
4 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
5 ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
6 ;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
7 ;;; Copyright © 2017 ng0 <ng0@n0.is>
8 ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
9 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
10 ;;; Copyright © 2017, 2019 Christopher Baines <mail@cbaines.net>
11 ;;; Copyright © 2019 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
12 ;;; Copyright © 2019 David Wilson <david@daviwil.com>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu services desktop)
30 #:use-module (gnu services)
31 #:use-module (gnu services shepherd)
32 #:use-module (gnu services base)
33 #:use-module (gnu services dbus)
34 #:use-module (gnu services avahi)
35 #:use-module (gnu services xorg)
36 #:use-module (gnu services networking)
37 #:use-module (gnu services sound)
38 #:use-module ((gnu system file-systems)
39 #:select (%elogind-file-systems))
40 #:use-module (gnu system)
41 #:use-module (gnu system shadow)
42 #:use-module (gnu system pam)
43 #:use-module (gnu packages glib)
44 #:use-module (gnu packages admin)
45 #:use-module (gnu packages cups)
46 #:use-module (gnu packages freedesktop)
47 #:use-module (gnu packages gnome)
48 #:use-module (gnu packages xfce)
49 #:use-module (gnu packages avahi)
50 #:use-module (gnu packages xdisorg)
51 #:use-module (gnu packages suckless)
52 #:use-module (gnu packages linux)
53 #:use-module (gnu packages libusb)
54 #:use-module (gnu packages mate)
55 #:use-module (gnu packages enlightenment)
56 #:use-module (guix deprecation)
57 #:use-module (guix records)
58 #:use-module (guix packages)
59 #:use-module (guix store)
60 #:use-module (guix utils)
61 #:use-module (guix gexp)
62 #:use-module (srfi srfi-1)
63 #:use-module (ice-9 match)
64 #:export (<upower-configuration>
65 upower-configuration
66 upower-configuration?
67 upower-configuration-upower
68 upower-configuration-watts-up-pro?
69 upower-configuration-poll-batteries?
70 upower-configuration-ignore-lid?
71 upower-configuration-use-percentage-for-policy?
72 upower-configuration-percentage-low
73 upower-configuration-percentage-critical
74 upower-configuration-percentage-action
75 upower-configuration-time-low
76 upower-configuration-time-critical
77 upower-configuration-time-action
78 upower-configuration-critical-power-action
79
80 upower-service
81 upower-service-type
82
83 udisks-configuration
84 udisks-configuration?
85 udisks-service
86 udisks-service-type
87
88 colord-service-type
89 colord-service
90
91 geoclue-application
92 geoclue-configuration
93 geoclue-configuration?
94 %standard-geoclue-applications
95 geoclue-service
96 geoclue-service-type
97
98 bluetooth-service-type
99 bluetooth-configuration
100 bluetooth-configuration?
101 bluetooth-service
102
103 elogind-configuration
104 elogind-configuration?
105 elogind-service
106 elogind-service-type
107
108 accountsservice-service-type
109 accountsservice-service
110
111 cups-pk-helper-service-type
112
113 gnome-desktop-configuration
114 gnome-desktop-configuration?
115 gnome-desktop-service
116 gnome-desktop-service-type
117
118 mate-desktop-configuration
119 mate-desktop-configuration?
120 mate-desktop-service
121 mate-desktop-service-type
122
123 xfce-desktop-configuration
124 xfce-desktop-configuration?
125 xfce-desktop-service
126 xfce-desktop-service-type
127
128 x11-socket-directory-service
129
130 enlightenment-desktop-configuration
131 enlightenment-desktop-configuration?
132 enlightenment-desktop-service-type
133
134 inputattach-configuration
135 inputattach-configuration?
136 inputattach-service-type
137
138 %desktop-services))
139
140 ;;; Commentary:
141 ;;;
142 ;;; This module contains service definitions for a "desktop" environment.
143 ;;;
144 ;;; Code:
145
146 \f
147 ;;;
148 ;;; Helpers.
149 ;;;
150
151 (define (bool value)
152 (if value "true\n" "false\n"))
153
154 (define (package-direct-input-selector input)
155 (lambda (package)
156 (match (assoc-ref (package-direct-inputs package) input)
157 ((package . _) package))))
158
159
160 \f
161 ;;;
162 ;;; Upower D-Bus service.
163 ;;;
164
165 (define-record-type* <upower-configuration>
166 upower-configuration make-upower-configuration
167 upower-configuration?
168 (upower upower-configuration-upower
169 (default upower))
170 (watts-up-pro? upower-configuration-watts-up-pro?
171 (default #f))
172 (poll-batteries? upower-configuration-poll-batteries?
173 (default #t))
174 (ignore-lid? upower-configuration-ignore-lid?
175 (default #f))
176 (use-percentage-for-policy? upower-configuration-use-percentage-for-policy?
177 (default #f))
178 (percentage-low upower-configuration-percentage-low
179 (default 10))
180 (percentage-critical upower-configuration-percentage-critical
181 (default 3))
182 (percentage-action upower-configuration-percentage-action
183 (default 2))
184 (time-low upower-configuration-time-low
185 (default 1200))
186 (time-critical upower-configuration-time-critical
187 (default 300))
188 (time-action upower-configuration-time-action
189 (default 120))
190 (critical-power-action upower-configuration-critical-power-action
191 (default 'hybrid-sleep)))
192
193 (define* upower-configuration-file
194 ;; Return an upower-daemon configuration file.
195 (match-lambda
196 (($ <upower-configuration> upower
197 watts-up-pro? poll-batteries? ignore-lid? use-percentage-for-policy?
198 percentage-low percentage-critical percentage-action time-low
199 time-critical time-action critical-power-action)
200 (plain-file "UPower.conf"
201 (string-append
202 "[UPower]\n"
203 "EnableWattsUpPro=" (bool watts-up-pro?)
204 "NoPollBatteries=" (bool (not poll-batteries?))
205 "IgnoreLid=" (bool ignore-lid?)
206 "UsePercentageForPolicy=" (bool use-percentage-for-policy?)
207 "PercentageLow=" (number->string percentage-low) "\n"
208 "PercentageCritical=" (number->string percentage-critical) "\n"
209 "PercentageAction=" (number->string percentage-action) "\n"
210 "TimeLow=" (number->string time-low) "\n"
211 "TimeCritical=" (number->string time-critical) "\n"
212 "TimeAction=" (number->string time-action) "\n"
213 "CriticalPowerAction=" (match critical-power-action
214 ('hybrid-sleep "HybridSleep")
215 ('hibernate "Hibernate")
216 ('power-off "PowerOff"))
217 "\n")))))
218
219 (define %upower-activation
220 #~(begin
221 (use-modules (guix build utils))
222 (mkdir-p "/var/lib/upower")))
223
224 (define (upower-dbus-service config)
225 (list (wrapped-dbus-service (upower-configuration-upower config)
226 "libexec/upowerd"
227 `(("UPOWER_CONF_FILE_NAME"
228 ,(upower-configuration-file config))))))
229
230 (define (upower-shepherd-service config)
231 "Return a shepherd service for UPower with CONFIG."
232 (let ((upower (upower-configuration-upower config))
233 (config (upower-configuration-file config)))
234 (list (shepherd-service
235 (documentation "Run the UPower power and battery monitor.")
236 (provision '(upower-daemon))
237 (requirement '(dbus-system udev))
238
239 (start #~(make-forkexec-constructor
240 (list (string-append #$upower "/libexec/upowerd"))
241 #:environment-variables
242 (list (string-append "UPOWER_CONF_FILE_NAME="
243 #$config))))
244 (stop #~(make-kill-destructor))))))
245
246 (define upower-service-type
247 (let ((upower-package (compose list upower-configuration-upower)))
248 (service-type (name 'upower)
249 (description
250 "Run @command{upowerd}}, a system-wide monitor for power
251 consumption and battery levels, with the given configuration settings. It
252 implements the @code{org.freedesktop.UPower} D-Bus interface, and is notably
253 used by GNOME.")
254 (extensions
255 (list (service-extension dbus-root-service-type
256 upower-dbus-service)
257 (service-extension shepherd-root-service-type
258 upower-shepherd-service)
259 (service-extension activation-service-type
260 (const %upower-activation))
261 (service-extension udev-service-type
262 upower-package)
263
264 ;; Make the 'upower' command visible.
265 (service-extension profile-service-type
266 upower-package)))
267 (default-value (upower-configuration)))))
268
269 (define-deprecated (upower-service #:key (upower upower)
270 (watts-up-pro? #f)
271 (poll-batteries? #t)
272 (ignore-lid? #f)
273 (use-percentage-for-policy? #f)
274 (percentage-low 10)
275 (percentage-critical 3)
276 (percentage-action 2)
277 (time-low 1200)
278 (time-critical 300)
279 (time-action 120)
280 (critical-power-action 'hybrid-sleep))
281 upower-service-type
282 "Return a service that runs @uref{http://upower.freedesktop.org/,
283 @command{upowerd}}, a system-wide monitor for power consumption and battery
284 levels, with the given configuration settings. It implements the
285 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by GNOME."
286 (let ((config (upower-configuration
287 (watts-up-pro? watts-up-pro?)
288 (poll-batteries? poll-batteries?)
289 (ignore-lid? ignore-lid?)
290 (use-percentage-for-policy? use-percentage-for-policy?)
291 (percentage-low percentage-low)
292 (percentage-critical percentage-critical)
293 (percentage-action percentage-action)
294 (time-low time-low)
295 (time-critical time-critical)
296 (time-action time-action)
297 (critical-power-action critical-power-action))))
298 (service upower-service-type config)))
299
300 \f
301 ;;;
302 ;;; GeoClue D-Bus service.
303 ;;;
304
305 ;; TODO: Export.
306 (define-record-type* <geoclue-configuration>
307 geoclue-configuration make-geoclue-configuration
308 geoclue-configuration?
309 (geoclue geoclue-configuration-geoclue
310 (default geoclue))
311 (whitelist geoclue-configuration-whitelist)
312 (wifi-geolocation-url geoclue-configuration-wifi-geolocation-url)
313 (submit-data? geoclue-configuration-submit-data?)
314 (wifi-submission-url geoclue-configuration-wifi-submission-url)
315 (submission-nick geoclue-configuration-submission-nick)
316 (applications geoclue-configuration-applications))
317
318 (define* (geoclue-application name #:key (allowed? #t) system? (users '()))
319 "Configure default GeoClue access permissions for an application. NAME is
320 the Desktop ID of the application, without the .desktop part. If ALLOWED? is
321 true, the application will have access to location information by default.
322 The boolean SYSTEM? value indicates that an application is a system component
323 or not. Finally USERS is a list of UIDs of all users for which this
324 application is allowed location info access. An empty users list means all
325 users are allowed."
326 (string-append
327 "[" name "]\n"
328 "allowed=" (bool allowed?)
329 "system=" (bool system?)
330 "users=" (string-join users ";") "\n"))
331
332 (define %standard-geoclue-applications
333 (list (geoclue-application "gnome-datetime-panel" #:system? #t)
334 (geoclue-application "epiphany" #:system? #f)
335 (geoclue-application "firefox" #:system? #f)))
336
337 (define* (geoclue-configuration-file config)
338 "Return a geoclue configuration file."
339 (plain-file "geoclue.conf"
340 (string-append
341 "[agent]\n"
342 "whitelist="
343 (string-join (geoclue-configuration-whitelist config)
344 ";") "\n"
345 "[wifi]\n"
346 "url=" (geoclue-configuration-wifi-geolocation-url config) "\n"
347 "submit-data=" (bool (geoclue-configuration-submit-data? config))
348 "submission-url="
349 (geoclue-configuration-wifi-submission-url config) "\n"
350 "submission-nick="
351 (geoclue-configuration-submission-nick config)
352 "\n"
353 (string-join (geoclue-configuration-applications config)
354 "\n"))))
355
356 (define (geoclue-dbus-service config)
357 (list (wrapped-dbus-service (geoclue-configuration-geoclue config)
358 "libexec/geoclue"
359 `(("GEOCLUE_CONFIG_FILE"
360 ,(geoclue-configuration-file config))))))
361
362 (define %geoclue-accounts
363 (list (user-group (name "geoclue") (system? #t))
364 (user-account
365 (name "geoclue")
366 (group "geoclue")
367 (system? #t)
368 (comment "GeoClue daemon user")
369 (home-directory "/var/empty")
370 (shell "/run/current-system/profile/sbin/nologin"))))
371
372 (define geoclue-service-type
373 (service-type (name 'geoclue)
374 (extensions
375 (list (service-extension dbus-root-service-type
376 geoclue-dbus-service)
377 (service-extension account-service-type
378 (const %geoclue-accounts))))))
379
380 (define* (geoclue-service #:key (geoclue geoclue)
381 (whitelist '())
382 (wifi-geolocation-url
383 ;; Mozilla geolocation service:
384 "https://location.services.mozilla.com/v1/geolocate?key=geoclue")
385 (submit-data? #f)
386 (wifi-submission-url
387 "https://location.services.mozilla.com/v1/submit?key=geoclue")
388 (submission-nick "geoclue")
389 (applications %standard-geoclue-applications))
390 "Return a service that runs the @command{geoclue} location service. This
391 service provides a D-Bus interface to allow applications to request access to
392 a user's physical location, and optionally to add information to online
393 location databases. By default, only the GNOME date-time panel and the Icecat
394 and Epiphany web browsers are able to ask for the user's location, and in the
395 case of Icecat and Epiphany, both will ask the user for permission first. See
396 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the geoclue web
397 site} for more information."
398 (service geoclue-service-type
399 (geoclue-configuration
400 (geoclue geoclue)
401 (whitelist whitelist)
402 (wifi-geolocation-url wifi-geolocation-url)
403 (submit-data? submit-data?)
404 (wifi-submission-url wifi-submission-url)
405 (submission-nick submission-nick)
406 (applications applications))))
407
408 \f
409 ;;;
410 ;;; Bluetooth.
411 ;;;
412
413 (define-record-type* <bluetooth-configuration>
414 bluetooth-configuration make-bluetooth-configuration
415 bluetooth-configuration?
416 (bluez bluetooth-configuration-bluez (default bluez))
417 (auto-enable? bluetooth-configuration-auto-enable? (default #f)))
418
419 (define (bluetooth-configuration-file config)
420 "Return a configuration file for the systemd bluetooth service, as a string."
421 (string-append
422 "[Policy]\n"
423 "AutoEnable=" (bool (bluetooth-configuration-auto-enable?
424 config))))
425
426 (define (bluetooth-directory config)
427 (computed-file "etc-bluetooth"
428 #~(begin
429 (mkdir #$output)
430 (chdir #$output)
431 (call-with-output-file "main.conf"
432 (lambda (port)
433 (display #$(bluetooth-configuration-file config)
434 port))))))
435
436 (define (bluetooth-shepherd-service config)
437 "Return a shepherd service for @command{bluetoothd}."
438 (shepherd-service
439 (provision '(bluetooth))
440 (requirement '(dbus-system udev))
441 (documentation "Run the bluetoothd daemon.")
442 (start #~(make-forkexec-constructor
443 (string-append #$(bluetooth-configuration-bluez config)
444 "/libexec/bluetooth/bluetoothd")))
445 (stop #~(make-kill-destructor))))
446
447 (define bluetooth-service-type
448 (service-type
449 (name 'bluetooth)
450 (extensions
451 (list (service-extension dbus-root-service-type
452 (compose list bluetooth-configuration-bluez))
453 (service-extension udev-service-type
454 (compose list bluetooth-configuration-bluez))
455 (service-extension etc-service-type
456 (lambda (config)
457 `(("bluetooth"
458 ,(bluetooth-directory config)))))
459 (service-extension shepherd-root-service-type
460 (compose list bluetooth-shepherd-service))))
461 (description "Run the @command{bluetoothd} daemon, which manages all the
462 Bluetooth devices and provides a number of D-Bus interfaces.")))
463
464 (define* (bluetooth-service #:key (bluez bluez) (auto-enable? #f))
465 "Return a service that runs the @command{bluetoothd} daemon, which manages
466 all the Bluetooth devices and provides a number of D-Bus interfaces. When
467 AUTO-ENABLE? is true, the bluetooth controller is powered automatically at
468 boot.
469
470 Users need to be in the @code{lp} group to access the D-Bus service.
471 "
472 (service bluetooth-service-type
473 (bluetooth-configuration
474 (bluez bluez)
475 (auto-enable? auto-enable?))))
476
477 \f
478 ;;;
479 ;;; Colord D-Bus service.
480 ;;;
481
482 (define %colord-activation
483 #~(begin
484 (use-modules (guix build utils))
485 (mkdir-p "/var/lib/colord")
486 (let ((user (getpwnam "colord")))
487 (chown "/var/lib/colord"
488 (passwd:uid user) (passwd:gid user)))))
489
490 (define %colord-accounts
491 (list (user-group (name "colord") (system? #t))
492 (user-account
493 (name "colord")
494 (group "colord")
495 (system? #t)
496 (comment "colord daemon user")
497 (home-directory "/var/empty")
498 (shell (file-append shadow "/sbin/nologin")))))
499
500 (define colord-service-type
501 (service-type (name 'colord)
502 (extensions
503 (list (service-extension account-service-type
504 (const %colord-accounts))
505 (service-extension activation-service-type
506 (const %colord-activation))
507
508 ;; Colord is a D-Bus service that dbus-daemon can
509 ;; activate.
510 (service-extension dbus-root-service-type list)
511
512 ;; Colord provides "color device" rules for udev.
513 (service-extension udev-service-type list)
514
515 ;; It provides polkit "actions".
516 (service-extension polkit-service-type list)))
517 (description
518 "Run @command{colord}, a system service with a D-Bus
519 interface to manage the color profiles of input and output devices such as
520 screens and scanners.")))
521
522 (define* (colord-service #:key (colord colord))
523 "Return a service that runs @command{colord}, a system service with a D-Bus
524 interface to manage the color profiles of input and output devices such as
525 screens and scanners. It is notably used by the GNOME Color Manager graphical
526 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
527 site} for more information."
528 (service colord-service-type colord))
529
530 \f
531 ;;;
532 ;;; UDisks.
533 ;;;
534
535 (define-record-type* <udisks-configuration>
536 udisks-configuration make-udisks-configuration
537 udisks-configuration?
538 (udisks udisks-configuration-udisks
539 (default udisks)))
540
541 (define %udisks-activation
542 (with-imported-modules '((guix build utils))
543 #~(begin
544 (use-modules (guix build utils))
545
546 (let ((run-dir "/var/run/udisks2"))
547 (mkdir-p run-dir)
548 (chmod run-dir #o700)))))
549
550 (define udisks-service-type
551 (let ((udisks-package (lambda (config)
552 (list (udisks-configuration-udisks config)))))
553 (service-type (name 'udisks)
554 (extensions
555 (list (service-extension polkit-service-type
556 udisks-package)
557 (service-extension dbus-root-service-type
558 udisks-package)
559 (service-extension udev-service-type
560 udisks-package)
561 (service-extension activation-service-type
562 (const %udisks-activation))
563
564 ;; Profile 'udisksctl' & co. in the system profile.
565 (service-extension profile-service-type
566 udisks-package))))))
567
568 (define* (udisks-service #:key (udisks udisks))
569 "Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
570 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
571 notifications and ways to mount/unmount disks. Programs that talk to UDisks
572 include the @command{udisksctl} command, part of UDisks, and GNOME Disks."
573 (service udisks-service-type
574 (udisks-configuration (udisks udisks))))
575
576 \f
577 ;;;
578 ;;; Elogind login and seat management service.
579 ;;;
580
581 (define-record-type* <elogind-configuration> elogind-configuration
582 make-elogind-configuration
583 elogind-configuration?
584 (elogind elogind-package
585 (default elogind))
586 (kill-user-processes? elogind-kill-user-processes?
587 (default #f))
588 (kill-only-users elogind-kill-only-users
589 (default '()))
590 (kill-exclude-users elogind-kill-exclude-users
591 (default '("root")))
592 (inhibit-delay-max-seconds elogind-inhibit-delay-max-seconds
593 (default 5))
594 (handle-power-key elogind-handle-power-key
595 (default 'poweroff))
596 (handle-suspend-key elogind-handle-suspend-key
597 (default 'suspend))
598 (handle-hibernate-key elogind-handle-hibernate-key
599 ;; (default 'hibernate)
600 ;; XXX Ignore it for now, since we don't
601 ;; yet handle resume-from-hibernation in
602 ;; our initrd.
603 (default 'ignore))
604 (handle-lid-switch elogind-handle-lid-switch
605 (default 'suspend))
606 (handle-lid-switch-docked elogind-handle-lid-switch-docked
607 (default 'ignore))
608 (power-key-ignore-inhibited? elogind-power-key-ignore-inhibited?
609 (default #f))
610 (suspend-key-ignore-inhibited? elogind-suspend-key-ignore-inhibited?
611 (default #f))
612 (hibernate-key-ignore-inhibited? elogind-hibernate-key-ignore-inhibited?
613 (default #f))
614 (lid-switch-ignore-inhibited? elogind-lid-switch-ignore-inhibited?
615 (default #t))
616 (holdoff-timeout-seconds elogind-holdoff-timeout-seconds
617 (default 30))
618 (idle-action elogind-idle-action
619 (default 'ignore))
620 (idle-action-seconds elogind-idle-action-seconds
621 (default (* 30 60)))
622 (runtime-directory-size-percent elogind-runtime-directory-size-percent
623 (default 10))
624 (runtime-directory-size elogind-runtime-directory-size
625 (default #f))
626 (remove-ipc? elogind-remove-ipc?
627 (default #t))
628
629 (suspend-state elogind-suspend-state
630 (default '("mem" "standby" "freeze")))
631 (suspend-mode elogind-suspend-mode
632 (default '()))
633 (hibernate-state elogind-hibernate-state
634 (default '("disk")))
635 (hibernate-mode elogind-hibernate-mode
636 (default '("platform" "shutdown")))
637 (hybrid-sleep-state elogind-hybrid-sleep-state
638 (default '("disk")))
639 (hybrid-sleep-mode elogind-hybrid-sleep-mode
640 (default
641 '("suspend" "platform" "shutdown"))))
642
643 (define (elogind-configuration-file config)
644 (define (yesno x)
645 (match x
646 (#t "yes")
647 (#f "no")
648 (_ (error "expected #t or #f, instead got:" x))))
649 (define char-set:user-name
650 (string->char-set "abcdefghijklmnopqrstuvwxyz0123456789_-"))
651 (define (valid-list? l pred)
652 (and-map (lambda (x) (string-every pred x)) l))
653 (define (user-name-list users)
654 (unless (valid-list? users char-set:user-name)
655 (error "invalid user list" users))
656 (string-join users " "))
657 (define (enum val allowed)
658 (unless (memq val allowed)
659 (error "invalid value" val allowed))
660 (symbol->string val))
661 (define (non-negative-integer x)
662 (unless (exact-integer? x) (error "not an integer" x))
663 (when (negative? x) (error "negative number not allowed" x))
664 (number->string x))
665 (define handle-actions
666 '(ignore poweroff reboot halt kexec suspend hibernate hybrid-sleep lock))
667 (define (handle-action x)
668 (enum x handle-actions))
669 (define (sleep-list tokens)
670 (unless (valid-list? tokens char-set:user-name)
671 (error "invalid sleep list" tokens))
672 (string-join tokens " "))
673 (define-syntax ini-file-clause
674 (syntax-rules ()
675 ((_ config (prop (parser getter)))
676 (string-append prop "=" (parser (getter config)) "\n"))
677 ((_ config str)
678 (string-append str "\n"))))
679 (define-syntax-rule (ini-file config file clause ...)
680 (plain-file file (string-append (ini-file-clause config clause) ...)))
681 (ini-file
682 config "logind.conf"
683 "[Login]"
684 ("KillUserProcesses" (yesno elogind-kill-user-processes?))
685 ("KillOnlyUsers" (user-name-list elogind-kill-only-users))
686 ("KillExcludeUsers" (user-name-list elogind-kill-exclude-users))
687 ("InhibitDelayMaxSec" (non-negative-integer elogind-inhibit-delay-max-seconds))
688 ("HandlePowerKey" (handle-action elogind-handle-power-key))
689 ("HandleSuspendKey" (handle-action elogind-handle-suspend-key))
690 ("HandleHibernateKey" (handle-action elogind-handle-hibernate-key))
691 ("HandleLidSwitch" (handle-action elogind-handle-lid-switch))
692 ("HandleLidSwitchDocked" (handle-action elogind-handle-lid-switch-docked))
693 ("PowerKeyIgnoreInhibited" (yesno elogind-power-key-ignore-inhibited?))
694 ("SuspendKeyIgnoreInhibited" (yesno elogind-suspend-key-ignore-inhibited?))
695 ("HibernateKeyIgnoreInhibited" (yesno elogind-hibernate-key-ignore-inhibited?))
696 ("LidSwitchIgnoreInhibited" (yesno elogind-lid-switch-ignore-inhibited?))
697 ("HoldoffTimeoutSec" (non-negative-integer elogind-holdoff-timeout-seconds))
698 ("IdleAction" (handle-action elogind-idle-action))
699 ("IdleActionSec" (non-negative-integer elogind-idle-action-seconds))
700 ("RuntimeDirectorySize"
701 (identity
702 (lambda (config)
703 (match (elogind-runtime-directory-size-percent config)
704 (#f (non-negative-integer (elogind-runtime-directory-size config)))
705 (percent (string-append (non-negative-integer percent) "%"))))))
706 ("RemoveIPC" (yesno elogind-remove-ipc?))
707 "[Sleep]"
708 ("SuspendState" (sleep-list elogind-suspend-state))
709 ("SuspendMode" (sleep-list elogind-suspend-mode))
710 ("HibernateState" (sleep-list elogind-hibernate-state))
711 ("HibernateMode" (sleep-list elogind-hibernate-mode))
712 ("HybridSleepState" (sleep-list elogind-hybrid-sleep-state))
713 ("HybridSleepMode" (sleep-list elogind-hybrid-sleep-mode))))
714
715 (define (elogind-dbus-service config)
716 (list (wrapped-dbus-service (elogind-package config)
717 "libexec/elogind/elogind"
718 `(("ELOGIND_CONF_FILE"
719 ,(elogind-configuration-file config))))))
720
721 (define (pam-extension-procedure config)
722 "Return an extension for PAM-ROOT-SERVICE-TYPE that ensures that all the PAM
723 services use 'pam_elogind.so', a module that allows elogind to keep track of
724 logged-in users (run 'loginctl' to see elogind's world view of users and
725 seats.)"
726 (define pam-elogind
727 (pam-entry
728 (control "required")
729 (module (file-append (elogind-package config)
730 "/lib/security/pam_elogind.so"))))
731
732 (list (lambda (pam)
733 (pam-service
734 (inherit pam)
735 (session (cons pam-elogind (pam-service-session pam)))))))
736
737 (define (elogind-shepherd-service config)
738 "Return a Shepherd service to start elogind according to @var{config}."
739 (list (shepherd-service
740 (requirement '(dbus-system))
741 (provision '(elogind))
742 (start #~(make-forkexec-constructor
743 (list #$(file-append (elogind-package config)
744 "/libexec/elogind/elogind"))
745 #:environment-variables
746 (list (string-append "ELOGIND_CONF_FILE="
747 #$(elogind-configuration-file
748 config)))))
749 (stop #~(make-kill-destructor)))))
750
751 (define elogind-service-type
752 (service-type (name 'elogind)
753 (extensions
754 (list (service-extension dbus-root-service-type
755 elogind-dbus-service)
756 (service-extension udev-service-type
757 (compose list elogind-package))
758 (service-extension polkit-service-type
759 (compose list elogind-package))
760
761 ;; Start elogind from the Shepherd rather than waiting
762 ;; for bus activation. This ensures that it can handle
763 ;; events like lid close, etc.
764 (service-extension shepherd-root-service-type
765 elogind-shepherd-service)
766
767 ;; Provide the 'loginctl' command.
768 (service-extension profile-service-type
769 (compose list elogind-package))
770
771 ;; Extend PAM with pam_elogind.so.
772 (service-extension pam-root-service-type
773 pam-extension-procedure)
774
775 ;; We need /run/user, /run/systemd, etc.
776 (service-extension file-system-service-type
777 (const %elogind-file-systems))))
778 (default-value (elogind-configuration))))
779
780 (define* (elogind-service #:key (config (elogind-configuration)))
781 "Return a service that runs the @command{elogind} login and seat management
782 service. The @command{elogind} service integrates with PAM to allow other
783 system components to know the set of logged-in users as well as their session
784 types (graphical, console, remote, etc.). It can also clean up after users
785 when they log out."
786 (service elogind-service-type config))
787
788 \f
789 ;;;
790 ;;; AccountsService service.
791 ;;;
792
793 (define %accountsservice-activation
794 #~(begin
795 (use-modules (guix build utils))
796 (mkdir-p "/var/lib/AccountsService")))
797
798 (define accountsservice-service-type
799 (service-type (name 'accountsservice)
800 (extensions
801 (list (service-extension activation-service-type
802 (const %accountsservice-activation))
803 (service-extension dbus-root-service-type list)
804 (service-extension polkit-service-type list)))))
805
806 (define* (accountsservice-service #:key (accountsservice accountsservice))
807 "Return a service that runs AccountsService, a system service that
808 can list available accounts, change their passwords, and so on.
809 AccountsService integrates with PolicyKit to enable unprivileged users to
810 acquire the capability to modify their system configuration.
811 @uref{https://www.freedesktop.org/wiki/Software/AccountsService/, the
812 accountsservice web site} for more information."
813 (service accountsservice-service-type accountsservice))
814
815 \f
816 ;;;
817 ;;; cups-pk-helper service.
818 ;;;
819
820 (define cups-pk-helper-service-type
821 (service-type
822 (name 'cups-pk-helper)
823 (description
824 "PolicyKit helper to configure CUPS with fine-grained privileges.")
825 (extensions
826 (list (service-extension dbus-root-service-type list)
827 (service-extension polkit-service-type list)))
828 (default-value cups-pk-helper)))
829
830 \f
831 ;;;
832 ;;; GNOME desktop service.
833 ;;;
834
835 (define-record-type* <gnome-desktop-configuration> gnome-desktop-configuration
836 make-gnome-desktop-configuration
837 gnome-desktop-configuration?
838 (gnome-package gnome-package (default gnome)))
839
840 (define (gnome-polkit-settings config)
841 "Return the list of GNOME dependencies that provide polkit actions and
842 rules."
843 (let ((gnome (gnome-package config)))
844 (map (lambda (name)
845 ((package-direct-input-selector name) gnome))
846 '("gnome-settings-daemon"
847 "gnome-control-center"
848 "gnome-system-monitor"
849 "gvfs"))))
850
851 (define gnome-desktop-service-type
852 (service-type
853 (name 'gnome-desktop)
854 (extensions
855 (list (service-extension polkit-service-type
856 gnome-polkit-settings)
857 (service-extension profile-service-type
858 (compose list
859 gnome-package))))
860 (default-value (gnome-desktop-configuration))
861 (description "Run the GNOME desktop environment.")))
862
863 (define-deprecated (gnome-desktop-service #:key (config
864 (gnome-desktop-configuration)))
865 gnome-desktop-service-type
866 "Return a service that adds the @code{gnome} package to the system profile,
867 and extends polkit with the actions from @code{gnome-settings-daemon}."
868 (service gnome-desktop-service-type config))
869
870 ;; MATE Desktop service.
871 ;; TODO: Add mate-screensaver.
872
873 (define-record-type* <mate-desktop-configuration> mate-desktop-configuration
874 make-mate-desktop-configuration
875 mate-desktop-configuration?
876 (mate-package mate-package (default mate)))
877
878 (define mate-desktop-service-type
879 (service-type
880 (name 'mate-desktop)
881 (extensions
882 (list (service-extension polkit-service-type
883 (compose list
884 (package-direct-input-selector
885 "mate-settings-daemon")
886 mate-package))
887 (service-extension profile-service-type
888 (compose list
889 mate-package))))
890 (default-value (mate-desktop-configuration))
891 (description "Run the MATE desktop environment.")))
892
893 (define-deprecated (mate-desktop-service #:key
894 (config
895 (mate-desktop-configuration)))
896 mate-desktop-service-type
897 "Return a service that adds the @code{mate} package to the system profile,
898 and extends polkit with the actions from @code{mate-settings-daemon}."
899 (service mate-desktop-service-type config))
900
901 \f
902 ;;;
903 ;;; XFCE desktop service.
904 ;;;
905
906 (define-record-type* <xfce-desktop-configuration> xfce-desktop-configuration
907 make-xfce-desktop-configuration
908 xfce-desktop-configuration?
909 (xfce xfce-package (default xfce)))
910
911 (define (xfce-polkit-settings config)
912 "Return the list of XFCE dependencies that provide polkit actions and
913 rules."
914 (let ((xfce (xfce-package config)))
915 (map (lambda (name)
916 ((package-direct-input-selector name) xfce))
917 '("thunar"
918 "xfce4-power-manager"))))
919
920 (define xfce-desktop-service-type
921 (service-type
922 (name 'xfce-desktop)
923 (extensions
924 (list (service-extension polkit-service-type
925 xfce-polkit-settings)
926 (service-extension profile-service-type
927 (compose list xfce-package))))
928 (default-value (xfce-desktop-configuration))
929 (description "Run the Xfce desktop environment.")))
930
931 (define-deprecated (xfce-desktop-service #:key (config
932 (xfce-desktop-configuration)))
933 xfce-desktop-service-type
934 "Return a service that adds the @code{xfce} package to the system profile,
935 and extends polkit with the ability for @code{thunar} to manipulate the file
936 system as root from within a user session, after the user has authenticated
937 with the administrator's password."
938 (service xfce-desktop-service-type config))
939
940 \f
941 ;;;
942 ;;; X11 socket directory service
943 ;;;
944
945 (define x11-socket-directory-service
946 ;; Return a service that creates /tmp/.X11-unix. When using X11, libxcb
947 ;; takes care of creating that directory. However, when using XWayland, we
948 ;; need to create beforehand. Thus, create it unconditionally here.
949 (simple-service 'x11-socket-directory
950 activation-service-type
951 (with-imported-modules '((guix build utils))
952 #~(begin
953 (use-modules (guix build utils))
954 (let ((directory "/tmp/.X11-unix"))
955 (mkdir-p directory)
956 (chmod directory #o777))))))
957 \f
958 ;;;
959 ;;; Enlightenment desktop service.
960 ;;;
961
962 (define-record-type* <enlightenment-desktop-configuration>
963 enlightenment-desktop-configuration make-enlightenment-desktop-configuration
964 enlightenment-desktop-configuration?
965 ;; <package>
966 (enlightenment enlightenment-package
967 (default enlightenment)))
968
969 (define (enlightenment-setuid-programs enlightenment-desktop-configuration)
970 (match-record enlightenment-desktop-configuration
971 <enlightenment-desktop-configuration>
972 (enlightenment)
973 (let ((module-arch (match (string-tokenize (%current-system)
974 (char-set-complement (char-set #\-)))
975 ((arch "linux") (string-append "linux-gnu-" arch))
976 ((arch "gnu") (string-append "gnu-" arch)))))
977 (list (file-append enlightenment
978 "/lib/enlightenment/utils/enlightenment_sys")
979 (file-append enlightenment
980 "/lib/enlightenment/utils/enlightenment_backlight")
981 ;; TODO: Move this binary to a screen-locker service.
982 (file-append enlightenment
983 "/lib/enlightenment/utils/enlightenment_ckpasswd")
984 (file-append enlightenment
985 (string-append
986 "/lib/enlightenment/modules/cpufreq/"
987 module-arch "-"
988 (package-version enlightenment)
989 "/freqset"))
990 (file-append enlightenment
991 (string-append
992 "/lib/enlightenment/modules/sysinfo/"
993 module-arch "-"
994 (package-version enlightenment)
995 "/cpuclock_sysfs"))))))
996
997 (define enlightenment-desktop-service-type
998 (service-type
999 (name 'enlightenment-desktop)
1000 (extensions
1001 (list (service-extension dbus-root-service-type
1002 (compose list
1003 (package-direct-input-selector
1004 "efl")
1005 enlightenment-package))
1006 (service-extension setuid-program-service-type
1007 enlightenment-setuid-programs)
1008 (service-extension profile-service-type
1009 (compose list
1010 enlightenment-package))))
1011 (default-value (enlightenment-desktop-configuration))
1012 (description
1013 "Return a service that adds the @code{enlightenment} package to the system
1014 profile, and extends dbus with the ability for @code{efl} to generate
1015 thumbnails and makes setuid the programs which enlightenment needs to function
1016 as expected.")))
1017
1018 \f
1019 ;;;
1020 ;;; inputattach-service-type
1021 ;;;
1022
1023 (define-record-type* <inputattach-configuration>
1024 inputattach-configuration
1025 make-inputattach-configuration
1026 inputattach-configuration?
1027 (device-type inputattach-configuration-device-type
1028 (default "wacom"))
1029 (device inputattach-configuration-device
1030 (default "/dev/ttyS0"))
1031 (baud-rate inputattach-configuration-baud-rate
1032 (default #f))
1033 (log-file inputattach-configuration-log-file
1034 (default #f)))
1035
1036 (define inputattach-shepherd-service
1037 (match-lambda
1038 (($ <inputattach-configuration> type device baud-rate log-file)
1039 (let ((args (append (if baud-rate
1040 (list "--baud-rate" (number->string baud-rate))
1041 '())
1042 (list (string-append "--" type)
1043 device))))
1044 (list (shepherd-service
1045 (provision '(inputattach))
1046 (requirement '(udev))
1047 (documentation "inputattach daemon")
1048 (start #~(make-forkexec-constructor
1049 (cons (string-append #$inputattach
1050 "/bin/inputattach")
1051 (quote #$args))
1052 #:log-file #$log-file))
1053 (stop #~(make-kill-destructor))))))))
1054
1055 (define inputattach-service-type
1056 (service-type
1057 (name 'inputattach)
1058 (extensions
1059 (list (service-extension shepherd-root-service-type
1060 inputattach-shepherd-service)))
1061 (default-value (inputattach-configuration))
1062 (description "Return a service that runs inputattach on a device and
1063 dispatches events from it.")))
1064
1065 \f
1066 ;;;
1067 ;;; The default set of desktop services.
1068 ;;;
1069
1070 (define %desktop-services
1071 ;; List of services typically useful for a "desktop" use case.
1072 (cons* (service gdm-service-type)
1073
1074 ;; Screen lockers are a pretty useful thing and these are small.
1075 (screen-locker-service slock)
1076 (screen-locker-service xlockmore "xlock")
1077
1078 ;; Add udev rules for MTP devices so that non-root users can access
1079 ;; them.
1080 (simple-service 'mtp udev-service-type (list libmtp))
1081
1082 ;; NetworkManager and its applet.
1083 (service network-manager-service-type)
1084 (service wpa-supplicant-service-type) ;needed by NetworkManager
1085 (simple-service 'network-manager-applet
1086 profile-service-type
1087 (list network-manager-applet))
1088 (service modem-manager-service-type)
1089 (service usb-modeswitch-service-type)
1090
1091 ;; The D-Bus clique.
1092 (service avahi-service-type)
1093 (udisks-service)
1094 (service upower-service-type)
1095 (accountsservice-service)
1096 (service cups-pk-helper-service-type)
1097 (colord-service)
1098 (geoclue-service)
1099 (service polkit-service-type)
1100 (elogind-service)
1101 (dbus-service)
1102
1103 (service ntp-service-type)
1104
1105 x11-socket-directory-service
1106
1107 (service alsa-service-type)
1108
1109 %base-services))
1110
1111 ;;; desktop.scm ends here