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