gnu: guix-data-service: Update to 0.0.1-7.156b7ee.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
CommitLineData
db4fdc04 1;;; GNU Guix --- Functional package management for GNU
92753a8b 2;;; Copyright © 2017 Andy Wingo <wingo@igalia.com>
01b3625d 3;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
4bd43bbe 4;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
e57c2adb 5;;; Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
24f11b06 6;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
bab7a495 7;;; Copyright © 2019 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
db4fdc04
LC
8;;;
9;;; This file is part of GNU Guix.
10;;;
11;;; GNU Guix is free software; you can redistribute it and/or modify it
12;;; under the terms of the GNU General Public License as published by
13;;; the Free Software Foundation; either version 3 of the License, or (at
14;;; your option) any later version.
15;;;
16;;; GNU Guix is distributed in the hope that it will be useful, but
17;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;;; GNU General Public License for more details.
20;;;
21;;; You should have received a copy of the GNU General Public License
22;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24(define-module (gnu services xorg)
84dfb458 25 #:use-module (gnu artwork)
db4fdc04 26 #:use-module (gnu services)
0190c1c0 27 #:use-module (gnu services shepherd)
6e828634 28 #:use-module (gnu system pam)
598757e0 29 #:use-module (gnu system keyboard)
607fcc75 30 #:use-module (gnu services base)
6e99c01b 31 #:use-module (gnu services dbus)
bdb36958
LC
32 #:use-module ((gnu packages base) #:select (canonical-package))
33 #:use-module (gnu packages guile)
db4fdc04 34 #:use-module (gnu packages xorg)
7e614198 35 #:use-module (gnu packages fonts)
db4fdc04 36 #:use-module (gnu packages gl)
1f564c15 37 #:use-module (gnu packages glib)
5fd66a37 38 #:use-module (gnu packages display-managers)
607fcc75 39 #:use-module (gnu packages freedesktop)
9e4eddb4 40 #:use-module (gnu packages gnustep)
6e99c01b 41 #:use-module (gnu packages gnome)
db4fdc04
LC
42 #:use-module (gnu packages admin)
43 #:use-module (gnu packages bash)
6e99c01b 44 #:use-module (gnu system shadow)
b5f4e686 45 #:use-module (guix gexp)
e87f0591 46 #:use-module (guix store)
6726282b 47 #:use-module (guix packages)
db4fdc04 48 #:use-module (guix derivations)
ffc3a02b 49 #:use-module (guix records)
65a67bf7 50 #:use-module (guix deprecation)
d2e59637 51 #:use-module (srfi srfi-1)
6726282b 52 #:use-module (srfi srfi-9)
d2e59637
LC
53 #:use-module (srfi srfi-26)
54 #:use-module (ice-9 match)
b2e56451
LC
55 #:export (xorg-configuration
56 xorg-configuration?
57 xorg-configuration-modules
58 xorg-configuration-fonts
59 xorg-configuration-drivers
60 xorg-configuration-resolutions
61 xorg-configuration-extra-config
62 xorg-configuration-server
63 xorg-configuration-server-arguments
64
79fd74fa 65 %default-xorg-modules
d344f5a5 66 %default-xorg-fonts
92753a8b 67 xorg-wrapper
d1cdd7ba 68 xorg-start-command
f2901d82
DC
69 xinitrc
70
0ecc3bf3
LC
71 %default-slim-theme
72 %default-slim-theme-name
b37f86d7 73
4b7513e0 74 slim-configuration
b37f86d7
LC
75 slim-configuration?
76 slim-configuration-slim
77 slim-configuration-allow-empty-passwords?
78 slim-configuration-auto-login?
79 slim-configuration-default-user
80 slim-configuration-theme
81 slim-configuration-theme-name
82 slim-configuration-xauth
83 slim-configuration-shepherd
84 slim-configuration-auto-login-session
bab7a495 85 slim-configuration-xorg
61569171
DNB
86 slim-configuration-display
87 slim-configuration-vt
bab7a495 88 slim-configuration-sessreg
b37f86d7 89
4b7513e0 90 slim-service-type
6726282b
LC
91 slim-service
92
24e96431
93 screen-locker
94 screen-locker?
6726282b 95 screen-locker-service-type
6e99c01b
AW
96 screen-locker-service
97
607fcc75
LC
98 localed-configuration
99 localed-configuration?
100 localed-service-type
101
6e99c01b
AW
102 gdm-configuration
103 gdm-service-type
305a732a
LC
104 gdm-service
105 set-xorg-configuration))
db4fdc04
LC
106
107;;; Commentary:
108;;;
109;;; Services that relate to the X Window System.
110;;;
111;;; Code:
112
d344f5a5 113(define %default-xorg-modules
fd96f94f
PN
114 ;; Default list of modules loaded by the server. When multiple drivers
115 ;; match, the first one in the list is loaded.
d344f5a5
LC
116 (list xf86-video-vesa
117 xf86-video-fbdev
fd96f94f 118 xf86-video-amdgpu
d344f5a5
LC
119 xf86-video-ati
120 xf86-video-cirrus
121 xf86-video-intel
122 xf86-video-mach64
123 xf86-video-nouveau
124 xf86-video-nv
125 xf86-video-sis
126
127 ;; Libinput is the new thing and is recommended over evdev/synaptics:
128 ;; <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
129 xf86-input-libinput
130
131 xf86-input-evdev
132 xf86-input-keyboard
133 xf86-input-mouse
134 xf86-input-synaptics))
135
136(define %default-xorg-fonts
137 ;; Default list of fonts available to the X server.
138 (list (file-append font-alias "/share/fonts/X11/75dpi")
139 (file-append font-alias "/share/fonts/X11/100dpi")
140 (file-append font-alias "/share/fonts/X11/misc")
141 (file-append font-alias "/share/fonts/X11/cyrillic")
4afc903a
LC
142 (file-append font-misc-misc ;default fonts for xterm
143 "/share/fonts/X11/misc")
d344f5a5
LC
144 (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
145
b2e56451
LC
146(define %default-xorg-server-arguments
147 ;; Default command-line arguments for X.
148 '("-nolisten" "tcp"))
149
150;; Configuration of an Xorg server.
151(define-record-type* <xorg-configuration>
152 xorg-configuration make-xorg-configuration
153 xorg-configuration?
154 (modules xorg-configuration-modules ;list of packages
155 (default %default-xorg-modules))
156 (fonts xorg-configuration-fonts ;list of packges
157 (default %default-xorg-fonts))
158 (drivers xorg-configuration-drivers ;list of strings
159 (default '()))
160 (resolutions xorg-configuration-resolutions ;list of tuples
161 (default '()))
598757e0
LC
162 (keyboard-layout xorg-configuration-keyboard-layout ;#f | <keyboard-layout>
163 (default #f))
b2e56451
LC
164 (extra-config xorg-configuration-extra-config ;list of strings
165 (default '()))
166 (server xorg-configuration-server ;package
167 (default xorg-server))
168 (server-arguments xorg-configuration-server-arguments ;list of strings
169 (default %default-xorg-server-arguments)))
170
171(define (xorg-configuration->file config)
172 "Compute an Xorg configuration file corresponding to CONFIG, an
173<xorg-configuration> record."
d344f5a5
LC
174 (define all-modules
175 ;; 'xorg-server' provides 'fbdevhw.so' etc.
b2e56451
LC
176 (append (xorg-configuration-modules config)
177 (list xorg-server)))
d344f5a5
LC
178
179 (define build
180 #~(begin
181 (use-modules (ice-9 match)
182 (srfi srfi-1)
183 (srfi srfi-26))
184
185 (call-with-output-file #$output
186 (lambda (port)
187 (define drivers
b2e56451 188 '#$(xorg-configuration-drivers config))
d344f5a5
LC
189
190 (define (device-section driver)
191 (string-append "
f703413e
LC
192Section \"Device\"
193 Identifier \"device-" driver "\"
194 Driver \"" driver "\"
195EndSection"))
db4fdc04 196
d344f5a5
LC
197 (define (screen-section driver resolutions)
198 (string-append "
d2e59637
LC
199Section \"Screen\"
200 Identifier \"screen-" driver "\"
201 Device \"device-" driver "\"
202 SubSection \"Display\"
203 Modes "
204 (string-join (map (match-lambda
d1cdd7ba
LC
205 ((x y)
206 (string-append "\"" (number->string x)
207 "x" (number->string y) "\"")))
d2e59637
LC
208 resolutions)) "
209 EndSubSection
210EndSection"))
211
598757e0
LC
212 (define (input-class-section layout variant model options)
213 (string-append "
214Section \"InputClass\"
215 Identifier \"evdev keyboard catchall\"
216 MatchIsKeyboard \"on\"
217 Option \"XkbLayout\" " (object->string layout)
218 (if variant
219 (string-append " Option \"XkbVariant\" \""
220 variant "\"")
221 "")
222 (if model
223 (string-append " Option \"XkbModel\" \""
224 model "\"")
225 "")
226 (match options
227 (()
228 "")
229 (_
230 (string-append " Option \"XkbOptions\" \""
231 (string-join options ",") "\""))) "
232
233 MatchDevicePath \"/dev/input/event*\"
234 Driver \"evdev\"
235EndSection\n"))
236
d344f5a5
LC
237 (define (expand modules)
238 ;; Append to MODULES the relevant /lib/xorg/modules
239 ;; sub-directories.
240 (append-map (lambda (module)
241 (filter-map (lambda (directory)
242 (let ((full (string-append module
243 directory)))
244 (and (file-exists? full)
245 full)))
246 '("/lib/xorg/modules/drivers"
247 "/lib/xorg/modules/input"
248 "/lib/xorg/modules/multimedia"
249 "/lib/xorg/modules/extensions")))
250 modules))
db4fdc04 251
d344f5a5
LC
252 (display "Section \"Files\"\n" port)
253 (for-each (lambda (font)
254 (format port " FontPath \"~a\"~%" font))
b2e56451 255 '#$(xorg-configuration-fonts config))
d344f5a5
LC
256 (for-each (lambda (module)
257 (format port
258 " ModulePath \"~a\"~%"
259 module))
260 (append (expand '#$all-modules)
261
262 ;; For fbdevhw.so and so on.
263 (list #$(file-append xorg-server
264 "/lib/xorg/modules"))))
265 (display "EndSection\n" port)
266 (display "
db4fdc04 267Section \"ServerFlags\"
e30442b5 268 Option \"AllowMouseOpenFail\" \"on\"
d344f5a5 269EndSection\n" port)
12422c9d 270
d344f5a5
LC
271 (display (string-join (map device-section drivers) "\n")
272 port)
273 (newline port)
274 (display (string-join
b2e56451
LC
275 (map (cut screen-section <>
276 '#$(xorg-configuration-resolutions config))
d344f5a5
LC
277 drivers)
278 "\n")
279 port)
280 (newline port)
281
598757e0
LC
282 (let ((layout #$(and=> (xorg-configuration-keyboard-layout config)
283 keyboard-layout-name))
284 (variant #$(and=> (xorg-configuration-keyboard-layout config)
285 keyboard-layout-variant))
286 (model #$(and=> (xorg-configuration-keyboard-layout config)
287 keyboard-layout-model))
70bb83b7
LC
288 (options '#$(and=> (xorg-configuration-keyboard-layout config)
289 keyboard-layout-options)))
598757e0
LC
290 (when layout
291 (display (input-class-section layout variant model options)
292 port)
293 (newline port)))
294
d344f5a5
LC
295 (for-each (lambda (config)
296 (display config port))
b2e56451 297 '#$(xorg-configuration-extra-config config))))))
d344f5a5
LC
298
299 (computed-file "xserver.conf" build))
db4fdc04 300
79fd74fa
AW
301(define (xorg-configuration-directory modules)
302 "Return a directory that contains the @code{.conf} files for X.org that
303includes the @code{share/X11/xorg.conf.d} directories of each package listed
304in @var{modules}."
4ee96a79
LC
305 (with-imported-modules '((guix build utils))
306 (computed-file "xorg.conf.d"
307 #~(begin
308 (use-modules (guix build utils)
309 (srfi srfi-1))
310
311 (define files
312 (append-map (lambda (module)
313 (find-files (string-append
314 module
315 "/share/X11/xorg.conf.d")
316 "\\.conf$"))
317 (list #$@modules)))
318
319 (mkdir #$output)
320 (for-each (lambda (file)
321 (symlink file
322 (string-append #$output "/"
323 (basename file))))
324 files)
325 #t))))
79fd74fa 326
b2e56451
LC
327(define* (xorg-wrapper #:optional (config (xorg-configuration)))
328 "Return a derivation that builds a script to start the X server with the
329given @var{config}. The resulting script should be used in place of
330@code{/usr/bin/X}."
be1c2c54
LC
331 (define exp
332 ;; Write a small wrapper around the X server.
333 #~(begin
334 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
335 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
336
b2e56451 337 (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
92753a8b
AW
338 (apply execl X X
339 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
b2e56451
LC
340 "-config" #$(xorg-configuration->file config)
341 "-configdir" #$(xorg-configuration-directory
342 (xorg-configuration-modules config))
92753a8b
AW
343 (cdr (command-line))))))
344
345 (program-file "X-wrapper" exp))
be1c2c54 346
b2e56451
LC
347(define* (xorg-start-command #:optional (config (xorg-configuration)))
348 "Return a @code{startx} script in which the modules, fonts, etc. specified
349in @var{config}, are available. The result should be used in place of
350@code{startx}."
92753a8b 351 (define X
b2e56451
LC
352 (xorg-wrapper config))
353
92753a8b
AW
354 (define exp
355 ;; Write a small wrapper around the X server.
356 #~(apply execl #$X #$X ;; Second #$X is for argv[0].
b2e56451
LC
357 "-logverbose" "-verbose" "-terminate"
358 #$@(xorg-configuration-server-arguments config)
24f11b06 359 (cdr (command-line))))
be1c2c54 360
92753a8b 361 (program-file "startx" exp))
db4fdc04 362
956607e3 363(define* (xinitrc #:key fallback-session)
24d56899
SB
364 "Return a system-wide xinitrc script that starts the specified X session,
365which should be passed to this script as the first argument. If not, the
65c0f436
LC
366@var{fallback-session} will be used or, if @var{fallback-session} is false, a
367desktop session from the system or user profile will be used."
8779d342
LC
368 (define builder
369 #~(begin
65c0f436
LC
370 (use-modules (ice-9 match)
371 (ice-9 regex)
372 (ice-9 ftw)
4e1efba4 373 (ice-9 rdelim)
65c0f436
LC
374 (srfi srfi-1)
375 (srfi srfi-26))
8779d342 376
16c33bfb
LC
377 (define (close-all-fdes)
378 ;; Close all the open file descriptors except 0 to 2.
379 (let loop ((fd 3))
380 (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
381 (false-if-exception (close-fdes fd))
382 (loop (+ 1 fd)))))
383
b2bd7c25
LC
384 (define (exec-from-login-shell command . args)
385 ;; Run COMMAND from a login shell so that it gets to see the same
386 ;; environment variables that one gets when logging in on a tty, for
387 ;; instance.
388 (let* ((pw (getpw (getuid)))
e0b85670
SB
389 (shell (passwd:shell pw)))
390 ;; Close any open file descriptors. This is all the more
391 ;; important that SLiM itself exec's us directly without closing
392 ;; its own file descriptors!
393 (close-all-fdes)
394
395 ;; The '--login' option is supported at least by Bash and zsh.
396 (execl shell shell "--login" "-c"
397 (string-join (cons command args)))))
398
65c0f436
LC
399 (define system-profile
400 "/run/current-system/profile")
401
402 (define user-profile
403 (and=> (getpw (getuid))
404 (lambda (pw)
405 (string-append (passwd:dir pw) "/.guix-profile"))))
406
407 (define (xsession-command desktop-file)
408 ;; Read from DESKTOP-FILE its X session command and return it as a
409 ;; list.
410 (define exec-regexp
411 (make-regexp "^[[:blank:]]*Exec=(.*)$"))
412
413 (call-with-input-file desktop-file
414 (lambda (port)
415 (let loop ()
416 (match (read-line port)
417 ((? eof-object?) #f)
418 ((= (cut regexp-exec exec-regexp <>) result)
419 (if result
420 (string-tokenize (match:substring result 1))
421 (loop))))))))
422
423 (define (find-session profile)
424 ;; Return an X session command from PROFILE or #f if none was found.
425 (let ((directory (string-append profile "/share/xsessions")))
426 (match (scandir directory
427 (cut string-suffix? ".desktop" <>))
428 ((or () #f)
429 #f)
430 ((sessions ...)
431 (any xsession-command
432 (map (cut string-append directory "/" <>)
433 sessions))))))
434
e0b85670
SB
435 (let* ((home (getenv "HOME"))
436 (xsession-file (string-append home "/.xsession"))
437 (session (match (command-line)
65c0f436
LC
438 ((_)
439 #$(if fallback-session
440 #~(list #$fallback-session)
441 #f))
442 ((_ x ..1)
443 x))))
e0b85670
SB
444 (if (file-exists? xsession-file)
445 ;; Run ~/.xsession when it exists.
617e87bf
LC
446 (apply exec-from-login-shell xsession-file
447 (or session '()))
65c0f436
LC
448 ;; Otherwise, start the specified session or a fallback.
449 (apply exec-from-login-shell
450 (or session
451 (find-session user-profile)
452 (find-session system-profile)))))))
c510cbb4 453
be1c2c54 454 (program-file "xinitrc" builder))
9e4eddb4 455
0ecc3bf3
LC
456\f
457;;;
458;;; SLiM log-in manager.
459;;;
460
0ecc3bf3
LC
461(define %default-slim-theme
462 ;; Theme based on work by Felipe López.
9e41130b 463 (file-append %artwork-repository "/slim"))
0ecc3bf3
LC
464
465(define %default-slim-theme-name
466 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
467 ;; contains the actual theme files.
2f9f792a 468 "1.x")
0ecc3bf3 469
0adfe95a
LC
470(define-record-type* <slim-configuration>
471 slim-configuration make-slim-configuration
472 slim-configuration?
473 (slim slim-configuration-slim
474 (default slim))
b37f86d7
LC
475 (allow-empty-passwords? slim-configuration-allow-empty-passwords?
476 (default #t))
477 (auto-login? slim-configuration-auto-login?
478 (default #f))
479 (default-user slim-configuration-default-user
480 (default ""))
481 (theme slim-configuration-theme
482 (default %default-slim-theme))
483 (theme-name slim-configuration-theme-name
484 (default %default-slim-theme-name))
0adfe95a
LC
485 (xauth slim-configuration-xauth
486 (default xauth))
26b94866
AK
487 (shepherd slim-configuration-shepherd
488 (default shepherd))
b37f86d7 489 (auto-login-session slim-configuration-auto-login-session
65c0f436 490 (default #f))
554b8607
LC
491 (xorg-configuration slim-configuration-xorg
492 (default (xorg-configuration)))
61569171
DNB
493 (display slim-configuration-display
494 (default ":0"))
495 (vt slim-configuration-vt
496 (default "vt7"))
736e45a2
DM
497 (sessreg slim-configuration-sessreg
498 (default sessreg)))
0adfe95a
LC
499
500(define (slim-pam-service config)
501 "Return a PAM service for @command{slim}."
502 (list (unix-pam-service
503 "slim"
e6b1a224 504 #:login-uid? #t
0adfe95a
LC
505 #:allow-empty-passwords?
506 (slim-configuration-allow-empty-passwords? config))))
507
d4053c71 508(define (slim-shepherd-service config)
61569171
DNB
509 (let* ((xinitrc (xinitrc #:fallback-session
510 (slim-configuration-auto-login-session config)))
511 (xauth (slim-configuration-xauth config))
512 (startx (xorg-start-command (slim-configuration-xorg config)))
513 (display (slim-configuration-display config))
514 (vt (slim-configuration-vt config))
515 (shepherd (slim-configuration-shepherd config))
516 (theme-name (slim-configuration-theme-name config))
517 (sessreg (slim-configuration-sessreg config))
518 (lockfile (string-append "/var/run/slim-" vt ".lock")))
519 (define slim.cfg
0adfe95a
LC
520 (mixed-text-file "slim.cfg" "
521default_path /run/current-system/profile/bin
522default_xserver " startx "
61569171
DNB
523display_name " display "
524xserver_arguments " vt "
0adfe95a 525xauth_path " xauth "/bin/xauth
61569171
DNB
526authfile /var/run/slim-" vt ".auth
527lockfile " lockfile "
528logfile /var/log/slim-" vt ".log
0adfe95a
LC
529
530# The login command. '%session' is replaced by the chosen session name, one
531# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
532login_cmd exec " xinitrc " %session
533sessiondir /run/current-system/profile/share/xsessions
534session_msg session (F1 to change):
736e45a2
DM
535sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
536sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
0adfe95a 537
26b94866
AK
538halt_cmd " shepherd "/sbin/halt
539reboot_cmd " shepherd "/sbin/reboot\n"
0adfe95a
LC
540(if (slim-configuration-auto-login? config)
541 (string-append "auto_login yes\ndefault_user "
542 (slim-configuration-default-user config) "\n")
543 "")
544(if theme-name
545 (string-append "current_theme " theme-name "\n")
61569171
DNB
546 "")))
547
548 (define theme
549 (slim-configuration-theme config))
550
551 (list (shepherd-service
552 (documentation "Xorg display server")
6ad799d7
LC
553 (provision (append
554 ;; For compatibility, also provide 'xorg-server'.
555 (if (string=? vt "vt7")
556 '(xorg-server)
557 '())
558
559 (list (symbol-append 'xorg-server-
560 (string->symbol vt)))))
61569171
DNB
561 (requirement '(user-processes host-name udev))
562 (start
563 #~(lambda ()
564 ;; A stale lock file can prevent SLiM from starting, so remove it to
565 ;; be on the safe side.
566 (false-if-exception (delete-file lockfile))
567
568 (fork+exec-command
569 (list (string-append #$(slim-configuration-slim config)
570 "/bin/slim")
571 "-nodaemon")
572 #:environment-variables
573 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
574 #$@(if theme
575 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
576 #~())))))
577 (stop #~(make-kill-destructor))
578 (respawn? #t)))))
0adfe95a
LC
579
580(define slim-service-type
581 (service-type (name 'slim)
582 (extensions
d4053c71
AK
583 (list (service-extension shepherd-root-service-type
584 slim-shepherd-service)
0adfe95a 585 (service-extension pam-root-service-type
e9b82124
LC
586 slim-pam-service)
587
588 ;; Unconditionally add xterm to the system profile, to
589 ;; avoid bad surprises.
590 (service-extension profile-service-type
b37f86d7
LC
591 (const (list xterm)))))
592 (default-value (slim-configuration))))
0adfe95a 593
65a67bf7
LC
594(define-deprecated (slim-service #:key (slim slim)
595 (allow-empty-passwords? #t) auto-login?
596 (default-user "")
597 (theme %default-slim-theme)
598 (theme-name %default-slim-theme-name)
599 (xauth xauth) (shepherd shepherd)
600 (auto-login-session #f)
601 (startx (xorg-start-command)))
602 slim-service-type
db4fdc04 603 "Return a service that spawns the SLiM graphical login manager, which in
51da7ca0
LC
604turn starts the X display server with @var{startx}, a command as returned by
605@code{xorg-start-command}.
db4fdc04 606
04e4e6ab
LC
607@cindex X session
608
609SLiM automatically looks for session types described by the @file{.desktop}
610files in @file{/run/current-system/profile/share/xsessions} and allows users
611to choose a session from the log-in screen using @kbd{F1}. Packages such as
612@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
613adding them to the system-wide set of packages automatically makes them
614available at the log-in screen.
615
616In addition, @file{~/.xsession} files are honored. When available,
617@file{~/.xsession} must be an executable that starts a window manager
618and/or other X clients.
619
51da7ca0
LC
620When @var{allow-empty-passwords?} is true, allow logins with an empty
621password. When @var{auto-login?} is true, log in automatically as
24d56899 622@var{default-user} with @var{auto-login-session}.
0ecc3bf3
LC
623
624If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
625@var{theme} must be a gexp denoting the name of a directory containing the
626theme to use. In that case, @var{theme-name} specifies the name of the
4bd43bbe 627theme."
0adfe95a
LC
628 (service slim-service-type
629 (slim-configuration
630 (slim slim)
631 (allow-empty-passwords? allow-empty-passwords?)
632 (auto-login? auto-login?) (default-user default-user)
633 (theme theme) (theme-name theme-name)
94b9abd9 634 (xauth xauth) (shepherd shepherd)
554b8607 635 (auto-login-session auto-login-session))))
db4fdc04 636
6726282b
LC
637\f
638;;;
639;;; Screen lockers & co.
640;;;
641
642(define-record-type <screen-locker>
643 (screen-locker name program empty?)
644 screen-locker?
645 (name screen-locker-name) ;string
646 (program screen-locker-program) ;gexp
647 (empty? screen-locker-allows-empty-passwords?)) ;Boolean
648
649(define screen-locker-pam-services
650 (match-lambda
651 (($ <screen-locker> name _ empty?)
652 (list (unix-pam-service name
653 #:allow-empty-passwords? empty?)))))
654
655(define screen-locker-setuid-programs
656 (compose list screen-locker-program))
657
658(define screen-locker-service-type
659 (service-type (name 'screen-locker)
660 (extensions
661 (list (service-extension pam-root-service-type
662 screen-locker-pam-services)
663 (service-extension setuid-program-service-type
664 screen-locker-setuid-programs)))))
665
666(define* (screen-locker-service package
667 #:optional
668 (program (package-name package))
669 #:key allow-empty-passwords?)
d64e1746 670 "Add @var{package}, a package for a screen locker or screen saver whose
6726282b
LC
671command is @var{program}, to the set of setuid programs and add a PAM entry
672for it. For example:
673
674@lisp
9e41130b 675 (screen-locker-service xlockmore \"xlock\")
6726282b
LC
676@end lisp
677
678makes the good ol' XlockMore usable."
679 (service screen-locker-service-type
680 (screen-locker program
9e41130b 681 (file-append package "/bin/" program)
6726282b
LC
682 allow-empty-passwords?)))
683
607fcc75
LC
684\f
685;;;
686;;; Locale service.
687;;;
688
689(define-record-type* <localed-configuration>
690 localed-configuration make-localed-configuration
691 localed-configuration?
692 (localed localed-configuration-localed
693 (default localed))
694 (keyboard-layout localed-configuration-keyboard-layout
695 (default #f)))
696
697(define (localed-dbus-service config)
698 "Return the 'localed' D-Bus service for @var{config}, a
699@code{<localed-configuration>} record."
700 (define keyboard-layout
701 (localed-configuration-keyboard-layout config))
702
703 ;; The primary purpose of 'localed' is to tell GDM what the "current" Xorg
704 ;; keyboard layout is. If 'localed' is missing, or if it's unable to
705 ;; determine the current XKB layout, then GDM forcefully installs its
706 ;; default XKB config (US English). Here we communicate the configured
707 ;; layout through environment variables.
708
709 (if keyboard-layout
710 (let* ((layout (keyboard-layout-name keyboard-layout))
711 (variant (keyboard-layout-variant keyboard-layout))
712 (model (keyboard-layout-model keyboard-layout))
713 (options (keyboard-layout-options keyboard-layout)))
714 (list (wrapped-dbus-service
715 (localed-configuration-localed config)
716 "libexec/localed/localed"
717 `(("GUIX_XKB_LAYOUT" ,layout)
718 ,@(if variant
719 `(("GUIX_XKB_VARIANT" ,variant))
720 '())
721 ,@(if model
722 `(("GUIX_XKB_MODEL" ,model))
723 '())
724 ,@(if (null? options)
725 '()
726 `(("GUIX_XKB_OPTIONS"
727 ,(string-join options ","))))))))
3ef3bdf1 728 '()))
607fcc75
LC
729
730(define localed-service-type
13615849
LC
731 (let ((package (lambda (config)
732 ;; Don't bother if the user didn't specify any keyboard
733 ;; layout.
734 (if (localed-configuration-keyboard-layout config)
735 (list (localed-configuration-localed config))
736 '()))))
607fcc75
LC
737 (service-type (name 'localed)
738 (extensions
739 (list (service-extension dbus-root-service-type
740 localed-dbus-service)
741 (service-extension udev-service-type package)
742 (service-extension polkit-service-type package)
743
744 ;; Add 'localectl' to the profile.
745 (service-extension profile-service-type package)))
746
747 ;; This service can be extended, typically by the X login
748 ;; manager, to communicate the chosen Xorg keyboard layout.
13615849
LC
749 (compose (lambda (extensions)
750 (find keyboard-layout? extensions)))
607fcc75
LC
751 (extend (lambda (config keyboard-layout)
752 (localed-configuration
753 (inherit config)
754 (keyboard-layout keyboard-layout))))
755 (description
756 "Run the locale daemon, @command{localed}, which can be used
757to control the system locale and keyboard mapping from user programs such as
758the GNOME desktop environment.")
759 (default-value (localed-configuration)))))
760
761\f
762;;;
763;;; GNOME Desktop Manager.
764;;;
765
6e99c01b
AW
766(define %gdm-accounts
767 (list (user-group (name "gdm") (system? #t))
768 (user-account
769 (name "gdm")
770 (group "gdm")
771 (system? #t)
772 (comment "GNOME Display Manager user")
773 (home-directory "/var/lib/gdm")
774 (shell (file-append shadow "/sbin/nologin")))))
775
a43e9157
LC
776(define %gdm-activation
777 ;; Ensure /var/lib/gdm is owned by the "gdm" user. This is normally the
778 ;; case but could be wrong if the "gdm" user was created, then removed, and
779 ;; then recreated under a different UID/GID: <https://bugs.gnu.org/37423>.
780 (with-imported-modules '((guix build utils))
781 #~(begin
782 (use-modules (guix build utils))
783
784 (let* ((gdm (getpwnam "gdm"))
785 (uid (passwd:uid gdm))
786 (gid (passwd:gid gdm))
787 (st (stat "/var/lib/gdm" #f)))
788 ;; Recurse into /var/lib/gdm only if it has wrong ownership.
789 (when (and st
790 (or (not (= uid (stat:uid st)))
791 (not (= gid (stat:gid st)))))
792 (for-each (lambda (file)
793 (chown file uid gid))
794 (find-files "/var/lib/gdm"
795 #:directories? #t)))))))
796
1f564c15 797(define dbus-daemon-wrapper
dcb3a0fe
TS
798 (program-file
799 "gdm-dbus-wrapper"
800 #~(begin
801 (use-modules (srfi srfi-26))
802
803 (define system-profile
804 "/run/current-system/profile")
805
806 (define user-profile
807 (and=> (getpw (getuid))
808 (lambda (pw)
809 (string-append (passwd:dir pw) "/.guix-profile"))))
810
811 ;; If we are able to find the user's profile, we can add it to
812 ;; the search paths set below. We need to do this so that D-Bus
813 ;; can start services installed by the user. This allows
814 ;; applications that require session D-Bus services (e.g,
815 ;; 'evolution') to work even if those services are only available
816 ;; in the user's profile. See <https://bugs.gnu.org/35267>.
817 (define profiles
818 (if user-profile
819 (list user-profile system-profile)
820 (list system-profile)))
821
822 (setenv "XDG_CONFIG_DIRS"
823 (string-join (map (cut string-append <> "/etc/xdg") profiles)
824 ":"))
825 (setenv "XDG_DATA_DIRS"
826 (string-join (map (cut string-append <> "/share") profiles)
827 ":"))
828 (apply execl (string-append #$dbus "/bin/dbus-daemon")
829 (program-arguments)))))
1f564c15 830
6e99c01b
AW
831(define-record-type* <gdm-configuration>
832 gdm-configuration make-gdm-configuration
833 gdm-configuration?
834 (gdm gdm-configuration-gdm (default gdm))
835 (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
6e99c01b 836 (auto-login? gdm-configuration-auto-login? (default #f))
1f564c15 837 (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
88f95687 838 (debug? gdm-configuration-debug? (default #f))
6e99c01b 839 (default-user gdm-configuration-default-user (default #f))
7e614198
TS
840 (gnome-shell-assets gdm-configuration-gnome-shell-assets
841 (default (list adwaita-icon-theme font-cantarell)))
554b8607
LC
842 (xorg-configuration gdm-configuration-xorg
843 (default (xorg-configuration)))
41fa9f18
TS
844 (x-session gdm-configuration-x-session
845 (default (xinitrc))))
6e99c01b 846
e57c2adb
TS
847(define (gdm-configuration-file config)
848 (mixed-text-file "gdm-custom.conf"
849 "[daemon]\n"
850 "#User=gdm\n"
851 "#Group=gdm\n"
852 (if (gdm-configuration-auto-login? config)
853 (string-append
854 "AutomaticLoginEnable=true\n"
855 "AutomaticLogin="
856 (or (gdm-configuration-default-user config)
857 (error "missing default user for auto-login"))
858 "\n")
859 (string-append
860 "AutomaticLoginEnable=false\n"
861 "#AutomaticLogin=\n"))
862 "#TimedLoginEnable=false\n"
863 "#TimedLogin=\n"
864 "#TimedLoginDelay=0\n"
865 "#InitialSetupEnable=true\n"
866 ;; Enable me once X is working.
867 "WaylandEnable=false\n"
868 "\n"
869 "[debug]\n"
88f95687
TS
870 "Enable=" (if (gdm-configuration-debug? config)
871 "true"
872 "false") "\n"
e57c2adb
TS
873 "\n"
874 "[security]\n"
875 "#DisallowTCP=true\n"
876 "#AllowRemoteAutoLogin=false\n"))
6e99c01b
AW
877
878(define (gdm-pam-service config)
879 "Return a PAM service for @command{gdm}."
880 (list
881 (pam-service
e6b1a224
LC
882 (inherit (unix-pam-service "gdm-autologin"
883 #:login-uid? #t))
6e99c01b
AW
884 (auth (list (pam-entry
885 (control "[success=ok default=1]")
886 (module (file-append (gdm-configuration-gdm config)
887 "/lib/security/pam_gdm.so")))
888 (pam-entry
889 (control "sufficient")
890 (module "pam_permit.so")))))
891 (pam-service
892 (inherit (unix-pam-service "gdm-launch-environment"))
893 (auth (list (pam-entry
894 (control "required")
895 (module "pam_permit.so")))))
de409e82 896 (unix-pam-service "gdm-password"
e6b1a224 897 #:login-uid? #t
de409e82
TS
898 #:allow-empty-passwords?
899 (gdm-configuration-allow-empty-passwords? config))))
6e99c01b
AW
900
901(define (gdm-shepherd-service config)
902 (list (shepherd-service
903 (documentation "Xorg display server (GDM)")
904 (provision '(xorg-server))
905 (requirement '(dbus-system user-processes host-name udev))
6e99c01b
AW
906 (start #~(lambda ()
907 (fork+exec-command
908 (list #$(file-append (gdm-configuration-gdm config)
909 "/bin/gdm"))
910 #:environment-variables
911 (list (string-append
e57c2adb
TS
912 "GDM_CUSTOM_CONF="
913 #$(gdm-configuration-file config))
1f564c15
TS
914 (string-append
915 "GDM_DBUS_DAEMON="
916 #$(gdm-configuration-dbus-daemon config))
e57c2adb 917 (string-append
6e99c01b 918 "GDM_X_SERVER="
554b8607
LC
919 #$(xorg-wrapper
920 (gdm-configuration-xorg config)))
41fa9f18
TS
921 (string-append
922 "GDM_X_SESSION="
923 #$(gdm-configuration-x-session config))
7e614198
TS
924 (string-append
925 "XDG_DATA_DIRS="
926 ((lambda (ls) (string-join ls ":"))
927 (map (lambda (path)
928 (string-append path "/share"))
929 ;; XXX: Remove gnome-shell below when GDM
930 ;; can depend on GNOME Shell directly.
931 (cons #$gnome-shell
932 '#$(gdm-configuration-gnome-shell-assets
933 config)))))))))
6e99c01b
AW
934 (stop #~(make-kill-destructor))
935 (respawn? #t))))
936
937(define gdm-service-type
938 (service-type (name 'gdm)
939 (extensions
940 (list (service-extension shepherd-root-service-type
941 gdm-shepherd-service)
a43e9157
LC
942 (service-extension activation-service-type
943 (const %gdm-activation))
6e99c01b
AW
944 (service-extension account-service-type
945 (const %gdm-accounts))
946 (service-extension pam-root-service-type
947 gdm-pam-service)
7e614198
TS
948 (service-extension profile-service-type
949 gdm-configuration-gnome-shell-assets)
6e99c01b 950 (service-extension dbus-root-service-type
01b3625d 951 (compose list
607fcc75
LC
952 gdm-configuration-gdm))
953 (service-extension localed-service-type
954 (compose
955 xorg-configuration-keyboard-layout
956 gdm-configuration-xorg))))
957
305a732a
LC
958 ;; For convenience, this service can be extended with an
959 ;; <xorg-configuration> record. Take the first one that
960 ;; comes.
0cf981a6
LC
961 (compose (lambda (extensions)
962 (match extensions
963 (() #f)
964 ((config . _) config))))
305a732a 965 (extend (lambda (config xorg-configuration)
0cf981a6
LC
966 (if xorg-configuration
967 (gdm-configuration
968 (inherit config)
969 (xorg-configuration xorg-configuration))
970 config)))
305a732a 971
01b3625d
LC
972 (default-value (gdm-configuration))
973 (description
974 "Run the GNOME Desktop Manager (GDM), a program that allows
975you to log in in a graphical session, whether or not you use GNOME.")))
6e99c01b 976
65a67bf7
LC
977(define-deprecated (gdm-service #:key (gdm gdm)
978 (allow-empty-passwords? #t)
979 (x-server (xorg-wrapper)))
980 gdm-service-type
6e99c01b
AW
981 "Return a service that spawns the GDM graphical login manager, which in turn
982starts the X display server with @var{X}, a command as returned by
983@code{xorg-wrapper}.
984
985@cindex X session
986
987GDM automatically looks for session types described by the @file{.desktop}
988files in @file{/run/current-system/profile/share/xsessions} and allows users
989to choose a session from the log-in screen using @kbd{F1}. Packages such as
990@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
991adding them to the system-wide set of packages automatically makes them
992available at the log-in screen.
993
994In addition, @file{~/.xsession} files are honored. When available,
995@file{~/.xsession} must be an executable that starts a window manager
996and/or other X clients.
997
998When @var{allow-empty-passwords?} is true, allow logins with an empty
999password."
1000 (service gdm-service-type
1001 (gdm-configuration
1002 (gdm gdm)
554b8607 1003 (allow-empty-passwords? allow-empty-passwords?))))
6e99c01b 1004
305a732a
LC
1005(define* (set-xorg-configuration config
1006 #:optional
1007 (login-manager-service-type
1008 gdm-service-type))
1009 "Tell the log-in manager (of type @var{login-manager-service-type}) to use
1010@var{config}, an <xorg-configuration> record."
1011 (simple-service 'set-xorg-configuration
1012 login-manager-service-type
1013 config))
1014
db4fdc04 1015;;; xorg.scm ends here