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