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