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