services: slim: Provide the 'xorg-server' Shepherd service.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Andy Wingo <wingo@igalia.com>
3 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
5 ;;; Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
6 ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
7 ;;; Copyright © 2019 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
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)
25 #:use-module (gnu artwork)
26 #:use-module (gnu services)
27 #:use-module (gnu services shepherd)
28 #:use-module (gnu system pam)
29 #:use-module (gnu system keyboard)
30 #:use-module (gnu services base)
31 #:use-module (gnu services dbus)
32 #:use-module ((gnu packages base) #:select (canonical-package))
33 #:use-module (gnu packages guile)
34 #:use-module (gnu packages xorg)
35 #:use-module (gnu packages fonts)
36 #:use-module (gnu packages gl)
37 #:use-module (gnu packages glib)
38 #:use-module (gnu packages display-managers)
39 #:use-module (gnu packages freedesktop)
40 #:use-module (gnu packages gnustep)
41 #:use-module (gnu packages gnome)
42 #:use-module (gnu packages admin)
43 #:use-module (gnu packages bash)
44 #:use-module (gnu system shadow)
45 #:use-module (guix gexp)
46 #:use-module (guix store)
47 #:use-module (guix packages)
48 #:use-module (guix derivations)
49 #:use-module (guix records)
50 #:use-module (guix deprecation)
51 #:use-module (srfi srfi-1)
52 #:use-module (srfi srfi-9)
53 #:use-module (srfi srfi-26)
54 #:use-module (ice-9 match)
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
65 %default-xorg-modules
66 %default-xorg-fonts
67 xorg-wrapper
68 xorg-start-command
69 xinitrc
70
71 %default-slim-theme
72 %default-slim-theme-name
73
74 slim-configuration
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
85 slim-configuration-xorg
86 slim-configuration-display
87 slim-configuration-vt
88 slim-configuration-sessreg
89
90 slim-service-type
91 slim-service
92
93 screen-locker
94 screen-locker?
95 screen-locker-service-type
96 screen-locker-service
97
98 localed-configuration
99 localed-configuration?
100 localed-service-type
101
102 gdm-configuration
103 gdm-service-type
104 gdm-service
105 set-xorg-configuration))
106
107 ;;; Commentary:
108 ;;;
109 ;;; Services that relate to the X Window System.
110 ;;;
111 ;;; Code:
112
113 (define %default-xorg-modules
114 ;; Default list of modules loaded by the server. When multiple drivers
115 ;; match, the first one in the list is loaded.
116 (list xf86-video-vesa
117 xf86-video-fbdev
118 xf86-video-amdgpu
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")
142 (file-append font-misc-misc ;default fonts for xterm
143 "/share/fonts/X11/misc")
144 (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
145
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 '()))
162 (keyboard-layout xorg-configuration-keyboard-layout ;#f | <keyboard-layout>
163 (default #f))
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."
174 (define all-modules
175 ;; 'xorg-server' provides 'fbdevhw.so' etc.
176 (append (xorg-configuration-modules config)
177 (list xorg-server)))
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
188 '#$(xorg-configuration-drivers config))
189
190 (define (device-section driver)
191 (string-append "
192 Section \"Device\"
193 Identifier \"device-" driver "\"
194 Driver \"" driver "\"
195 EndSection"))
196
197 (define (screen-section driver resolutions)
198 (string-append "
199 Section \"Screen\"
200 Identifier \"screen-" driver "\"
201 Device \"device-" driver "\"
202 SubSection \"Display\"
203 Modes "
204 (string-join (map (match-lambda
205 ((x y)
206 (string-append "\"" (number->string x)
207 "x" (number->string y) "\"")))
208 resolutions)) "
209 EndSubSection
210 EndSection"))
211
212 (define (input-class-section layout variant model options)
213 (string-append "
214 Section \"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\"
235 EndSection\n"))
236
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))
251
252 (display "Section \"Files\"\n" port)
253 (for-each (lambda (font)
254 (format port " FontPath \"~a\"~%" font))
255 '#$(xorg-configuration-fonts config))
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 "
267 Section \"ServerFlags\"
268 Option \"AllowMouseOpenFail\" \"on\"
269 EndSection\n" port)
270
271 (display (string-join (map device-section drivers) "\n")
272 port)
273 (newline port)
274 (display (string-join
275 (map (cut screen-section <>
276 '#$(xorg-configuration-resolutions config))
277 drivers)
278 "\n")
279 port)
280 (newline port)
281
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))
288 (options '#$(and=> (xorg-configuration-keyboard-layout config)
289 keyboard-layout-options)))
290 (when layout
291 (display (input-class-section layout variant model options)
292 port)
293 (newline port)))
294
295 (for-each (lambda (config)
296 (display config port))
297 '#$(xorg-configuration-extra-config config))))))
298
299 (computed-file "xserver.conf" build))
300
301 (define (xorg-configuration-directory modules)
302 "Return a directory that contains the @code{.conf} files for X.org that
303 includes the @code{share/X11/xorg.conf.d} directories of each package listed
304 in @var{modules}."
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))))
326
327 (define* (xorg-wrapper #:optional (config (xorg-configuration)))
328 "Return a derivation that builds a script to start the X server with the
329 given @var{config}. The resulting script should be used in place of
330 @code{/usr/bin/X}."
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
337 (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
338 (apply execl X X
339 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
340 "-config" #$(xorg-configuration->file config)
341 "-configdir" #$(xorg-configuration-directory
342 (xorg-configuration-modules config))
343 (cdr (command-line))))))
344
345 (program-file "X-wrapper" exp))
346
347 (define* (xorg-start-command #:optional (config (xorg-configuration)))
348 "Return a @code{startx} script in which the modules, fonts, etc. specified
349 in @var{config}, are available. The result should be used in place of
350 @code{startx}."
351 (define X
352 (xorg-wrapper config))
353
354 (define exp
355 ;; Write a small wrapper around the X server.
356 #~(apply execl #$X #$X ;; Second #$X is for argv[0].
357 "-logverbose" "-verbose" "-terminate"
358 #$@(xorg-configuration-server-arguments config)
359 (cdr (command-line))))
360
361 (program-file "startx" exp))
362
363 (define* (xinitrc #:key fallback-session)
364 "Return a system-wide xinitrc script that starts the specified X session,
365 which should be passed to this script as the first argument. If not, the
366 @var{fallback-session} will be used or, if @var{fallback-session} is false, a
367 desktop session from the system or user profile will be used."
368 (define builder
369 #~(begin
370 (use-modules (ice-9 match)
371 (ice-9 regex)
372 (ice-9 ftw)
373 (ice-9 rdelim)
374 (srfi srfi-1)
375 (srfi srfi-26))
376
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
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)))
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
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
435 (let* ((home (getenv "HOME"))
436 (xsession-file (string-append home "/.xsession"))
437 (session (match (command-line)
438 ((_)
439 #$(if fallback-session
440 #~(list #$fallback-session)
441 #f))
442 ((_ x ..1)
443 x))))
444 (if (file-exists? xsession-file)
445 ;; Run ~/.xsession when it exists.
446 (apply exec-from-login-shell xsession-file
447 (or session '()))
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)))))))
453
454 (program-file "xinitrc" builder))
455
456 \f
457 ;;;
458 ;;; SLiM log-in manager.
459 ;;;
460
461 (define %default-slim-theme
462 ;; Theme based on work by Felipe López.
463 (file-append %artwork-repository "/slim"))
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.
468 "0.x")
469
470 (define-record-type* <slim-configuration>
471 slim-configuration make-slim-configuration
472 slim-configuration?
473 (slim slim-configuration-slim
474 (default slim))
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))
485 (xauth slim-configuration-xauth
486 (default xauth))
487 (shepherd slim-configuration-shepherd
488 (default shepherd))
489 (auto-login-session slim-configuration-auto-login-session
490 (default #f))
491 (xorg-configuration slim-configuration-xorg
492 (default (xorg-configuration)))
493 (display slim-configuration-display
494 (default ":0"))
495 (vt slim-configuration-vt
496 (default "vt7"))
497 (sessreg slim-configuration-sessreg
498 (default sessreg)))
499
500 (define (slim-pam-service config)
501 "Return a PAM service for @command{slim}."
502 (list (unix-pam-service
503 "slim"
504 #:allow-empty-passwords?
505 (slim-configuration-allow-empty-passwords? config))))
506
507 (define (slim-shepherd-service config)
508 (let* ((xinitrc (xinitrc #:fallback-session
509 (slim-configuration-auto-login-session config)))
510 (xauth (slim-configuration-xauth config))
511 (startx (xorg-start-command (slim-configuration-xorg config)))
512 (display (slim-configuration-display config))
513 (vt (slim-configuration-vt config))
514 (shepherd (slim-configuration-shepherd config))
515 (theme-name (slim-configuration-theme-name config))
516 (sessreg (slim-configuration-sessreg config))
517 (lockfile (string-append "/var/run/slim-" vt ".lock")))
518 (define slim.cfg
519 (mixed-text-file "slim.cfg" "
520 default_path /run/current-system/profile/bin
521 default_xserver " startx "
522 display_name " display "
523 xserver_arguments " vt "
524 xauth_path " xauth "/bin/xauth
525 authfile /var/run/slim-" vt ".auth
526 lockfile " lockfile "
527 logfile /var/log/slim-" vt ".log
528
529 # The login command. '%session' is replaced by the chosen session name, one
530 # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
531 login_cmd exec " xinitrc " %session
532 sessiondir /run/current-system/profile/share/xsessions
533 session_msg session (F1 to change):
534 sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
535 sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
536
537 halt_cmd " shepherd "/sbin/halt
538 reboot_cmd " shepherd "/sbin/reboot\n"
539 (if (slim-configuration-auto-login? config)
540 (string-append "auto_login yes\ndefault_user "
541 (slim-configuration-default-user config) "\n")
542 "")
543 (if theme-name
544 (string-append "current_theme " theme-name "\n")
545 "")))
546
547 (define theme
548 (slim-configuration-theme config))
549
550 (list (shepherd-service
551 (documentation "Xorg display server")
552 (provision (append
553 ;; For compatibility, also provide 'xorg-server'.
554 (if (string=? vt "vt7")
555 '(xorg-server)
556 '())
557
558 (list (symbol-append 'xorg-server-
559 (string->symbol vt)))))
560 (requirement '(user-processes host-name udev))
561 (start
562 #~(lambda ()
563 ;; A stale lock file can prevent SLiM from starting, so remove it to
564 ;; be on the safe side.
565 (false-if-exception (delete-file lockfile))
566
567 (fork+exec-command
568 (list (string-append #$(slim-configuration-slim config)
569 "/bin/slim")
570 "-nodaemon")
571 #:environment-variables
572 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
573 #$@(if theme
574 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
575 #~())))))
576 (stop #~(make-kill-destructor))
577 (respawn? #t)))))
578
579 (define slim-service-type
580 (service-type (name 'slim)
581 (extensions
582 (list (service-extension shepherd-root-service-type
583 slim-shepherd-service)
584 (service-extension pam-root-service-type
585 slim-pam-service)
586
587 ;; Unconditionally add xterm to the system profile, to
588 ;; avoid bad surprises.
589 (service-extension profile-service-type
590 (const (list xterm)))))
591 (default-value (slim-configuration))))
592
593 (define-deprecated (slim-service #:key (slim slim)
594 (allow-empty-passwords? #t) auto-login?
595 (default-user "")
596 (theme %default-slim-theme)
597 (theme-name %default-slim-theme-name)
598 (xauth xauth) (shepherd shepherd)
599 (auto-login-session #f)
600 (startx (xorg-start-command)))
601 slim-service-type
602 "Return a service that spawns the SLiM graphical login manager, which in
603 turn starts the X display server with @var{startx}, a command as returned by
604 @code{xorg-start-command}.
605
606 @cindex X session
607
608 SLiM automatically looks for session types described by the @file{.desktop}
609 files in @file{/run/current-system/profile/share/xsessions} and allows users
610 to choose a session from the log-in screen using @kbd{F1}. Packages such as
611 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
612 adding them to the system-wide set of packages automatically makes them
613 available at the log-in screen.
614
615 In addition, @file{~/.xsession} files are honored. When available,
616 @file{~/.xsession} must be an executable that starts a window manager
617 and/or other X clients.
618
619 When @var{allow-empty-passwords?} is true, allow logins with an empty
620 password. When @var{auto-login?} is true, log in automatically as
621 @var{default-user} with @var{auto-login-session}.
622
623 If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
624 @var{theme} must be a gexp denoting the name of a directory containing the
625 theme to use. In that case, @var{theme-name} specifies the name of the
626 theme."
627 (service slim-service-type
628 (slim-configuration
629 (slim slim)
630 (allow-empty-passwords? allow-empty-passwords?)
631 (auto-login? auto-login?) (default-user default-user)
632 (theme theme) (theme-name theme-name)
633 (xauth xauth) (shepherd shepherd)
634 (auto-login-session auto-login-session))))
635
636 \f
637 ;;;
638 ;;; Screen lockers & co.
639 ;;;
640
641 (define-record-type <screen-locker>
642 (screen-locker name program empty?)
643 screen-locker?
644 (name screen-locker-name) ;string
645 (program screen-locker-program) ;gexp
646 (empty? screen-locker-allows-empty-passwords?)) ;Boolean
647
648 (define screen-locker-pam-services
649 (match-lambda
650 (($ <screen-locker> name _ empty?)
651 (list (unix-pam-service name
652 #:allow-empty-passwords? empty?)))))
653
654 (define screen-locker-setuid-programs
655 (compose list screen-locker-program))
656
657 (define screen-locker-service-type
658 (service-type (name 'screen-locker)
659 (extensions
660 (list (service-extension pam-root-service-type
661 screen-locker-pam-services)
662 (service-extension setuid-program-service-type
663 screen-locker-setuid-programs)))))
664
665 (define* (screen-locker-service package
666 #:optional
667 (program (package-name package))
668 #:key allow-empty-passwords?)
669 "Add @var{package}, a package for a screen locker or screen saver whose
670 command is @var{program}, to the set of setuid programs and add a PAM entry
671 for it. For example:
672
673 @lisp
674 (screen-locker-service xlockmore \"xlock\")
675 @end lisp
676
677 makes the good ol' XlockMore usable."
678 (service screen-locker-service-type
679 (screen-locker program
680 (file-append package "/bin/" program)
681 allow-empty-passwords?)))
682
683 \f
684 ;;;
685 ;;; Locale service.
686 ;;;
687
688 (define-record-type* <localed-configuration>
689 localed-configuration make-localed-configuration
690 localed-configuration?
691 (localed localed-configuration-localed
692 (default localed))
693 (keyboard-layout localed-configuration-keyboard-layout
694 (default #f)))
695
696 (define (localed-dbus-service config)
697 "Return the 'localed' D-Bus service for @var{config}, a
698 @code{<localed-configuration>} record."
699 (define keyboard-layout
700 (localed-configuration-keyboard-layout config))
701
702 ;; The primary purpose of 'localed' is to tell GDM what the "current" Xorg
703 ;; keyboard layout is. If 'localed' is missing, or if it's unable to
704 ;; determine the current XKB layout, then GDM forcefully installs its
705 ;; default XKB config (US English). Here we communicate the configured
706 ;; layout through environment variables.
707
708 (if keyboard-layout
709 (let* ((layout (keyboard-layout-name keyboard-layout))
710 (variant (keyboard-layout-variant keyboard-layout))
711 (model (keyboard-layout-model keyboard-layout))
712 (options (keyboard-layout-options keyboard-layout)))
713 (list (wrapped-dbus-service
714 (localed-configuration-localed config)
715 "libexec/localed/localed"
716 `(("GUIX_XKB_LAYOUT" ,layout)
717 ,@(if variant
718 `(("GUIX_XKB_VARIANT" ,variant))
719 '())
720 ,@(if model
721 `(("GUIX_XKB_MODEL" ,model))
722 '())
723 ,@(if (null? options)
724 '()
725 `(("GUIX_XKB_OPTIONS"
726 ,(string-join options ","))))))))
727 '()))
728
729 (define localed-service-type
730 (let ((package (lambda (config)
731 ;; Don't bother if the user didn't specify any keyboard
732 ;; layout.
733 (if (localed-configuration-keyboard-layout config)
734 (list (localed-configuration-localed config))
735 '()))))
736 (service-type (name 'localed)
737 (extensions
738 (list (service-extension dbus-root-service-type
739 localed-dbus-service)
740 (service-extension udev-service-type package)
741 (service-extension polkit-service-type package)
742
743 ;; Add 'localectl' to the profile.
744 (service-extension profile-service-type package)))
745
746 ;; This service can be extended, typically by the X login
747 ;; manager, to communicate the chosen Xorg keyboard layout.
748 (compose (lambda (extensions)
749 (find keyboard-layout? extensions)))
750 (extend (lambda (config keyboard-layout)
751 (localed-configuration
752 (inherit config)
753 (keyboard-layout keyboard-layout))))
754 (description
755 "Run the locale daemon, @command{localed}, which can be used
756 to control the system locale and keyboard mapping from user programs such as
757 the GNOME desktop environment.")
758 (default-value (localed-configuration)))))
759
760 \f
761 ;;;
762 ;;; GNOME Desktop Manager.
763 ;;;
764
765 (define %gdm-accounts
766 (list (user-group (name "gdm") (system? #t))
767 (user-account
768 (name "gdm")
769 (group "gdm")
770 (system? #t)
771 (comment "GNOME Display Manager user")
772 (home-directory "/var/lib/gdm")
773 (shell (file-append shadow "/sbin/nologin")))))
774
775 (define dbus-daemon-wrapper
776 (program-file "gdm-dbus-wrapper"
777 #~(begin
778 (setenv "XDG_CONFIG_DIRS"
779 "/run/current-system/profile/etc/xdg")
780 (setenv "XDG_DATA_DIRS"
781 "/run/current-system/profile/share")
782 (apply execl (string-append #$dbus "/bin/dbus-daemon")
783 (program-arguments)))))
784
785 (define-record-type* <gdm-configuration>
786 gdm-configuration make-gdm-configuration
787 gdm-configuration?
788 (gdm gdm-configuration-gdm (default gdm))
789 (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
790 (auto-login? gdm-configuration-auto-login? (default #f))
791 (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
792 (default-user gdm-configuration-default-user (default #f))
793 (gnome-shell-assets gdm-configuration-gnome-shell-assets
794 (default (list adwaita-icon-theme font-cantarell)))
795 (xorg-configuration gdm-configuration-xorg
796 (default (xorg-configuration)))
797 (x-session gdm-configuration-x-session
798 (default (xinitrc))))
799
800 (define (gdm-configuration-file config)
801 (mixed-text-file "gdm-custom.conf"
802 "[daemon]\n"
803 "#User=gdm\n"
804 "#Group=gdm\n"
805 (if (gdm-configuration-auto-login? config)
806 (string-append
807 "AutomaticLoginEnable=true\n"
808 "AutomaticLogin="
809 (or (gdm-configuration-default-user config)
810 (error "missing default user for auto-login"))
811 "\n")
812 (string-append
813 "AutomaticLoginEnable=false\n"
814 "#AutomaticLogin=\n"))
815 "#TimedLoginEnable=false\n"
816 "#TimedLogin=\n"
817 "#TimedLoginDelay=0\n"
818 "#InitialSetupEnable=true\n"
819 ;; Enable me once X is working.
820 "WaylandEnable=false\n"
821 "\n"
822 "[debug]\n"
823 "#Enable=true\n"
824 "\n"
825 "[security]\n"
826 "#DisallowTCP=true\n"
827 "#AllowRemoteAutoLogin=false\n"))
828
829 (define (gdm-pam-service config)
830 "Return a PAM service for @command{gdm}."
831 (list
832 (pam-service
833 (inherit (unix-pam-service "gdm-autologin"))
834 (auth (list (pam-entry
835 (control "[success=ok default=1]")
836 (module (file-append (gdm-configuration-gdm config)
837 "/lib/security/pam_gdm.so")))
838 (pam-entry
839 (control "sufficient")
840 (module "pam_permit.so")))))
841 (pam-service
842 (inherit (unix-pam-service "gdm-launch-environment"))
843 (auth (list (pam-entry
844 (control "required")
845 (module "pam_permit.so")))))
846 (unix-pam-service "gdm-password"
847 #:allow-empty-passwords?
848 (gdm-configuration-allow-empty-passwords? config))))
849
850 (define (gdm-shepherd-service config)
851 (list (shepherd-service
852 (documentation "Xorg display server (GDM)")
853 (provision '(xorg-server))
854 (requirement '(dbus-system user-processes host-name udev))
855 (start #~(lambda ()
856 (fork+exec-command
857 (list #$(file-append (gdm-configuration-gdm config)
858 "/bin/gdm"))
859 #:environment-variables
860 (list (string-append
861 "GDM_CUSTOM_CONF="
862 #$(gdm-configuration-file config))
863 (string-append
864 "GDM_DBUS_DAEMON="
865 #$(gdm-configuration-dbus-daemon config))
866 (string-append
867 "GDM_X_SERVER="
868 #$(xorg-wrapper
869 (gdm-configuration-xorg config)))
870 (string-append
871 "GDM_X_SESSION="
872 #$(gdm-configuration-x-session config))
873 (string-append
874 "XDG_DATA_DIRS="
875 ((lambda (ls) (string-join ls ":"))
876 (map (lambda (path)
877 (string-append path "/share"))
878 ;; XXX: Remove gnome-shell below when GDM
879 ;; can depend on GNOME Shell directly.
880 (cons #$gnome-shell
881 '#$(gdm-configuration-gnome-shell-assets
882 config)))))))))
883 (stop #~(make-kill-destructor))
884 (respawn? #t))))
885
886 (define gdm-service-type
887 (service-type (name 'gdm)
888 (extensions
889 (list (service-extension shepherd-root-service-type
890 gdm-shepherd-service)
891 (service-extension account-service-type
892 (const %gdm-accounts))
893 (service-extension pam-root-service-type
894 gdm-pam-service)
895 (service-extension profile-service-type
896 gdm-configuration-gnome-shell-assets)
897 (service-extension dbus-root-service-type
898 (compose list
899 gdm-configuration-gdm))
900 (service-extension localed-service-type
901 (compose
902 xorg-configuration-keyboard-layout
903 gdm-configuration-xorg))))
904
905 ;; For convenience, this service can be extended with an
906 ;; <xorg-configuration> record. Take the first one that
907 ;; comes.
908 (compose (lambda (extensions)
909 (match extensions
910 (() #f)
911 ((config . _) config))))
912 (extend (lambda (config xorg-configuration)
913 (if xorg-configuration
914 (gdm-configuration
915 (inherit config)
916 (xorg-configuration xorg-configuration))
917 config)))
918
919 (default-value (gdm-configuration))
920 (description
921 "Run the GNOME Desktop Manager (GDM), a program that allows
922 you to log in in a graphical session, whether or not you use GNOME.")))
923
924 (define-deprecated (gdm-service #:key (gdm gdm)
925 (allow-empty-passwords? #t)
926 (x-server (xorg-wrapper)))
927 gdm-service-type
928 "Return a service that spawns the GDM graphical login manager, which in turn
929 starts the X display server with @var{X}, a command as returned by
930 @code{xorg-wrapper}.
931
932 @cindex X session
933
934 GDM automatically looks for session types described by the @file{.desktop}
935 files in @file{/run/current-system/profile/share/xsessions} and allows users
936 to choose a session from the log-in screen using @kbd{F1}. Packages such as
937 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
938 adding them to the system-wide set of packages automatically makes them
939 available at the log-in screen.
940
941 In addition, @file{~/.xsession} files are honored. When available,
942 @file{~/.xsession} must be an executable that starts a window manager
943 and/or other X clients.
944
945 When @var{allow-empty-passwords?} is true, allow logins with an empty
946 password."
947 (service gdm-service-type
948 (gdm-configuration
949 (gdm gdm)
950 (allow-empty-passwords? allow-empty-passwords?))))
951
952 (define* (set-xorg-configuration config
953 #:optional
954 (login-manager-service-type
955 gdm-service-type))
956 "Tell the log-in manager (of type @var{login-manager-service-type}) to use
957 @var{config}, an <xorg-configuration> record."
958 (simple-service 'set-xorg-configuration
959 login-manager-service-type
960 config))
961
962 ;;; xorg.scm ends here