projects/guix·blob ruby-team · refs

1445 lines · 58.0 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Andy Wingo <[email protected]>
3;;; Copyright © 2013-2017, 2019-2020, 2022, 2024 Ludovic Courtès <[email protected]>
4;;; Copyright © 2015 Sou Bunnbu <[email protected]>
5;;; Copyright © 2018, 2019 Timothy Sample <[email protected]>
6;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <[email protected]>
7;;; Copyright © 2019 Tim Gesthuizen <[email protected]>
8;;; Copyright © 2020 shtwzrd <[email protected]>
9;;; Copyright © 2020 Jakub Kądziołka <[email protected]>
10;;; Copyright © 2020 Alex Griffin <[email protected]>
11;;; Copyright © 2021 Brice Waegeneire <[email protected]>
12;;; Copyright © 2021 Oleg Pykhalov <[email protected]>
13;;; Copyright © 2021 Josselin Poiret <[email protected]>
14;;; Copyright © 2022 Chris Marusich <[email protected]>
15;;; Copyright © 2022 Maxim Cournoyer <[email protected]>
16;;; Copyright © 2023 muradm <[email protected]>
17;;; Copyright © 2024 Zheng Junjie <[email protected]>
18;;; Copyright © 2024 Tomas Volf <[email protected]>
19;;; Copyright © 2025 Ian Eure <[email protected]>
20;;;
21;;; This file is part of GNU Guix.
22;;;
23;;; GNU Guix is free software; you can redistribute it and/or modify it
24;;; under the terms of the GNU General Public License as published by
25;;; the Free Software Foundation; either version 3 of the License, or (at
26;;; your option) any later version.
27;;;
28;;; GNU Guix is distributed in the hope that it will be useful, but
29;;; WITHOUT ANY WARRANTY; without even the implied warranty of
30;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31;;; GNU General Public License for more details.
32;;;
33;;; You should have received a copy of the GNU General Public License
34;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
35
36(define-module (gnu services xorg)
37 #:autoload (gnu services sddm) (sddm-service-type)
38 #:use-module (gnu artwork)
39 #:use-module (gnu services)
40 #:use-module (gnu services configuration)
41 #:use-module (gnu services shepherd)
42 #:use-module (gnu system keyboard)
43 #:use-module (gnu system pam)
44 #:use-module (gnu system privilege)
45 #:use-module (gnu services base)
46 #:use-module (gnu services dbus)
47 #:use-module (gnu packages base)
48 #:use-module (gnu packages guile)
49 #:use-module (gnu packages xorg)
50 #:use-module (gnu packages fonts)
51 #:use-module (gnu packages gl)
52 #:use-module (gnu packages glib)
53 #:use-module (gnu packages display-managers)
54 #:use-module (gnu packages freedesktop)
55 #:use-module (gnu packages gnustep)
56 #:use-module (gnu packages gnome)
57 #:use-module (gnu packages admin)
58 #:use-module (gnu packages bash)
59 #:use-module (gnu packages linux)
60 #:use-module (gnu system shadow)
61 #:use-module (guix build-system glib-or-gtk)
62 #:use-module (guix build-system trivial)
63 #:use-module (guix gexp)
64 #:use-module (guix store)
65 #:use-module ((guix modules) #:select (source-module-closure))
66 #:use-module (guix packages)
67 #:use-module (guix derivations)
68 #:use-module (guix platform)
69 #:use-module (guix records)
70 #:use-module (guix deprecation)
71 #:use-module (guix utils)
72 #:use-module (srfi srfi-1)
73 #:use-module (srfi srfi-9)
74 #:use-module (srfi srfi-26)
75 #:use-module (ice-9 format)
76 #:use-module (ice-9 match)
77 #:export (xorg-configuration
78 xorg-configuration?
79 xorg-configuration-modules
80 xorg-configuration-fonts
81 xorg-configuration-drivers
82 xorg-configuration-resolutions
83 xorg-configuration-extra-config
84 xorg-configuration-server
85 xorg-configuration-server-arguments
86 xorg-configuration-keyboard-layout
87
88 %default-xorg-modules
89 %default-xorg-fonts
90 %default-xorg-server-arguments
91
92 xorg-wrapper
93 xorg-start-command
94 xorg-start-command-xinit
95 xinitrc
96 xorg-server-service-type
97 startx-command-service-type
98
99 %default-slim-theme
100 %default-slim-theme-name
101
102 slim-configuration
103 slim-configuration?
104 slim-configuration-slim
105 slim-configuration-allow-empty-passwords?
106 slim-configuration-auto-login?
107 slim-configuration-default-user
108 slim-configuration-theme
109 slim-configuration-theme-name
110 slim-configuration-xauth
111 slim-configuration-shepherd
112 slim-configuration-auto-login-session
113 slim-configuration-xorg
114 slim-configuration-display
115 slim-configuration-vt
116 slim-configuration-sessreg
117
118 slim-service-type
119
120 screen-locker-configuration
121 screen-locker-configuration?
122 screen-locker-configuration-name
123 screen-locker-configuration-program
124 screen-locker-configuration-allow-empty-password?
125 screen-locker-configuration-using-pam?
126 screen-locker-configuration-using-setuid?
127 screen-locker-service-type
128 screen-locker-service ; deprecated
129
130 localed-configuration
131 localed-configuration?
132 localed-service-type
133
134 dconf-keyfile
135 dconf-profile
136 dconf-profile-name
137 dconf-profile-content
138 dconf-profile-keyfile
139 dconf-service-type
140
141 gdm-configuration
142 gdm-service-type
143
144 handle-xorg-configuration
145 set-xorg-configuration))
146
147;;; Commentary:
148;;;
149;;; Services that relate to the X Window System.
150;;;
151;;; Code:
152
153(define* (default-xorg-modules
154 #:optional
155 (system (or (and=>
156 (%current-target-system)
157 platform-target->system)
158 (%current-system))))
159 "Default list of modules loaded by the server. When multiple drivers match,
160the first one in the list is loaded."
161 ;; Return only supported packages, because some aren't supported
162 ;; on all architectures.
163 (filter (cut supported-package? <> system)
164 (list xf86-video-vesa
165 xf86-video-fbdev
166 xf86-video-amdgpu
167 xf86-video-ati
168 xf86-video-cirrus
169 xf86-video-intel
170 xf86-video-mach64
171 xf86-video-nouveau
172 xf86-video-nv
173 xf86-video-sis
174
175 ;; Libinput is the new thing and is recommended over evdev/synaptics:
176 ;; <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
177 xf86-input-libinput
178 xf86-input-evdev
179 xf86-input-mouse)))
180
181(define-syntax %default-xorg-modules
182 (identifier-syntax (default-xorg-modules)))
183
184(define %default-xorg-fonts
185 ;; Default list of fonts available to the X server.
186 (list (file-append font-alias "/share/fonts/X11/75dpi")
187 (file-append font-alias "/share/fonts/X11/100dpi")
188 (file-append font-alias "/share/fonts/X11/misc")
189 (file-append font-alias "/share/fonts/X11/cyrillic")
190 (file-append font-misc-misc ;default fonts for xterm
191 "/share/fonts/X11/misc")
192 (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
193
194(define %default-xorg-server-arguments
195 ;; Default command-line arguments for X.
196 '("-nolisten" "tcp"))
197
198(define %default-xorg-server xorg-server)
199
200;; Configuration of an Xorg server.
201(define-record-type* <xorg-configuration>
202 xorg-configuration make-xorg-configuration
203 xorg-configuration?
204 (modules xorg-configuration-modules ;list of file-like
205 (thunked)
206 ; filter out modules not supported on current system
207 (default (filter
208 (lambda (p)
209 (member (%current-system)
210 (package-supported-systems p)))
211 %default-xorg-modules)))
212 (fonts xorg-configuration-fonts ;list of packges
213 (default %default-xorg-fonts))
214 (drivers xorg-configuration-drivers ;list of strings
215 (default '()))
216 (resolutions xorg-configuration-resolutions ;list of tuples
217 (default '()))
218 (keyboard-layout xorg-configuration-keyboard-layout ;#f | <keyboard-layout>
219 (default #f))
220 (extra-config xorg-configuration-extra-config ;list of strings
221 (default '()))
222 (server xorg-configuration-server ;file-like
223 (default %default-xorg-server))
224 (server-arguments xorg-configuration-server-arguments ;list of strings
225 (default %default-xorg-server-arguments)))
226
227(define (merge-xorg-configurations configs)
228 ;; Find whichever config has a non-default Xorg server.
229 (let ((config-with-server
230 (or
231 (find
232 (lambda (config)
233 (or (not (eq? %default-xorg-server
234 (xorg-configuration-server config)))
235 (not (eq? %default-xorg-server-arguments
236 (xorg-configuration-server-arguments config)))))
237 (reverse configs))
238 (xorg-configuration))))
239
240 (xorg-configuration
241 (modules
242 (delete-duplicates (append-map xorg-configuration-modules configs)))
243 (fonts
244 (delete-duplicates (append-map xorg-configuration-fonts configs)))
245 (drivers
246 (delete-duplicates (append-map xorg-configuration-drivers configs)))
247 (resolutions
248 (delete-duplicates (append-map xorg-configuration-resolutions configs)))
249 (extra-config
250 (append-map xorg-configuration-extra-config configs))
251 (keyboard-layout
252 (any xorg-configuration-keyboard-layout (reverse configs)))
253 ;; Use the later config with non-default server for both these fields.
254 (server
255 (xorg-configuration-server config-with-server))
256 (server-arguments
257 (xorg-configuration-server-arguments config-with-server)))))
258
259(define (xorg-configuration->file config)
260 "Compute an Xorg configuration file corresponding to CONFIG, an
261<xorg-configuration> record."
262 (let ((xorg-server (xorg-configuration-server config)))
263 (define all-modules
264 ;; 'xorg-server' provides 'fbdevhw.so' etc.
265 (append (xorg-configuration-modules config)
266 (list xorg-server)))
267
268 (define build
269 #~(begin
270 (use-modules (ice-9 match)
271 (srfi srfi-1)
272 (srfi srfi-26))
273
274 (call-with-output-file #$output
275 (lambda (port)
276 (define drivers
277 '#$(xorg-configuration-drivers config))
278
279 (define (device-section driver)
280 (string-append "
281Section \"Device\"
282 Identifier \"device-" driver "\"
283 Driver \"" driver "\"
284EndSection"))
285
286 (define (screen-section driver resolutions)
287 (string-append "
288Section \"Screen\"
289 Identifier \"screen-" driver "\"
290 Device \"device-" driver "\"
291 SubSection \"Display\"
292 Modes "
293 (string-join (map (match-lambda
294 ((x y)
295 (string-append "\"" (number->string x)
296 "x" (number->string y) "\"")))
297 resolutions)) "
298 EndSubSection
299EndSection"))
300
301 (define (input-class-section layout variant model options)
302 (string-append "
303Section \"InputClass\"
304 Identifier \"evdev keyboard catchall\"
305 MatchIsKeyboard \"on\"
306 Option \"XkbLayout\" " (object->string layout)
307 (if variant
308 (string-append " Option \"XkbVariant\" \""
309 variant "\"")
310 "")
311 (if model
312 (string-append " Option \"XkbModel\" \""
313 model "\"")
314 "")
315 (match options
316 (()
317 "")
318 (_
319 (string-append " Option \"XkbOptions\" \""
320 (string-join options ",") "\""))) "
321
322 MatchDevicePath \"/dev/input/event*\"
323 Driver \"evdev\"
324EndSection\n"))
325
326 (define (expand modules)
327 ;; Append to MODULES the relevant /lib/xorg/modules
328 ;; sub-directories.
329 (append-map (lambda (module)
330 (filter-map (lambda (directory)
331 (let ((full (string-append module
332 directory)))
333 (and (file-exists? full)
334 full)))
335 '("/lib/xorg/modules/drivers"
336 "/lib/xorg/modules/input"
337 "/lib/xorg/modules/multimedia"
338 "/lib/xorg/modules/extensions")))
339 modules))
340
341 (display "Section \"Files\"\n" port)
342 (for-each (lambda (font)
343 (format port " FontPath \"~a\"~%" font))
344 '#$(xorg-configuration-fonts config))
345 (for-each (lambda (module)
346 (format port
347 " ModulePath \"~a\"~%"
348 module))
349 (append (expand '#$all-modules)
350
351 ;; For fbdevhw.so and so on.
352 (list #$(file-append xorg-server
353 "/lib/xorg/modules"))))
354 (display "EndSection\n" port)
355 (display "
356Section \"ServerFlags\"
357 Option \"AllowMouseOpenFail\" \"on\"
358EndSection\n" port)
359
360 (display (string-join (map device-section drivers) "\n")
361 port)
362 (newline port)
363 (display (string-join
364 (map (cut screen-section <>
365 '#$(xorg-configuration-resolutions config))
366 drivers)
367 "\n")
368 port)
369 (newline port)
370
371 (let ((layout #$(and=> (xorg-configuration-keyboard-layout config)
372 keyboard-layout-name))
373 (variant #$(and=> (xorg-configuration-keyboard-layout config)
374 keyboard-layout-variant))
375 (model #$(and=> (xorg-configuration-keyboard-layout config)
376 keyboard-layout-model))
377 (options '#$(and=> (xorg-configuration-keyboard-layout config)
378 keyboard-layout-options)))
379 (when layout
380 (display (input-class-section layout variant model options)
381 port)
382 (newline port)))
383
384 (for-each (lambda (config)
385 (display (string-append config "\n\n") port))
386 '#$(xorg-configuration-extra-config config))))))
387
388 (computed-file "xserver.conf" build)))
389
390(define (xorg-configuration-directory modules)
391 "Return a directory that contains the @code{.conf} files for X.org that
392includes the @code{share/X11/xorg.conf.d} directories of each package listed
393in @var{modules}."
394 (with-imported-modules '((guix build utils))
395 (computed-file "xorg.conf.d"
396 #~(begin
397 (use-modules (guix build utils)
398 (srfi srfi-1))
399
400 (define files
401 (append-map (lambda (module)
402 (find-files (string-append
403 module
404 "/share/X11/xorg.conf.d")
405 "\\.conf$"))
406 (list #$@modules)))
407
408 (mkdir #$output)
409 (for-each (lambda (file)
410 (symlink file
411 (string-append #$output "/"
412 (basename file))))
413 files)
414 #t))))
415
416(define (xorg-configuration-server-package-path config input path)
417 "Lookup the direct @var{input} in the xorg server package of @var{config}
418and append @var{path} to it."
419 (let* ((server (xorg-configuration-server config))
420 (package (lookup-package-direct-input server input)))
421 (when package (file-append package path))))
422
423(define (xorg-configuration-dri-driver-path config)
424 (xorg-configuration-server-package-path config "mesa" "/lib/dri"))
425
426(define (xorg-configuration-xkb-bin-dir config)
427 (xorg-configuration-server-package-path config "xkbcomp" "/bin"))
428
429(define (xorg-configuration-xkb-dir config)
430 (xorg-configuration-server-package-path config "xkeyboard-config" "/share/X11/xkb"))
431
432(define* (xorg-wrapper #:optional (config (xorg-configuration)))
433 "Return a derivation that builds a script to start the X server with the
434given @var{config}. The resulting script should be used in place of
435@code{/usr/bin/X}."
436 (define exp
437 ;; Write a small wrapper around the X server.
438 #~(begin
439 (setenv "XORG_DRI_DRIVER_PATH"
440 #$(xorg-configuration-dri-driver-path config))
441 (setenv "XKB_BINDIR" #$(xorg-configuration-xkb-bin-dir config))
442
443 (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
444 (apply execl X X
445 "-xkbdir" #$(xorg-configuration-xkb-dir config)
446 "-config" #$(xorg-configuration->file config)
447 "-configdir" #$(xorg-configuration-directory
448 (xorg-configuration-modules config))
449 (cdr (command-line))))))
450
451 (program-file "X-wrapper" exp))
452
453(define* (xorg-start-command #:optional (config (xorg-configuration)))
454 "Return a @code{startx} script in which the modules, fonts, etc. specified
455in @var{config}, are available. The result should be used in place of
456@code{startx}."
457 (define X
458 (xorg-wrapper config))
459
460 (define exp
461 ;; Write a small wrapper around the X server.
462 #~(apply execl #$X #$X ;; Second #$X is for argv[0].
463 "-logverbose" "-verbose" "-terminate"
464 #$@(xorg-configuration-server-arguments config)
465 (cdr (command-line))))
466
467 (program-file "startx" exp))
468
469(define* (xorg-start-command-xinit #:optional (config (xorg-configuration)))
470 "Return a @code{startx} script in which the modules, fonts, etc. specified
471in @var{config}, are available. The result should be used in place of
472@code{startx}. Compared to the @code{xorg-start-command} it calls xinit,
473therefore it works well when executed from tty."
474 (define X
475 (xorg-wrapper config))
476
477 (define exp
478 ;; Small wrapper providing subset of functionality of typical startx
479 ;; script from distributions like alpine.
480 (with-imported-modules (source-module-closure '((guix build utils)))
481 #~(begin
482 (use-modules (guix build utils)
483 (ice-9 popen)
484 (ice-9 textual-ports))
485
486 (define (capture-stdout . prog+args)
487 (let* ((port (apply open-pipe* OPEN_READ prog+args))
488 (data (get-string-all port)))
489 (if (zero? (status:exit-val (close-pipe port)))
490 (string-trim-right data #\newline)
491 (error "Command failed: " prog+args))))
492
493 (define (determine-unused-display n)
494 (let ((lock-file (format #f "/tmp/.X~a-lock" n))
495 (sock-file (format #f "/tmp/.X11-unix/X~a" n)))
496 (if (or (file-exists? lock-file)
497 (false-if-exception
498 (eq? 'socket (stat:type (stat sock-file)))))
499 (determine-unused-display (+ n 1))
500 (format #f ":~a" n))))
501
502 (define (vty-from-fd0)
503 (let ((fd0 (readlink "/proc/self/fd/0"))
504 (pref "/dev/tty"))
505 (if (string-prefix? pref fd0)
506 (substring fd0 (string-length pref))
507 (error (format #f "Cannot determine VT from: ~a" fd0)))))
508
509 (define (determine-vty)
510 (string-append "vt" (or (getenv "XDG_VTNR") (vty-from-fd0))))
511
512 (define (enable-xauth server-auth-file display)
513 ;; Configure and enable X authority
514 (or (getenv "XAUTHORITY")
515 (setenv "XAUTHORITY" (string-append (getenv "HOME") "/.Xauthority")))
516
517 (let* ((bin/xauth #$(file-append xauth "/bin/xauth"))
518 (bin/mcookie #$(file-append util-linux "/bin/mcookie"))
519 (mcookie (capture-stdout bin/mcookie)))
520 (invoke bin/xauth "-qf" server-auth-file
521 "add" display "." mcookie)
522 (invoke bin/xauth "-q"
523 "add" display "." mcookie)))
524
525 (let* ((xinit #$(file-append xinit "/bin/xinit"))
526 (display (determine-unused-display 0))
527 (vty (determine-vty))
528 (server-auth-port (mkstemp "/tmp/serverauth.XXXXXX"))
529 (server-auth-file (port-filename server-auth-port)))
530 (close-port server-auth-port)
531 (enable-xauth server-auth-file display)
532 (apply execl
533 xinit
534 xinit
535 "--"
536 #$X
537 display
538 vty
539 "-keeptty"
540 "-auth" server-auth-file
541 ;; These are set by xorg-start-command, so do the same to keep
542 ;; it consistent.
543 "-logverbose" "-verbose" "-terminate"
544 #$@(xorg-configuration-server-arguments config)
545 (cdr (command-line)))))))
546
547 (program-file "startx" exp))
548
549(define (startx-command-profile-service config)
550 ;; XXX: profile-service-type only accepts <package> objects.
551 (package
552 (name "startx-profile-package")
553 (version "0")
554 (source (xorg-start-command-xinit config))
555 (build-system trivial-build-system)
556 (arguments
557 (list
558 #:modules '((guix build utils))
559 #:builder
560 #~(begin
561 (use-modules (guix build utils))
562 (let ((bin (string-append #$output "/bin")))
563 (mkdir-p bin)
564 (symlink #$source (string-append bin "/startx"))))))
565 (home-page #f)
566 (synopsis #f)
567 (description #f)
568 (license #f)))
569
570(define startx-command-service-type
571 (service-type
572 (name 'startx-command)
573 (extensions
574 (list (service-extension profile-service-type
575 (compose list startx-command-profile-service))))
576 (default-value (xorg-configuration))
577 (description "Add @command{startx} to the system profile.")))
578
579
580
581(define* (xinitrc #:key fallback-session)
582 "Return a system-wide xinitrc script that starts the specified X session,
583which should be passed to this script as the first argument. If not, the
584@var{fallback-session} will be used or, if @var{fallback-session} is false, a
585desktop session from the system or user profile will be used."
586 (define builder
587 #~(begin
588 (use-modules (ice-9 match)
589 (ice-9 regex)
590 (ice-9 ftw)
591 (ice-9 rdelim)
592 (srfi srfi-1)
593 (srfi srfi-26))
594
595 (define (close-all-fdes)
596 ;; Close all the open file descriptors except 0 to 2.
597 (let loop ((fd 3))
598 (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
599 (false-if-exception (close-fdes fd))
600 (loop (+ 1 fd)))))
601
602 (define (exec-from-login-shell command . args)
603 ;; Run COMMAND from a login shell so that it gets to see the same
604 ;; environment variables that one gets when logging in on a tty, for
605 ;; instance.
606 (let* ((pw (getpw (getuid)))
607 (shell (passwd:shell pw)))
608 ;; Close any open file descriptors. This is all the more
609 ;; important that SLiM itself exec's us directly without closing
610 ;; its own file descriptors!
611 (close-all-fdes)
612
613 ;; The '--login' option is supported at least by Bash and zsh.
614 (execl shell shell "--login" "-c"
615 (string-join (cons command args)))))
616
617 (define system-profile
618 "/run/current-system/profile")
619
620 (define user-profile
621 (and=> (getpw (getuid))
622 (lambda (pw)
623 (string-append (passwd:dir pw) "/.guix-profile"))))
624
625 (define (xsession-command desktop-file)
626 ;; Read from DESKTOP-FILE its X session command and return it as a
627 ;; list.
628 (define exec-regexp
629 (make-regexp "^[[:blank:]]*Exec=(.*)$"))
630
631 (call-with-input-file desktop-file
632 (lambda (port)
633 (let loop ()
634 (match (read-line port)
635 ((? eof-object?) #f)
636 ((= (cut regexp-exec exec-regexp <>) result)
637 (if result
638 (string-tokenize (match:substring result 1))
639 (loop))))))))
640
641 (define (find-session profile)
642 ;; Return an X session command from PROFILE or #f if none was found.
643 (let ((directory (string-append profile "/share/xsessions")))
644 (match (scandir directory
645 (cut string-suffix? ".desktop" <>))
646 ((or () #f)
647 #f)
648 ((sessions ...)
649 (any xsession-command
650 (map (cut string-append directory "/" <>)
651 sessions))))))
652
653 (let* ((home (getenv "HOME"))
654 (xsession-file (string-append home "/.xsession"))
655 (session (match (command-line)
656 ((_)
657 #$(if fallback-session
658 #~(list #$fallback-session)
659 #f))
660 ((_ x ..1)
661 x))))
662 (if (file-exists? xsession-file)
663 ;; Run ~/.xsession when it exists.
664 (apply exec-from-login-shell xsession-file
665 (or session '()))
666 ;; Otherwise, start the specified session or a fallback.
667 (apply exec-from-login-shell
668 (or session
669 (find-session user-profile)
670 (find-session system-profile)))))))
671
672 (program-file "xinitrc" builder))
673
674(define-syntax handle-xorg-configuration
675 (syntax-rules ()
676 "Generate the `compose' and `extend' entries of a login manager
677`service-type' to handle specifying the `xorg-configuration' through
678a `service-extension', as used by `set-xorg-configuration'."
679 ((_ configuration-record service-type-definition)
680 (service-type
681 (inherit service-type-definition)
682 (compose cons*)
683 (extend (lambda (config xorg-configurations)
684 (configuration-record
685 (inherit config)
686 (xorg-configuration
687 (merge-xorg-configurations
688 (cons ((record-accessor (record-type-descriptor config)
689 'xorg-configuration)
690 config)
691 xorg-configurations))))))))))
692
693(define (xorg-server-profile-service config)
694 ;; XXX: profile-service-type only accepts <package> objects.
695 (list
696 (package
697 (name "xorg-wrapper")
698 (version (package-version xorg-server))
699 (source (xorg-wrapper config))
700 (build-system trivial-build-system)
701 (arguments
702 '(#:modules ((guix build utils))
703 #:builder
704 (begin
705 (use-modules (guix build utils))
706 (let* ((source (assoc-ref %build-inputs "source"))
707 (out (assoc-ref %outputs "out"))
708 (bin (string-append out "/bin")))
709 (mkdir-p bin)
710 (symlink source (string-append bin "/X"))
711 (symlink source (string-append bin "/Xorg"))
712 #t))))
713 (home-page (package-home-page xorg-server))
714 (synopsis (package-synopsis xorg-server))
715 (description (package-description xorg-server))
716 (license (package-license xorg-server)))))
717
718(define xorg-server-service-type
719 (service-type
720 (name 'xorg-server)
721 (extensions
722 (list (service-extension profile-service-type
723 xorg-server-profile-service)))
724 (default-value (xorg-configuration))
725 (description "Add @command{X} to the system profile, to be used with
726@command{sx} or @command{xinit}.")))
727
728
729;;;
730;;; SLiM log-in manager.
731;;;
732
733(define %default-slim-theme
734 ;; Theme based on work by Felipe López.
735 (file-append %artwork-repository "/slim"))
736
737(define %default-slim-theme-name
738 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
739 ;; contains the actual theme files.
740 "1.x")
741
742(define-record-type* <slim-configuration>
743 slim-configuration make-slim-configuration
744 slim-configuration?
745 (slim slim-configuration-slim
746 (default slim))
747 (allow-empty-passwords? slim-configuration-allow-empty-passwords?
748 (default #t))
749 (gnupg? slim-configuration-gnupg?
750 (default #f))
751 (auto-login? slim-configuration-auto-login?
752 (default #f))
753 (default-user slim-configuration-default-user
754 (default ""))
755 (theme slim-configuration-theme
756 (default %default-slim-theme))
757 (theme-name slim-configuration-theme-name
758 (default %default-slim-theme-name))
759 (xauth slim-configuration-xauth
760 (default xauth))
761 (shepherd slim-configuration-shepherd
762 (default shepherd))
763 (auto-login-session slim-configuration-auto-login-session
764 (default #f))
765 (xorg-configuration slim-configuration-xorg
766 (default (xorg-configuration)))
767 (display slim-configuration-display
768 (default ":0"))
769 (vt slim-configuration-vt
770 (default "vt7"))
771 (sessreg slim-configuration-sessreg
772 (default sessreg)))
773
774(define (slim-pam-service config)
775 "Return a PAM service for @command{slim}."
776 (list (unix-pam-service
777 "slim"
778 #:login-uid? #t
779 #:allow-empty-passwords?
780 (slim-configuration-allow-empty-passwords? config)
781 #:gnupg?
782 (slim-configuration-gnupg? config))))
783
784(define (slim-shepherd-service config)
785 (let* ((xinitrc (xinitrc #:fallback-session
786 (slim-configuration-auto-login-session config)))
787 (xauth (slim-configuration-xauth config))
788 (startx (xorg-start-command (slim-configuration-xorg config)))
789 (display (slim-configuration-display config))
790 (vt (slim-configuration-vt config))
791 (shepherd (slim-configuration-shepherd config))
792 (theme-name (slim-configuration-theme-name config))
793 (sessreg (slim-configuration-sessreg config))
794 (lockfile (string-append "/var/run/slim-" vt ".lock")))
795 (define slim.cfg
796 (mixed-text-file "slim.cfg" "
797default_path /run/current-system/profile/bin
798default_xserver " startx "
799display_name " display "
800xserver_arguments " vt "
801xauth_path " xauth "/bin/xauth
802authfile /var/run/slim-" vt ".auth
803lockfile " lockfile "
804logfile /var/log/slim-" vt ".log
805
806# The login command. '%session' is replaced by the chosen session name, one
807# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
808login_cmd exec " xinitrc " %session
809sessiondir /run/current-system/profile/share/xsessions
810session_msg session (F1 to change):
811sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
812sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
813
814halt_cmd " shepherd "/sbin/halt
815reboot_cmd " shepherd "/sbin/reboot\n"
816(if (slim-configuration-auto-login? config)
817 (string-append "auto_login yes\ndefault_user "
818 (slim-configuration-default-user config) "\n")
819 "")
820(if theme-name
821 (string-append "current_theme " theme-name "\n")
822 "")))
823
824 (define theme
825 (slim-configuration-theme config))
826
827 (list (shepherd-service
828 (documentation "Xorg display server")
829 (provision (append
830 ;; For compatibility, also provide 'xorg-server'.
831 (if (string=? vt "vt7")
832 '(xorg-server)
833 '())
834
835 (list (symbol-append 'xorg-server-
836 (string->symbol vt)))))
837 (requirement '(pam user-processes host-name udev))
838 (start
839 #~(lambda ()
840 ;; A stale lock file can prevent SLiM from starting, so remove it to
841 ;; be on the safe side.
842 (false-if-exception (delete-file lockfile))
843
844 (fork+exec-command
845 (list (string-append #$(slim-configuration-slim config)
846 "/bin/slim")
847 "-nodaemon")
848 #:environment-variables
849 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
850 #$@(if theme
851 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
852 #~())))))
853 (stop #~(make-kill-destructor))
854 (respawn? #t)))))
855
856(define slim-service-type
857 (handle-xorg-configuration slim-configuration
858 (service-type (name 'slim)
859 (extensions
860 (list (service-extension shepherd-root-service-type
861 slim-shepherd-service)
862 (service-extension pam-root-service-type
863 slim-pam-service)))
864 (default-value (slim-configuration))
865 (description
866 "Run the SLiM graphical login manager for X11."))))
867
868
869;;;
870;;; Screen lockers & co.
871;;;
872
873(define-configuration/no-serialization screen-locker-configuration
874 (name
875 string
876 "Name of the screen locker.")
877 (program
878 file-like
879 "Path to the executable for the screen locker as a G-Expression.")
880 (allow-empty-password?
881 (boolean #f)
882 "Whether to allow empty passwords.")
883 (using-pam?
884 (boolean #t)
885 "Whether to setup PAM entry.")
886 (using-setuid?
887 (boolean #t)
888 "Whether to setup program as setuid binary."))
889
890(define (screen-locker-pam-services config)
891 (match-record config <screen-locker-configuration>
892 (name allow-empty-password? using-pam?)
893 (if using-pam?
894 (list (unix-pam-service name
895 #:allow-empty-passwords?
896 allow-empty-password?))
897 '())))
898
899(define (screen-locker-privileged-programs config)
900 (match-record config <screen-locker-configuration>
901 (name program using-setuid?)
902 (if using-setuid?
903 (list (privileged-program
904 (program program)
905 (setuid? #t)))
906 '())))
907
908(define screen-locker-service-type
909 (service-type (name 'screen-locker)
910 (extensions
911 (list (service-extension pam-root-service-type
912 screen-locker-pam-services)
913 (service-extension privileged-program-service-type
914 screen-locker-privileged-programs)))
915 (description
916 "Allow the given program to be used as a screen locker for
917the graphical server by making it setuid-root, so it can authenticate users,
918and by creating a PAM service for it.")))
919
920(define (screen-locker-generate-doc)
921 (configuration->documentation 'screen-locker-configuration))
922
923(define-deprecated (screen-locker-service package
924 #:optional
925 (program (package-name package))
926 #:key allow-empty-passwords?)
927 screen-locker-service-type
928 "Add @var{package}, a package for a screen locker or screen saver whose
929command is @var{program}, to the set of setuid programs and add a PAM entry
930for it. For example:
931
932@lisp
933 (screen-locker-service xlockmore \"xlock\")
934@end lisp
935
936makes the good ol' XlockMore usable."
937 (service screen-locker-service-type
938 (screen-locker-configuration
939 (name program)
940 (program (file-append package "/bin/" program))
941 (allow-empty-password? allow-empty-passwords?))))
942
943
944;;;
945;;; Locale service.
946;;;
947
948(define-record-type* <localed-configuration>
949 localed-configuration make-localed-configuration
950 localed-configuration?
951 (localed localed-configuration-localed
952 (default localed))
953 (keyboard-layout localed-configuration-keyboard-layout
954 (default #f)))
955
956(define (localed-dbus-service config)
957 "Return the 'localed' D-Bus service for @var{config}, a
958@code{<localed-configuration>} record."
959 (define keyboard-layout
960 (localed-configuration-keyboard-layout config))
961
962 ;; The primary purpose of 'localed' is to tell GDM what the "current" Xorg
963 ;; keyboard layout is. If 'localed' is missing, or if it's unable to
964 ;; determine the current XKB layout, then GDM forcefully installs its
965 ;; default XKB config (US English). Here we communicate the configured
966 ;; layout through environment variables.
967
968 (if keyboard-layout
969 (let* ((layout (keyboard-layout-name keyboard-layout))
970 (variant (keyboard-layout-variant keyboard-layout))
971 (model (keyboard-layout-model keyboard-layout))
972 (options (keyboard-layout-options keyboard-layout)))
973 (list (wrapped-dbus-service
974 (localed-configuration-localed config)
975 "libexec/localed/localed"
976 `(("GUIX_XKB_LAYOUT" ,layout)
977 ,@(if variant
978 `(("GUIX_XKB_VARIANT" ,variant))
979 '())
980 ,@(if model
981 `(("GUIX_XKB_MODEL" ,model))
982 '())
983 ,@(if (null? options)
984 '()
985 `(("GUIX_XKB_OPTIONS"
986 ,(string-join options ","))))))))
987 '()))
988
989(define localed-service-type
990 (let ((package (lambda (config)
991 ;; Don't bother if the user didn't specify any keyboard
992 ;; layout.
993 (if (localed-configuration-keyboard-layout config)
994 (list (localed-configuration-localed config))
995 '()))))
996 (service-type (name 'localed)
997 (extensions
998 (list (service-extension dbus-root-service-type
999 localed-dbus-service)
1000 (service-extension udev-service-type package)
1001 (service-extension polkit-service-type package)
1002
1003 ;; Add 'localectl' to the profile.
1004 (service-extension profile-service-type package)))
1005
1006 ;; This service can be extended, typically by the X login
1007 ;; manager, to communicate the chosen Xorg keyboard layout.
1008 (compose (lambda (extensions)
1009 (find keyboard-layout? extensions)))
1010 (extend (lambda (config keyboard-layout)
1011 (localed-configuration
1012 (inherit config)
1013 (keyboard-layout keyboard-layout))))
1014 (description
1015 "Run the locale daemon, @command{localed}, which can be used
1016to control the system locale and keyboard mapping from user programs such as
1017the GNOME desktop environment.")
1018 (default-value (localed-configuration)))))
1019
1020
1021;;;
1022;;; Dconf.
1023;;;
1024
1025(define-maybe text-config)
1026
1027(define-configuration/no-serialization dconf-keyfile
1028 (name string
1029 "The file name of the associated keyfile, e.g. \"00-login-screen\".")
1030 (content text-config "The content of the associated keyfile."))
1031
1032(define-configuration/no-serialization dconf-profile
1033 (name string "The file name of the dconf system profile, which should match
1034the name of a user for which the profile is to be used with. To have the
1035profile used, the environment variable \"DCONF_PROFILE\" should be set to the
1036profile file, e.g.:
1037@example
1038 export DCONF_PROFILE=/etc/dconf/profile/gdm
1039@end example")
1040 (content maybe-text-config "The content of the Dconf profile. Unless
1041provided, it defaults to include the user database (\"user-db:NAME\") as well
1042as the system database (\"system-db:NAME\"), which corresponds to the
1043generated database, @file{/etc/dconf/db/NAME}.")
1044 (keyfile dconf-keyfile "The keyfile associated with the profile"))
1045
1046(define dconf-profiles?
1047 (list-of dconf-profile?))
1048
1049(define-configuration/no-serialization dconf-configuration
1050 (profiles dconf-profiles "The list of <dconf-profile> objects to populate."))
1051
1052(define (dconf-profile->profile-file profile)
1053 "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
1054 (let ((name (dconf-profile-name profile))
1055 (content (dconf-profile-content profile)))
1056 (apply mixed-text-file
1057 name
1058 (if (maybe-value-set? content)
1059 (interpose content "\n" 'suffix)
1060 (interpose (list (string-append "user-db:" name)
1061 (string-append "system-db:" name))
1062 "\n" 'suffix)))))
1063
1064(define (dconf-profile->db-keyfile profile)
1065 "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
1066 (let ((keyfile (dconf-profile-keyfile profile)))
1067 (apply mixed-text-file (dconf-keyfile-name keyfile)
1068 (interpose (dconf-keyfile-content keyfile) "\n" 'suffix))))
1069
1070(define (dconf-profile->db-keyfile-dir profile)
1071 "Wrap the keyfile in a directory, to satisfy 'dconf compile'."
1072 (let ((name (dconf-profile-name profile))
1073 (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
1074 (computed-file name
1075 #~(begin
1076 (mkdir #$output)
1077 (symlink #$(dconf-profile->db-keyfile profile)
1078 (string-append #$output "/" #$keyfile-name))))))
1079
1080(define (dconf-profile->db profile)
1081 "Compile the a <dconf-profile> object into a GVariant Database file."
1082 (let ((name (dconf-profile-name profile)))
1083 (computed-file
1084 name
1085 (with-imported-modules '((guix build utils))
1086 #~(begin
1087 (use-modules (guix build utils))
1088 (setenv "DCONF_PROFILE" #$(dconf-profile->profile-file profile))
1089 (invoke #$(file-append dconf "/bin/dconf") "compile"
1090 #$output #$(dconf-profile->db-keyfile-dir profile)))))))
1091
1092(define (dconf-profile->files profile)
1093 "Given PROFILE, a <dconf-profile> object, return a dconf directory
1094containing the associated profile, keyfile and database files to be assembled
1095under /etc."
1096 (let ((name (dconf-profile-name profile))
1097 (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
1098 (list (list (string-append "dconf/profile/" name)
1099 (dconf-profile->profile-file profile))
1100 (list (string-append "dconf/db/" name ".d/" keyfile-name)
1101 (dconf-profile->db-keyfile profile))
1102 (list (string-append "dconf/db/" name)
1103 (dconf-profile->db profile)))))
1104
1105(define dconf-service-type
1106 (service-type
1107 (name 'dconf-profile)
1108 (extensions
1109 (list (service-extension etc-service-type
1110 (lambda (dconf-profiles)
1111 (append-map dconf-profile->files
1112 dconf-profiles)))))
1113 (compose concatenate)
1114 (extend append)
1115 (default-value '())
1116 (description "Extend the @code{etc-service-type} to populate the file
1117hierarchy under @file{/etc/dconf} with the <dconf-profile> objects provided as
1118argument.")))
1119
1120
1121;;;
1122;;; GNOME Desktop Manager.
1123;;;
1124
1125(define %gdm-accounts
1126 (list (user-group (name "gdm") (system? #t))
1127 (user-account
1128 (name "gdm")
1129 (group "gdm")
1130 (supplementary-groups '("video"))
1131 (system? #t)
1132 (comment "GNOME Display Manager user")
1133 (home-directory "/var/lib/gdm")
1134 (shell (file-append shadow "/sbin/nologin")))
1135 ;; This is not needed with userdb (provided by elogind), but it acts as
1136 ;; a fallback in case userdb is not available.
1137 (user-account
1138 (name "gdm-greeter")
1139 (group "gdm")
1140 (supplementary-groups '("video"))
1141 (system? #t)
1142 (comment "GNOME Display Manager greeter 1")
1143 (home-directory "/var/lib/gdm-greeter"))))
1144
1145(define dbus-daemon-wrapper
1146 (program-file
1147 "gdm-dbus-wrapper"
1148 #~(begin
1149 (use-modules (srfi srfi-26))
1150
1151 (define system-profile
1152 "/run/current-system/profile")
1153
1154 (define user-profile
1155 (and=> (getpw (getuid))
1156 (lambda (pw)
1157 (string-append (passwd:dir pw) "/.guix-profile"))))
1158
1159 (define home-profile
1160 (and=> (getpw (getuid))
1161 (lambda (pw)
1162 (string-append (passwd:dir pw) "/.guix-home/profile"))))
1163
1164 ;; If we are able to find the user's profile, we can add it to
1165 ;; the search paths set below. We need to do this so that D-Bus
1166 ;; can start services installed by the user. This allows
1167 ;; applications that require session D-Bus services (e.g,
1168 ;; 'evolution') to work even if those services are only available
1169 ;; in the user's profile. See <https://bugs.gnu.org/35267>.
1170 (define profiles
1171 (append (if home-profile
1172 (list home-profile)
1173 '())
1174 (if user-profile
1175 (list user-profile)
1176 '())
1177 (list system-profile)))
1178
1179 (setenv "XDG_CONFIG_DIRS"
1180 (string-join (map (cut string-append <> "/etc/xdg") profiles)
1181 ":"))
1182 (setenv "XDG_DATA_DIRS"
1183 (string-join (map (cut string-append <> "/share") profiles)
1184 ":"))
1185 (apply execl (string-append #$dbus "/bin/dbus-daemon")
1186 (program-arguments)))))
1187
1188;; Wrapper script for Wayland sessions, similar to Xsession.
1189;;
1190;; See `xinitrc`. By default, it launches the specified session through a
1191;; login shell. With the default Guix configuration, this should source
1192;; /etc/profile, setting up the Guix profile environment variables. However,
1193;; gdm launches its own graphical session through the same method, so we need
1194;; to ignore this case, since `gdm` doesn't have a login shell.
1195(define gdm-wayland-session-wrapper
1196 (program-file
1197 "gdm-wayland-session-wrapper"
1198 #~((let* ((user (getpw (getuid)))
1199 (name (passwd:name user))
1200 (shell (passwd:shell user))
1201 (args (cdr (command-line))))
1202 (if (string=? name "gdm")
1203 (apply execl (cons (car args) args))
1204 (execl shell shell "--login" "-c" (string-join args)))))))
1205
1206(define-record-type* <gdm-configuration>
1207 gdm-configuration make-gdm-configuration
1208 gdm-configuration?
1209 (gdm gdm-configuration-gdm (default gdm))
1210 (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
1211 (auto-login? gdm-configuration-auto-login? (default #f))
1212 (auto-suspend? gdm-configuration-auto-suspend? (default #t))
1213 (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
1214 (debug? gdm-configuration-debug? (default #f))
1215 (default-user gdm-configuration-default-user (default #f))
1216 (gnome-shell-assets gdm-configuration-gnome-shell-assets
1217 (default (list adwaita-icon-theme font-abattis-cantarell)))
1218 (xorg-configuration gdm-configuration-xorg
1219 (default (xorg-configuration)))
1220 (x-session gdm-configuration-x-session
1221 (default (xinitrc)))
1222 (xdmcp? gdm-configuration-xdmcp?
1223 (default #f))
1224 (wayland? gdm-configuration-wayland? (default #t))
1225 (wayland-session gdm-configuration-wayland-session
1226 (default gdm-wayland-session-wrapper)))
1227
1228(define (gdm-dconf-profiles config)
1229 (if (gdm-configuration-auto-suspend? config)
1230 '()
1231 ;; This custom gconf profile works around a lack of configuration option
1232 ;; to disable auto-suspend when no users are physically logged in (see:
1233 ;; https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/22).
1234 (list (dconf-profile
1235 (name "gdm")
1236 (content (list #~(begin
1237 (use-modules (ice-9 textual-ports))
1238 (string-trim
1239 (call-with-input-file
1240 #$(file-append gdm "/share/dconf/profile/gdm")
1241 get-string-all)))
1242 "system-db:gdm"))
1243 (keyfile (dconf-keyfile
1244 (name "00-disable-suspend")
1245 (content
1246 (list "[org/gnome/settings-daemon/plugins/power]"
1247 "sleep-inactive-ac-type='nothing'"
1248 "sleep-inactive-battery-type='nothing'"
1249 "sleep-inactive-ac-timeout=0"
1250 "sleep-inactive-battery-timeout=0"))))))))
1251
1252(define (gdm-configuration-file config)
1253 (mixed-text-file "gdm-custom.conf"
1254 "[daemon]\n"
1255 "#User=gdm\n"
1256 "#Group=gdm\n"
1257 (if (gdm-configuration-auto-login? config)
1258 (string-append
1259 "AutomaticLoginEnable=true\n"
1260 "AutomaticLogin="
1261 (or (gdm-configuration-default-user config)
1262 (error "missing default user for auto-login"))
1263 "\n")
1264 (string-append
1265 "AutomaticLoginEnable=false\n"
1266 "#AutomaticLogin=\n"))
1267 "#TimedLoginEnable=false\n"
1268 "#TimedLogin=\n"
1269 "#TimedLoginDelay=0\n"
1270 ;; Disable initial system setup inside GDM.
1271 ;; Whatever settings are set there should already be
1272 ;; taken care of through `guix system'.
1273 ;; See also
1274 ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=39281>.
1275 "InitialSetupEnable=false\n"
1276 (format #f "WaylandEnable=~:[false~;true~]~%"
1277 (gdm-configuration-wayland? config))
1278 "\n"
1279 "[debug]\n"
1280 (format #f "Enable=~:[false~;true~]~%"
1281 (gdm-configuration-debug? config))
1282 "\n"
1283 "[security]\n"
1284 "#DisallowTCP=true\n"
1285 "#AllowRemoteAutoLogin=false\n"
1286 "\n"
1287 "[xdmcp]\n"
1288 (format #f "Enable=~:[false~;true~]~%"
1289 (gdm-configuration-xdmcp? config))))
1290
1291(define (gdm-pam-service config)
1292 "Return a PAM service for @command{gdm}."
1293 (list
1294 (pam-service
1295 (inherit (unix-pam-service "gdm-autologin"
1296 #:login-uid? #t))
1297 (auth (list (pam-entry
1298 (control "optional")
1299 (module (file-append (gdm-configuration-gdm config)
1300 "/lib/security/pam_gdm.so")))
1301 (pam-entry
1302 (control "sufficient")
1303 (module "pam_permit.so")))))
1304 (pam-service
1305 (inherit (unix-pam-service "gdm-launch-environment"))
1306 (auth (list (pam-entry
1307 (control "required")
1308 (module "pam_permit.so")))))
1309 (unix-pam-service "gdm-password"
1310 #:login-uid? #t
1311 #:allow-empty-passwords?
1312 (gdm-configuration-allow-empty-passwords? config))))
1313
1314(define (gdm-shepherd-service config)
1315 (define config-file
1316 (gdm-configuration-file config))
1317
1318 (list (shepherd-service
1319 (documentation "Xorg display server (GDM)")
1320 (provision '(xorg-server))
1321 (requirement '(dbus-system pam user-processes host-name udev elogind))
1322 (start #~(make-forkexec-constructor
1323 '(#$(file-append (gdm-configuration-gdm config) "/bin/gdm"))
1324 #:environment-variables
1325 (list #$@(if (gdm-configuration-auto-suspend? config)
1326 #~()
1327 #~("DCONF_PROFILE=/etc/dconf/profile/gdm"))
1328 (string-append "GDM_CUSTOM_CONF=" #$config-file)
1329 (string-append
1330 "GDM_DBUS_DAEMON="
1331 #$(gdm-configuration-dbus-daemon config))
1332 (string-append
1333 "GDM_X_SERVER="
1334 #$(xorg-wrapper
1335 (gdm-configuration-xorg config)))
1336 (string-append
1337 "GDM_X_SESSION="
1338 #$(gdm-configuration-x-session config))
1339 (string-append
1340 "XDG_DATA_DIRS="
1341 ((lambda (ls) (string-join ls ":"))
1342 (map (lambda (path)
1343 (string-append path "/share"))
1344 ;; NOTE: Add system profile here so that we can
1345 ;; use fonts installed in it.
1346 ;; XXX: Remove gnome-shell below when GDM
1347 ;; can depend on GNOME Shell directly.
1348 (cons* "/run/current-system/profile"
1349 #$gnome-shell
1350 '#$(gdm-configuration-gnome-shell-assets
1351 config)))))
1352 ;; Add XCURSOR_PATH so that mutter can find its
1353 ;; cursors. gdm doesn't login so doesn't source
1354 ;; the corresponding line in /etc/profile.
1355 "XCURSOR_PATH=/run/current-system/profile/share/icons"
1356 (string-append
1357 "GUIX_GDK_PIXBUF_MODULE_FILES="
1358 #$gnome-shell "/" #$%gdk-pixbuf-loaders-cache-file)
1359 (string-append
1360 "GDM_WAYLAND_SESSION="
1361 #$(gdm-configuration-wayland-session config)))))
1362 (stop #~(make-kill-destructor))
1363 (actions (list (shepherd-configuration-action config-file)))
1364 (respawn? #t))))
1365
1366(define gdm-polkit-rules
1367 (lambda (config)
1368 (if (gdm-configuration-xdmcp? config)
1369 ;; Allow remote (XDMCP) users to use colord; otherwise an
1370 ;; authentication dialog would appear on the GDM screen (see the
1371 ;; upstream bug:
1372 ;; https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/273).
1373 (list (computed-file
1374 "02-allow-colord.rules"
1375 (with-imported-modules '((guix build utils))
1376 #~(begin
1377 (use-modules (guix build utils))
1378
1379 (let* ((rules.d
1380 (string-append #$output
1381 "/share/polkit-1"
1382 "/rules.d"))
1383 (allow-colord.rules (string-append
1384 rules.d
1385 "/02-allow-colord.rules")))
1386 (mkdir-p rules.d)
1387 (call-with-output-file allow-colord.rules
1388 (lambda (port)
1389 ;; This workaround enables any local or remote in
1390 ;; the "users" group to use colord (see:
1391 ;; https://c-nergy.be/blog/?p=12073).
1392 (format port "\
1393polkit.addRule(function(action, subject) {
1394 if (action.id.match(\"org.freedesktop.color-manager\")) {
1395 polkit.log(\"POLKIT DEBUG returning YES for action: \" + action);
1396 return polkit.Result.YES;
1397 }
1398});~%"))))))))
1399 '())))
1400
1401(define gdm-service-type
1402 (handle-xorg-configuration gdm-configuration
1403 (service-type (name 'gdm)
1404 (extensions
1405 (list (service-extension shepherd-root-service-type
1406 gdm-shepherd-service)
1407 (service-extension account-service-type
1408 (const %gdm-accounts))
1409 (service-extension dconf-service-type
1410 gdm-dconf-profiles)
1411 (service-extension pam-root-service-type
1412 gdm-pam-service)
1413 (service-extension polkit-service-type
1414 gdm-polkit-rules)
1415 (service-extension profile-service-type
1416 gdm-configuration-gnome-shell-assets)
1417 (service-extension dbus-root-service-type
1418 (compose list
1419 gdm-configuration-gdm))
1420 (service-extension localed-service-type
1421 (compose
1422 xorg-configuration-keyboard-layout
1423 gdm-configuration-xorg))))
1424 (default-value (gdm-configuration))
1425 (description
1426 "Run the GNOME Desktop Manager (GDM), a program that allows
1427you to log in in a graphical session, whether or not you use GNOME."))))
1428
1429
1430;; FIXME: Since GDM depends on more dependencies that do not build on i686,
1431;; keep SDDM on it for the time being.
1432;; XXX: When changing this, also change desktop-services-for-system
1433(define* (set-xorg-configuration config
1434 #:optional
1435 (login-manager-service-type
1436 (if (target-64bit?)
1437 gdm-service-type
1438 sddm-service-type)))
1439 "Tell the log-in manager (of type @var{login-manager-service-type}) to use
1440@var{config}, an <xorg-configuration> record."
1441 (simple-service 'set-xorg-configuration
1442 login-manager-service-type
1443 config))
1444
1445;;; xorg.scm ends here