services: Add 'localed' service type and have GDM extend it.
[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-sessreg
87
88 slim-service-type
89 slim-service
90
91 screen-locker
92 screen-locker?
93 screen-locker-service-type
94 screen-locker-service
95
96 localed-configuration
97 localed-configuration?
98 localed-service-type
99
100 gdm-configuration
101 gdm-service-type
102 gdm-service))
103
104 ;;; Commentary:
105 ;;;
106 ;;; Services that relate to the X Window System.
107 ;;;
108 ;;; Code:
109
110 (define %default-xorg-modules
111 ;; Default list of modules loaded by the server. When multiple drivers
112 ;; match, the first one in the list is loaded.
113 (list xf86-video-vesa
114 xf86-video-fbdev
115 xf86-video-amdgpu
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")
139 (file-append font-misc-misc ;default fonts for xterm
140 "/share/fonts/X11/misc")
141 (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
142
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 '()))
159 (keyboard-layout xorg-configuration-keyboard-layout ;#f | <keyboard-layout>
160 (default #f))
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."
171 (define all-modules
172 ;; 'xorg-server' provides 'fbdevhw.so' etc.
173 (append (xorg-configuration-modules config)
174 (list xorg-server)))
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
185 '#$(xorg-configuration-drivers config))
186
187 (define (device-section driver)
188 (string-append "
189 Section \"Device\"
190 Identifier \"device-" driver "\"
191 Driver \"" driver "\"
192 EndSection"))
193
194 (define (screen-section driver resolutions)
195 (string-append "
196 Section \"Screen\"
197 Identifier \"screen-" driver "\"
198 Device \"device-" driver "\"
199 SubSection \"Display\"
200 Modes "
201 (string-join (map (match-lambda
202 ((x y)
203 (string-append "\"" (number->string x)
204 "x" (number->string y) "\"")))
205 resolutions)) "
206 EndSubSection
207 EndSection"))
208
209 (define (input-class-section layout variant model options)
210 (string-append "
211 Section \"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\"
232 EndSection\n"))
233
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))
248
249 (display "Section \"Files\"\n" port)
250 (for-each (lambda (font)
251 (format port " FontPath \"~a\"~%" font))
252 '#$(xorg-configuration-fonts config))
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 "
264 Section \"ServerFlags\"
265 Option \"AllowMouseOpenFail\" \"on\"
266 EndSection\n" port)
267
268 (display (string-join (map device-section drivers) "\n")
269 port)
270 (newline port)
271 (display (string-join
272 (map (cut screen-section <>
273 '#$(xorg-configuration-resolutions config))
274 drivers)
275 "\n")
276 port)
277 (newline port)
278
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))
285 (options '#$(and=> (xorg-configuration-keyboard-layout config)
286 keyboard-layout-options)))
287 (when layout
288 (display (input-class-section layout variant model options)
289 port)
290 (newline port)))
291
292 (for-each (lambda (config)
293 (display config port))
294 '#$(xorg-configuration-extra-config config))))))
295
296 (computed-file "xserver.conf" build))
297
298 (define (xorg-configuration-directory modules)
299 "Return a directory that contains the @code{.conf} files for X.org that
300 includes the @code{share/X11/xorg.conf.d} directories of each package listed
301 in @var{modules}."
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))))
323
324 (define* (xorg-wrapper #:optional (config (xorg-configuration)))
325 "Return a derivation that builds a script to start the X server with the
326 given @var{config}. The resulting script should be used in place of
327 @code{/usr/bin/X}."
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
334 (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
335 (apply execl X X
336 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
337 "-config" #$(xorg-configuration->file config)
338 "-configdir" #$(xorg-configuration-directory
339 (xorg-configuration-modules config))
340 (cdr (command-line))))))
341
342 (program-file "X-wrapper" exp))
343
344 (define* (xorg-start-command #:optional (config (xorg-configuration)))
345 "Return a @code{startx} script in which the modules, fonts, etc. specified
346 in @var{config}, are available. The result should be used in place of
347 @code{startx}."
348 (define X
349 (xorg-wrapper config))
350
351 (define exp
352 ;; Write a small wrapper around the X server.
353 #~(apply execl #$X #$X ;; Second #$X is for argv[0].
354 "-logverbose" "-verbose" "-terminate"
355 #$@(xorg-configuration-server-arguments config)
356 (cdr (command-line))))
357
358 (program-file "startx" exp))
359
360 (define* (xinitrc #:key fallback-session)
361 "Return a system-wide xinitrc script that starts the specified X session,
362 which should be passed to this script as the first argument. If not, the
363 @var{fallback-session} will be used or, if @var{fallback-session} is false, a
364 desktop session from the system or user profile will be used."
365 (define builder
366 #~(begin
367 (use-modules (ice-9 match)
368 (ice-9 regex)
369 (ice-9 ftw)
370 (ice-9 rdelim)
371 (srfi srfi-1)
372 (srfi srfi-26))
373
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
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)))
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
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
432 (let* ((home (getenv "HOME"))
433 (xsession-file (string-append home "/.xsession"))
434 (session (match (command-line)
435 ((_)
436 #$(if fallback-session
437 #~(list #$fallback-session)
438 #f))
439 ((_ x ..1)
440 x))))
441 (if (file-exists? xsession-file)
442 ;; Run ~/.xsession when it exists.
443 (apply exec-from-login-shell xsession-file
444 (or session '()))
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)))))))
450
451 (program-file "xinitrc" builder))
452
453 \f
454 ;;;
455 ;;; SLiM log-in manager.
456 ;;;
457
458 (define %default-slim-theme
459 ;; Theme based on work by Felipe López.
460 (file-append %artwork-repository "/slim"))
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.
465 "0.x")
466
467 (define-record-type* <slim-configuration>
468 slim-configuration make-slim-configuration
469 slim-configuration?
470 (slim slim-configuration-slim
471 (default slim))
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))
482 (xauth slim-configuration-xauth
483 (default xauth))
484 (shepherd slim-configuration-shepherd
485 (default shepherd))
486 (auto-login-session slim-configuration-auto-login-session
487 (default #f))
488 (xorg-configuration slim-configuration-xorg
489 (default (xorg-configuration)))
490 (sessreg slim-configuration-sessreg
491 (default sessreg)))
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
500 (define (slim-shepherd-service config)
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))
506 (startx (xorg-start-command (slim-configuration-xorg config)))
507 (shepherd (slim-configuration-shepherd config))
508 (theme-name (slim-configuration-theme-name config))
509 (sessreg (slim-configuration-sessreg config)))
510 (mixed-text-file "slim.cfg" "
511 default_path /run/current-system/profile/bin
512 default_xserver " startx "
513 xserver_arguments :0 vt7
514 xauth_path " xauth "/bin/xauth
515 authfile /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.
519 login_cmd exec " xinitrc " %session
520 sessiondir /run/current-system/profile/share/xsessions
521 session_msg session (F1 to change):
522 sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
523 sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
524
525 halt_cmd " shepherd "/sbin/halt
526 reboot_cmd " shepherd "/sbin/reboot\n"
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
538 (list (shepherd-service
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
561 (list (service-extension shepherd-root-service-type
562 slim-shepherd-service)
563 (service-extension pam-root-service-type
564 slim-pam-service)
565
566 ;; Unconditionally add xterm to the system profile, to
567 ;; avoid bad surprises.
568 (service-extension profile-service-type
569 (const (list xterm)))))
570 (default-value (slim-configuration))))
571
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
581 "Return a service that spawns the SLiM graphical login manager, which in
582 turn starts the X display server with @var{startx}, a command as returned by
583 @code{xorg-start-command}.
584
585 @cindex X session
586
587 SLiM automatically looks for session types described by the @file{.desktop}
588 files in @file{/run/current-system/profile/share/xsessions} and allows users
589 to 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;
591 adding them to the system-wide set of packages automatically makes them
592 available at the log-in screen.
593
594 In addition, @file{~/.xsession} files are honored. When available,
595 @file{~/.xsession} must be an executable that starts a window manager
596 and/or other X clients.
597
598 When @var{allow-empty-passwords?} is true, allow logins with an empty
599 password. When @var{auto-login?} is true, log in automatically as
600 @var{default-user} with @var{auto-login-session}.
601
602 If @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
604 theme to use. In that case, @var{theme-name} specifies the name of the
605 theme."
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)
612 (xauth xauth) (shepherd shepherd)
613 (auto-login-session auto-login-session))))
614
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?)
648 "Add @var{package}, a package for a screen locker or screen saver whose
649 command is @var{program}, to the set of setuid programs and add a PAM entry
650 for it. For example:
651
652 @lisp
653 (screen-locker-service xlockmore \"xlock\")
654 @end lisp
655
656 makes the good ol' XlockMore usable."
657 (service screen-locker-service-type
658 (screen-locker program
659 (file-append package "/bin/" program)
660 allow-empty-passwords?)))
661
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
729 to control the system locale and keyboard mapping from user programs such as
730 the GNOME desktop environment.")
731 (default-value (localed-configuration)))))
732
733 \f
734 ;;;
735 ;;; GNOME Desktop Manager.
736 ;;;
737
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
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
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))
763 (auto-login? gdm-configuration-auto-login? (default #f))
764 (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
765 (default-user gdm-configuration-default-user (default #f))
766 (gnome-shell-assets gdm-configuration-gnome-shell-assets
767 (default (list adwaita-icon-theme font-cantarell)))
768 (xorg-configuration gdm-configuration-xorg
769 (default (xorg-configuration)))
770 (x-session gdm-configuration-x-session
771 (default (xinitrc))))
772
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"))
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")))))
819 (unix-pam-service "gdm-password"
820 #:allow-empty-passwords?
821 (gdm-configuration-allow-empty-passwords? config))))
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))
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
834 "GDM_CUSTOM_CONF="
835 #$(gdm-configuration-file config))
836 (string-append
837 "GDM_DBUS_DAEMON="
838 #$(gdm-configuration-dbus-daemon config))
839 (string-append
840 "GDM_X_SERVER="
841 #$(xorg-wrapper
842 (gdm-configuration-xorg config)))
843 (string-append
844 "GDM_X_SESSION="
845 #$(gdm-configuration-x-session config))
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)))))))))
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)
868 (service-extension profile-service-type
869 gdm-configuration-gnome-shell-assets)
870 (service-extension dbus-root-service-type
871 (compose list
872 gdm-configuration-gdm))
873 (service-extension localed-service-type
874 (compose
875 xorg-configuration-keyboard-layout
876 gdm-configuration-xorg))))
877
878 (default-value (gdm-configuration))
879 (description
880 "Run the GNOME Desktop Manager (GDM), a program that allows
881 you to log in in a graphical session, whether or not you use GNOME.")))
882
883 (define-deprecated (gdm-service #:key (gdm gdm)
884 (allow-empty-passwords? #t)
885 (x-server (xorg-wrapper)))
886 gdm-service-type
887 "Return a service that spawns the GDM graphical login manager, which in turn
888 starts the X display server with @var{X}, a command as returned by
889 @code{xorg-wrapper}.
890
891 @cindex X session
892
893 GDM automatically looks for session types described by the @file{.desktop}
894 files in @file{/run/current-system/profile/share/xsessions} and allows users
895 to 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;
897 adding them to the system-wide set of packages automatically makes them
898 available at the log-in screen.
899
900 In addition, @file{~/.xsession} files are honored. When available,
901 @file{~/.xsession} must be an executable that starts a window manager
902 and/or other X clients.
903
904 When @var{allow-empty-passwords?} is true, allow logins with an empty
905 password."
906 (service gdm-service-type
907 (gdm-configuration
908 (gdm gdm)
909 (allow-empty-passwords? allow-empty-passwords?))))
910
911 ;;; xorg.scm ends here