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