1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Andy Wingo <wingo@igalia.com>
3 ;;; Copyright © 2013-2017, 2019-2020, 2022 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 ;;; Copyright © 2020 shtwzrd <shtwzrd@protonmail.com>
9 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
10 ;;; Copyright © 2020 Alex Griffin <a@ajgrf.com>
11 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
12 ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
13 ;;; Copyright © 2021 Josselin Poiret <josselin.poiret@protonmail.ch>
14 ;;; Copyright © 2022 Chris Marusich <cmmarusich@gmail.com>
15 ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
17 ;;; This file is part of GNU Guix.
19 ;;; GNU Guix is free software; you can redistribute it and/or modify it
20 ;;; under the terms of the GNU General Public License as published by
21 ;;; the Free Software Foundation; either version 3 of the License, or (at
22 ;;; your option) any later version.
24 ;;; GNU Guix is distributed in the hope that it will be useful, but
25 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;;; GNU General Public License for more details.
29 ;;; You should have received a copy of the GNU General Public License
30 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
32 (define-module (gnu services xorg)
33 #:autoload (gnu services sddm) (sddm-service-type)
34 #:use-module (gnu artwork)
35 #:use-module (gnu services)
36 #:use-module (gnu services configuration)
37 #:use-module (gnu services shepherd)
38 #:use-module (gnu system pam)
39 #:use-module (gnu system setuid)
40 #:use-module (gnu system keyboard)
41 #:use-module (gnu services base)
42 #:use-module (gnu services dbus)
43 #:use-module (gnu packages base)
44 #:use-module (gnu packages guile)
45 #:use-module (gnu packages xorg)
46 #:use-module (gnu packages fonts)
47 #:use-module (gnu packages gl)
48 #:use-module (gnu packages glib)
49 #:use-module (gnu packages display-managers)
50 #:use-module (gnu packages freedesktop)
51 #:use-module (gnu packages gnustep)
52 #:use-module (gnu packages gnome)
53 #:use-module (gnu packages admin)
54 #:use-module (gnu packages bash)
55 #:use-module (gnu system shadow)
56 #:use-module (guix build-system glib-or-gtk)
57 #:use-module (guix build-system trivial)
58 #:use-module (guix gexp)
59 #:use-module (guix store)
60 #:use-module (guix packages)
61 #:use-module (guix derivations)
62 #:use-module (guix records)
63 #:use-module (guix deprecation)
64 #:use-module (guix utils)
65 #:use-module (srfi srfi-1)
66 #:use-module (srfi srfi-9)
67 #:use-module (srfi srfi-26)
68 #:use-module (ice-9 format)
69 #:use-module (ice-9 match)
70 #:export (xorg-configuration
72 xorg-configuration-modules
73 xorg-configuration-fonts
74 xorg-configuration-drivers
75 xorg-configuration-resolutions
76 xorg-configuration-extra-config
77 xorg-configuration-server
78 xorg-configuration-server-arguments
82 %default-xorg-server-arguments
87 xorg-server-service-type
90 %default-slim-theme-name
94 slim-configuration-slim
95 slim-configuration-allow-empty-passwords?
96 slim-configuration-auto-login?
97 slim-configuration-default-user
98 slim-configuration-theme
99 slim-configuration-theme-name
100 slim-configuration-xauth
101 slim-configuration-shepherd
102 slim-configuration-auto-login-session
103 slim-configuration-xorg
104 slim-configuration-display
105 slim-configuration-vt
106 slim-configuration-sessreg
112 screen-locker-service-type
113 screen-locker-service
115 localed-configuration
116 localed-configuration?
122 dconf-profile-content
123 dconf-profile-keyfile
129 handle-xorg-configuration
130 set-xorg-configuration))
134 ;;; Services that relate to the X Window System.
138 (define %default-xorg-modules
139 ;; Default list of modules loaded by the server. When multiple drivers
140 ;; match, the first one in the list is loaded.
141 (list xf86-video-vesa
152 ;; Libinput is the new thing and is recommended over evdev/synaptics:
153 ;; <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
160 (define %default-xorg-fonts
161 ;; Default list of fonts available to the X server.
162 (list (file-append font-alias "/share/fonts/X11/75dpi")
163 (file-append font-alias "/share/fonts/X11/100dpi")
164 (file-append font-alias "/share/fonts/X11/misc")
165 (file-append font-alias "/share/fonts/X11/cyrillic")
166 (file-append font-misc-misc ;default fonts for xterm
167 "/share/fonts/X11/misc")
168 (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
170 (define %default-xorg-server-arguments
171 ;; Default command-line arguments for X.
172 '("-nolisten" "tcp"))
174 ;; Configuration of an Xorg server.
175 (define-record-type* <xorg-configuration>
176 xorg-configuration make-xorg-configuration
178 (modules xorg-configuration-modules ;list of file-like
180 ; filter out modules not supported on current system
183 (member (%current-system)
184 (package-supported-systems p)))
185 %default-xorg-modules)))
186 (fonts xorg-configuration-fonts ;list of packges
187 (default %default-xorg-fonts))
188 (drivers xorg-configuration-drivers ;list of strings
190 (resolutions xorg-configuration-resolutions ;list of tuples
192 (keyboard-layout xorg-configuration-keyboard-layout ;#f | <keyboard-layout>
194 (extra-config xorg-configuration-extra-config ;list of strings
196 (server xorg-configuration-server ;file-like
197 (default xorg-server))
198 (server-arguments xorg-configuration-server-arguments ;list of strings
199 (default %default-xorg-server-arguments)))
201 (define (xorg-configuration->file config)
202 "Compute an Xorg configuration file corresponding to CONFIG, an
203 <xorg-configuration> record."
204 (let ((xorg-server (xorg-configuration-server config)))
206 ;; 'xorg-server' provides 'fbdevhw.so' etc.
207 (append (xorg-configuration-modules config)
212 (use-modules (ice-9 match)
216 (call-with-output-file #$output
219 '#$(xorg-configuration-drivers config))
221 (define (device-section driver)
224 Identifier \"device-" driver "\"
225 Driver \"" driver "\"
228 (define (screen-section driver resolutions)
231 Identifier \"screen-" driver "\"
232 Device \"device-" driver "\"
233 SubSection \"Display\"
235 (string-join (map (match-lambda
237 (string-append "\"" (number->string x)
238 "x" (number->string y) "\"")))
243 (define (input-class-section layout variant model options)
245 Section \"InputClass\"
246 Identifier \"evdev keyboard catchall\"
247 MatchIsKeyboard \"on\"
248 Option \"XkbLayout\" " (object->string layout)
250 (string-append " Option \"XkbVariant\" \""
254 (string-append " Option \"XkbModel\" \""
261 (string-append " Option \"XkbOptions\" \""
262 (string-join options ",") "\""))) "
264 MatchDevicePath \"/dev/input/event*\"
268 (define (expand modules)
269 ;; Append to MODULES the relevant /lib/xorg/modules
271 (append-map (lambda (module)
272 (filter-map (lambda (directory)
273 (let ((full (string-append module
275 (and (file-exists? full)
277 '("/lib/xorg/modules/drivers"
278 "/lib/xorg/modules/input"
279 "/lib/xorg/modules/multimedia"
280 "/lib/xorg/modules/extensions")))
283 (display "Section \"Files\"\n" port)
284 (for-each (lambda (font)
285 (format port " FontPath \"~a\"~%" font))
286 '#$(xorg-configuration-fonts config))
287 (for-each (lambda (module)
289 " ModulePath \"~a\"~%"
291 (append (expand '#$all-modules)
293 ;; For fbdevhw.so and so on.
294 (list #$(file-append xorg-server
295 "/lib/xorg/modules"))))
296 (display "EndSection\n" port)
298 Section \"ServerFlags\"
299 Option \"AllowMouseOpenFail\" \"on\"
302 (display (string-join (map device-section drivers) "\n")
305 (display (string-join
306 (map (cut screen-section <>
307 '#$(xorg-configuration-resolutions config))
313 (let ((layout #$(and=> (xorg-configuration-keyboard-layout config)
314 keyboard-layout-name))
315 (variant #$(and=> (xorg-configuration-keyboard-layout config)
316 keyboard-layout-variant))
317 (model #$(and=> (xorg-configuration-keyboard-layout config)
318 keyboard-layout-model))
319 (options '#$(and=> (xorg-configuration-keyboard-layout config)
320 keyboard-layout-options)))
322 (display (input-class-section layout variant model options)
326 (for-each (lambda (config)
327 (display config port))
328 '#$(xorg-configuration-extra-config config))))))
330 (computed-file "xserver.conf" build)))
332 (define (xorg-configuration-directory modules)
333 "Return a directory that contains the @code{.conf} files for X.org that
334 includes the @code{share/X11/xorg.conf.d} directories of each package listed
336 (with-imported-modules '((guix build utils))
337 (computed-file "xorg.conf.d"
339 (use-modules (guix build utils)
343 (append-map (lambda (module)
344 (find-files (string-append
346 "/share/X11/xorg.conf.d")
351 (for-each (lambda (file)
353 (string-append #$output "/"
358 (define* (xorg-wrapper #:optional (config (xorg-configuration)))
359 "Return a derivation that builds a script to start the X server with the
360 given @var{config}. The resulting script should be used in place of
363 ;; Write a small wrapper around the X server.
365 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
366 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
368 (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
370 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
371 "-config" #$(xorg-configuration->file config)
372 "-configdir" #$(xorg-configuration-directory
373 (xorg-configuration-modules config))
374 (cdr (command-line))))))
376 (program-file "X-wrapper" exp))
378 (define* (xorg-start-command #:optional (config (xorg-configuration)))
379 "Return a @code{startx} script in which the modules, fonts, etc. specified
380 in @var{config}, are available. The result should be used in place of
383 (xorg-wrapper config))
386 ;; Write a small wrapper around the X server.
387 #~(apply execl #$X #$X ;; Second #$X is for argv[0].
388 "-logverbose" "-verbose" "-terminate"
389 #$@(xorg-configuration-server-arguments config)
390 (cdr (command-line))))
392 (program-file "startx" exp))
394 (define* (xinitrc #:key fallback-session)
395 "Return a system-wide xinitrc script that starts the specified X session,
396 which should be passed to this script as the first argument. If not, the
397 @var{fallback-session} will be used or, if @var{fallback-session} is false, a
398 desktop session from the system or user profile will be used."
401 (use-modules (ice-9 match)
408 (define (close-all-fdes)
409 ;; Close all the open file descriptors except 0 to 2.
411 (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
412 (false-if-exception (close-fdes fd))
415 (define (exec-from-login-shell command . args)
416 ;; Run COMMAND from a login shell so that it gets to see the same
417 ;; environment variables that one gets when logging in on a tty, for
419 (let* ((pw (getpw (getuid)))
420 (shell (passwd:shell pw)))
421 ;; Close any open file descriptors. This is all the more
422 ;; important that SLiM itself exec's us directly without closing
423 ;; its own file descriptors!
426 ;; The '--login' option is supported at least by Bash and zsh.
427 (execl shell shell "--login" "-c"
428 (string-join (cons command args)))))
430 (define system-profile
431 "/run/current-system/profile")
434 (and=> (getpw (getuid))
436 (string-append (passwd:dir pw) "/.guix-profile"))))
438 (define (xsession-command desktop-file)
439 ;; Read from DESKTOP-FILE its X session command and return it as a
442 (make-regexp "^[[:blank:]]*Exec=(.*)$"))
444 (call-with-input-file desktop-file
447 (match (read-line port)
449 ((= (cut regexp-exec exec-regexp <>) result)
451 (string-tokenize (match:substring result 1))
454 (define (find-session profile)
455 ;; Return an X session command from PROFILE or #f if none was found.
456 (let ((directory (string-append profile "/share/xsessions")))
457 (match (scandir directory
458 (cut string-suffix? ".desktop" <>))
462 (any xsession-command
463 (map (cut string-append directory "/" <>)
466 (let* ((home (getenv "HOME"))
467 (xsession-file (string-append home "/.xsession"))
468 (session (match (command-line)
470 #$(if fallback-session
471 #~(list #$fallback-session)
475 (if (file-exists? xsession-file)
476 ;; Run ~/.xsession when it exists.
477 (apply exec-from-login-shell xsession-file
479 ;; Otherwise, start the specified session or a fallback.
480 (apply exec-from-login-shell
482 (find-session user-profile)
483 (find-session system-profile)))))))
485 (program-file "xinitrc" builder))
487 (define-syntax handle-xorg-configuration
489 "Generate the `compose' and `extend' entries of a login manager
490 `service-type' to handle specifying the `xorg-configuration' through
491 a `service-extension', as used by `set-xorg-configuration'."
492 ((_ configuration-record service-type-definition)
494 (inherit service-type-definition)
495 (compose (lambda (extensions)
498 ((config . _) config))))
499 (extend (lambda (config xorg-configuration)
500 (if xorg-configuration
501 (configuration-record
503 (xorg-configuration xorg-configuration))
506 (define (xorg-server-profile-service config)
507 ;; XXX: profile-service-type only accepts <package> objects.
510 (name "xorg-wrapper")
511 (version (package-version xorg-server))
512 (source (xorg-wrapper config))
513 (build-system trivial-build-system)
515 '(#:modules ((guix build utils))
518 (use-modules (guix build utils))
519 (let* ((source (assoc-ref %build-inputs "source"))
520 (out (assoc-ref %outputs "out"))
521 (bin (string-append out "/bin")))
523 (symlink source (string-append bin "/X"))
524 (symlink source (string-append bin "/Xorg"))
526 (home-page (package-home-page xorg-server))
527 (synopsis (package-synopsis xorg-server))
528 (description (package-description xorg-server))
529 (license (package-license xorg-server)))))
531 (define xorg-server-service-type
535 (list (service-extension profile-service-type
536 xorg-server-profile-service)))
537 (default-value (xorg-configuration))
538 (description "Add @command{X} to the system profile, to be used with
539 @command{sx} or @command{xinit}.")))
543 ;;; SLiM log-in manager.
546 (define %default-slim-theme
547 ;; Theme based on work by Felipe López.
548 (file-append %artwork-repository "/slim"))
550 (define %default-slim-theme-name
551 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
552 ;; contains the actual theme files.
555 (define-record-type* <slim-configuration>
556 slim-configuration make-slim-configuration
558 (slim slim-configuration-slim
560 (allow-empty-passwords? slim-configuration-allow-empty-passwords?
562 (gnupg? slim-configuration-gnupg?
564 (auto-login? slim-configuration-auto-login?
566 (default-user slim-configuration-default-user
568 (theme slim-configuration-theme
569 (default %default-slim-theme))
570 (theme-name slim-configuration-theme-name
571 (default %default-slim-theme-name))
572 (xauth slim-configuration-xauth
574 (shepherd slim-configuration-shepherd
576 (auto-login-session slim-configuration-auto-login-session
578 (xorg-configuration slim-configuration-xorg
579 (default (xorg-configuration)))
580 (display slim-configuration-display
582 (vt slim-configuration-vt
584 (sessreg slim-configuration-sessreg
587 (define (slim-pam-service config)
588 "Return a PAM service for @command{slim}."
589 (list (unix-pam-service
592 #:allow-empty-passwords?
593 (slim-configuration-allow-empty-passwords? config)
595 (slim-configuration-gnupg? config))))
597 (define (slim-shepherd-service config)
598 (let* ((xinitrc (xinitrc #:fallback-session
599 (slim-configuration-auto-login-session config)))
600 (xauth (slim-configuration-xauth config))
601 (startx (xorg-start-command (slim-configuration-xorg config)))
602 (display (slim-configuration-display config))
603 (vt (slim-configuration-vt config))
604 (shepherd (slim-configuration-shepherd config))
605 (theme-name (slim-configuration-theme-name config))
606 (sessreg (slim-configuration-sessreg config))
607 (lockfile (string-append "/var/run/slim-" vt ".lock")))
609 (mixed-text-file "slim.cfg" "
610 default_path /run/current-system/profile/bin
611 default_xserver " startx "
612 display_name " display "
613 xserver_arguments " vt "
614 xauth_path " xauth "/bin/xauth
615 authfile /var/run/slim-" vt ".auth
616 lockfile " lockfile "
617 logfile /var/log/slim-" vt ".log
619 # The login command. '%session' is replaced by the chosen session name, one
620 # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
621 login_cmd exec " xinitrc " %session
622 sessiondir /run/current-system/profile/share/xsessions
623 session_msg session (F1 to change):
624 sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
625 sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
627 halt_cmd " shepherd "/sbin/halt
628 reboot_cmd " shepherd "/sbin/reboot\n"
629 (if (slim-configuration-auto-login? config)
630 (string-append "auto_login yes\ndefault_user "
631 (slim-configuration-default-user config) "\n")
634 (string-append "current_theme " theme-name "\n")
638 (slim-configuration-theme config))
640 (list (shepherd-service
641 (documentation "Xorg display server")
643 ;; For compatibility, also provide 'xorg-server'.
644 (if (string=? vt "vt7")
648 (list (symbol-append 'xorg-server-
649 (string->symbol vt)))))
650 (requirement '(user-processes host-name udev))
653 ;; A stale lock file can prevent SLiM from starting, so remove it to
654 ;; be on the safe side.
655 (false-if-exception (delete-file lockfile))
658 (list (string-append #$(slim-configuration-slim config)
661 #:environment-variables
662 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
664 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
666 (stop #~(make-kill-destructor))
669 (define slim-service-type
670 (handle-xorg-configuration slim-configuration
671 (service-type (name 'slim)
673 (list (service-extension shepherd-root-service-type
674 slim-shepherd-service)
675 (service-extension pam-root-service-type
677 (default-value (slim-configuration))
679 "Run the SLiM graphical login manager for X11."))))
683 ;;; Screen lockers & co.
686 (define-record-type <screen-locker>
687 (screen-locker name program empty?)
689 (name screen-locker-name) ;string
690 (program screen-locker-program) ;gexp
691 (empty? screen-locker-allows-empty-passwords?)) ;Boolean
693 (define screen-locker-pam-services
695 (($ <screen-locker> name _ empty?)
696 (list (unix-pam-service name
697 #:allow-empty-passwords? empty?)))))
699 (define screen-locker-setuid-programs
700 (compose list file-like->setuid-program screen-locker-program))
702 (define screen-locker-service-type
703 (service-type (name 'screen-locker)
705 (list (service-extension pam-root-service-type
706 screen-locker-pam-services)
707 (service-extension setuid-program-service-type
708 screen-locker-setuid-programs)))
710 "Allow the given program to be used as a screen locker for
711 the graphical server by making it setuid-root, so it can authenticate users,
712 and by creating a PAM service for it.")))
714 (define* (screen-locker-service package
716 (program (package-name package))
717 #:key allow-empty-passwords?)
718 "Add @var{package}, a package for a screen locker or screen saver whose
719 command is @var{program}, to the set of setuid programs and add a PAM entry
723 (screen-locker-service xlockmore \"xlock\")
726 makes the good ol' XlockMore usable."
727 (service screen-locker-service-type
728 (screen-locker program
729 (file-append package "/bin/" program)
730 allow-empty-passwords?)))
737 (define-record-type* <localed-configuration>
738 localed-configuration make-localed-configuration
739 localed-configuration?
740 (localed localed-configuration-localed
742 (keyboard-layout localed-configuration-keyboard-layout
745 (define (localed-dbus-service config)
746 "Return the 'localed' D-Bus service for @var{config}, a
747 @code{<localed-configuration>} record."
748 (define keyboard-layout
749 (localed-configuration-keyboard-layout config))
751 ;; The primary purpose of 'localed' is to tell GDM what the "current" Xorg
752 ;; keyboard layout is. If 'localed' is missing, or if it's unable to
753 ;; determine the current XKB layout, then GDM forcefully installs its
754 ;; default XKB config (US English). Here we communicate the configured
755 ;; layout through environment variables.
758 (let* ((layout (keyboard-layout-name keyboard-layout))
759 (variant (keyboard-layout-variant keyboard-layout))
760 (model (keyboard-layout-model keyboard-layout))
761 (options (keyboard-layout-options keyboard-layout)))
762 (list (wrapped-dbus-service
763 (localed-configuration-localed config)
764 "libexec/localed/localed"
765 `(("GUIX_XKB_LAYOUT" ,layout)
767 `(("GUIX_XKB_VARIANT" ,variant))
770 `(("GUIX_XKB_MODEL" ,model))
772 ,@(if (null? options)
774 `(("GUIX_XKB_OPTIONS"
775 ,(string-join options ","))))))))
778 (define localed-service-type
779 (let ((package (lambda (config)
780 ;; Don't bother if the user didn't specify any keyboard
782 (if (localed-configuration-keyboard-layout config)
783 (list (localed-configuration-localed config))
785 (service-type (name 'localed)
787 (list (service-extension dbus-root-service-type
788 localed-dbus-service)
789 (service-extension udev-service-type package)
790 (service-extension polkit-service-type package)
792 ;; Add 'localectl' to the profile.
793 (service-extension profile-service-type package)))
795 ;; This service can be extended, typically by the X login
796 ;; manager, to communicate the chosen Xorg keyboard layout.
797 (compose (lambda (extensions)
798 (find keyboard-layout? extensions)))
799 (extend (lambda (config keyboard-layout)
800 (localed-configuration
802 (keyboard-layout keyboard-layout))))
804 "Run the locale daemon, @command{localed}, which can be used
805 to control the system locale and keyboard mapping from user programs such as
806 the GNOME desktop environment.")
807 (default-value (localed-configuration)))))
814 (define-maybe text-config)
816 (define-configuration/no-serialization dconf-keyfile
818 "The file name of the associated keyfile, e.g. \"00-login-screen\".")
819 (content text-config "The content of the associated keyfile."))
821 (define-configuration/no-serialization dconf-profile
822 (name string "The file name of the dconf system profile, which should match
823 the name of a user for which the profile is to be used with. To have the
824 profile used, the environment variable \"DCONF_PROFILE\" should be set to the
827 export DCONF_PROFILE=/etc/dconf/profile/gdm
829 (content maybe-text-config "The content of the Dconf profile. Unless
830 provided, it defaults to include the user database (\"user-db:NAME\") as well
831 as the system database (\"system-db:NAME\"), which corresponds to the
832 generated database, @file{/etc/dconf/db/NAME}.")
833 (keyfile dconf-keyfile "The keyfile associated with the profile"))
835 (define dconf-profiles?
836 (list-of dconf-profile?))
838 (define-configuration/no-serialization dconf-configuration
839 (profiles dconf-profiles "The list of <dconf-profile> objects to populate."))
841 (define (dconf-profile->profile-file profile)
842 "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
843 (let ((name (dconf-profile-name profile))
844 (content (dconf-profile-content profile)))
845 (apply mixed-text-file
847 (if (maybe-value-set? content)
848 (interpose content "\n" 'suffix)
849 (interpose (list (string-append "user-db:" name)
850 (string-append "system-db:" name))
853 (define (dconf-profile->db-keyfile profile)
854 "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
855 (let ((keyfile (dconf-profile-keyfile profile)))
856 (apply mixed-text-file (dconf-keyfile-name keyfile)
857 (interpose (dconf-keyfile-content keyfile) "\n" 'suffix))))
859 (define (dconf-profile->db-keyfile-dir profile)
860 "Wrap the keyfile in a directory, to satisfy 'dconf compile'."
861 (let ((name (dconf-profile-name profile))
862 (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
866 (symlink #$(dconf-profile->db-keyfile profile)
867 (string-append #$output "/" #$keyfile-name))))))
869 (define (dconf-profile->db profile)
870 "Compile the a <dconf-profile> object into a GVariant Database file."
871 (let ((name (dconf-profile-name profile)))
874 (with-imported-modules '((guix build utils))
876 (use-modules (guix build utils))
877 (setenv "DCONF_PROFILE" #$(dconf-profile->profile-file profile))
878 (invoke #$(file-append dconf "/bin/dconf") "compile"
879 #$output #$(dconf-profile->db-keyfile-dir profile)))))))
881 (define (dconf-profile->files profile)
882 "Given PROFILE, a <dconf-profile> object, return a dconf directory
883 containing the associated profile, keyfile and database files to be assembled
885 (let ((name (dconf-profile-name profile))
886 (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
887 (list (list (string-append "dconf/profile/" name)
888 (dconf-profile->profile-file profile))
889 (list (string-append "dconf/db/" name ".d/" keyfile-name)
890 (dconf-profile->db-keyfile profile))
891 (list (string-append "dconf/db/" name)
892 (dconf-profile->db profile)))))
894 (define dconf-service-type
896 (name 'dconf-profile)
898 (list (service-extension etc-service-type
899 (lambda (dconf-profiles)
900 (append-map dconf-profile->files
902 (compose concatenate)
905 (description "Extend the @code{etc-service-type} to populate the file
906 hierarchy under @file{/etc/dconf} with the <dconf-profile> objects provided as
911 ;;; GNOME Desktop Manager.
914 (define %gdm-accounts
915 (list (user-group (name "gdm") (system? #t))
919 (supplementary-groups '("video"))
921 (comment "GNOME Display Manager user")
922 (home-directory "/var/lib/gdm")
923 (shell (file-append shadow "/sbin/nologin")))))
925 (define dbus-daemon-wrapper
929 (use-modules (srfi srfi-26))
931 (define system-profile
932 "/run/current-system/profile")
935 (and=> (getpw (getuid))
937 (string-append (passwd:dir pw) "/.guix-profile"))))
939 ;; If we are able to find the user's profile, we can add it to
940 ;; the search paths set below. We need to do this so that D-Bus
941 ;; can start services installed by the user. This allows
942 ;; applications that require session D-Bus services (e.g,
943 ;; 'evolution') to work even if those services are only available
944 ;; in the user's profile. See <https://bugs.gnu.org/35267>.
947 (list user-profile system-profile)
948 (list system-profile)))
950 (setenv "XDG_CONFIG_DIRS"
951 (string-join (map (cut string-append <> "/etc/xdg") profiles)
953 (setenv "XDG_DATA_DIRS"
954 (string-join (map (cut string-append <> "/share") profiles)
956 (apply execl (string-append #$dbus "/bin/dbus-daemon")
957 (program-arguments)))))
959 ;; Wrapper script for Wayland sessions, similar to Xsession.
961 ;; See `xinitrc`. By default, it launches the specified session through a
962 ;; login shell. With the default Guix configuration, this should source
963 ;; /etc/profile, setting up the Guix profile environment variables. However,
964 ;; gdm launches its own graphical session through the same method, so we need
965 ;; to ignore this case, since `gdm` doesn't have a login shell.
966 (define gdm-wayland-session-wrapper
968 "gdm-wayland-session-wrapper"
969 #~((let* ((user (getpw (getuid)))
970 (name (passwd:name user))
971 (shell (passwd:shell user))
972 (args (cdr (command-line))))
973 (if (string=? name "gdm")
974 (apply execl (cons (car args) args))
975 (execl shell shell "--login" "-c" (string-join args)))))))
977 (define-record-type* <gdm-configuration>
978 gdm-configuration make-gdm-configuration
980 (gdm gdm-configuration-gdm (default gdm))
981 (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
982 (auto-login? gdm-configuration-auto-login? (default #f))
983 (auto-suspend? gdm-configuration-auto-suspend? (default #t))
984 (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
985 (debug? gdm-configuration-debug? (default #f))
986 (default-user gdm-configuration-default-user (default #f))
987 (gnome-shell-assets gdm-configuration-gnome-shell-assets
988 (default (list adwaita-icon-theme font-abattis-cantarell)))
989 (xorg-configuration gdm-configuration-xorg
990 (default (xorg-configuration)))
991 (x-session gdm-configuration-x-session
993 (xdmcp? gdm-configuration-xdmcp?
995 (wayland? gdm-configuration-wayland? (default #f))
996 (wayland-session gdm-configuration-wayland-session
997 (default gdm-wayland-session-wrapper)))
999 (define (gdm-dconf-profiles config)
1000 (if (gdm-configuration-auto-suspend? config)
1002 ;; This custom gconf profile works around a lack of configuration option
1003 ;; to disable auto-suspend when no users are physically logged in (see:
1004 ;; https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/22).
1005 (list (dconf-profile
1007 (content (list #~(begin
1008 (use-modules (ice-9 textual-ports))
1010 (call-with-input-file
1011 #$(file-append gdm "/share/dconf/profile/gdm")
1014 (keyfile (dconf-keyfile
1015 (name "00-disable-suspend")
1017 (list "[org/gnome/settings-daemon/plugins/power]"
1018 "sleep-inactive-ac-type='nothing'"
1019 "sleep-inactive-battery-type='nothing'"
1020 "sleep-inactive-ac-timeout=0"
1021 "sleep-inactive-battery-timeout=0"))))))))
1023 (define (gdm-configuration-file config)
1024 (mixed-text-file "gdm-custom.conf"
1028 (if (gdm-configuration-auto-login? config)
1030 "AutomaticLoginEnable=true\n"
1032 (or (gdm-configuration-default-user config)
1033 (error "missing default user for auto-login"))
1036 "AutomaticLoginEnable=false\n"
1037 "#AutomaticLogin=\n"))
1038 "#TimedLoginEnable=false\n"
1040 "#TimedLoginDelay=0\n"
1041 ;; Disable initial system setup inside GDM.
1042 ;; Whatever settings are set there should already be
1043 ;; taken care of through `guix system'.
1045 ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=39281>.
1046 "InitialSetupEnable=false\n"
1047 (format #f "WaylandEnable=~:[false~;true~]~%"
1048 (gdm-configuration-wayland? config))
1051 (format #f "Enable=~:[false~;true~]~%"
1052 (gdm-configuration-debug? config))
1055 "#DisallowTCP=true\n"
1056 "#AllowRemoteAutoLogin=false\n"
1059 (format #f "Enable=~:[false~;true~]~%"
1060 (gdm-configuration-xdmcp? config))))
1062 (define (gdm-pam-service config)
1063 "Return a PAM service for @command{gdm}."
1066 (inherit (unix-pam-service "gdm-autologin"
1068 (auth (list (pam-entry
1069 (control "optional")
1070 (module (file-append (gdm-configuration-gdm config)
1071 "/lib/security/pam_gdm.so")))
1073 (control "sufficient")
1074 (module "pam_permit.so")))))
1076 (inherit (unix-pam-service "gdm-launch-environment"))
1077 (auth (list (pam-entry
1078 (control "required")
1079 (module "pam_permit.so")))))
1080 (unix-pam-service "gdm-password"
1082 #:allow-empty-passwords?
1083 (gdm-configuration-allow-empty-passwords? config))))
1085 (define (gdm-shepherd-service config)
1087 (gdm-configuration-file config))
1089 (list (shepherd-service
1090 (documentation "Xorg display server (GDM)")
1091 (provision '(xorg-server))
1092 (requirement '(dbus-system user-processes host-name udev elogind))
1095 (list #$(file-append (gdm-configuration-gdm config)
1097 #:environment-variables
1098 (list #$@(if (gdm-configuration-auto-suspend? config)
1100 #~("DCONF_PROFILE=/etc/dconf/profile/gdm"))
1101 (string-append "GDM_CUSTOM_CONF=" #$config-file)
1104 #$(gdm-configuration-dbus-daemon config))
1108 (gdm-configuration-xorg config)))
1111 #$(gdm-configuration-x-session config))
1114 ((lambda (ls) (string-join ls ":"))
1116 (string-append path "/share"))
1117 ;; XXX: Remove gnome-shell below when GDM
1118 ;; can depend on GNOME Shell directly.
1120 '#$(gdm-configuration-gnome-shell-assets
1122 ;; Add XCURSOR_PATH so that mutter can find its
1123 ;; cursors. gdm doesn't login so doesn't source
1124 ;; the corresponding line in /etc/profile.
1125 "XCURSOR_PATH=/run/current-system/profile/share/icons"
1127 "GDK_PIXBUF_MODULE_FILE="
1128 #$gnome-shell "/" #$%gdk-pixbuf-loaders-cache-file)
1130 "GDM_WAYLAND_SESSION="
1131 #$(gdm-configuration-wayland-session config))))))
1132 (stop #~(make-kill-destructor))
1133 (actions (list (shepherd-configuration-action config-file)))
1136 (define gdm-polkit-rules
1138 (if (gdm-configuration-xdmcp? config)
1139 ;; Allow remote (XDMCP) users to use colord; otherwise an
1140 ;; authentication dialog would appear on the GDM screen (see the
1142 ;; https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/273).
1143 (list (computed-file
1144 "02-allow-colord.rules"
1145 (with-imported-modules '((guix build utils))
1147 (use-modules (guix build utils))
1150 (string-append #$output
1153 (allow-colord.rules (string-append
1155 "/02-allow-colord.rules")))
1157 (call-with-output-file allow-colord.rules
1159 ;; This workaround enables any local or remote in
1160 ;; the "users" group to use colord (see:
1161 ;; https://c-nergy.be/blog/?p=12073).
1163 polkit.addRule(function(action, subject) {
1164 if (action.id.match(\"org.freedesktop.color-manager\")) {
1165 polkit.log(\"POLKIT DEBUG returning YES for action: \" + action);
1166 return polkit.Result.YES;
1171 (define gdm-service-type
1172 (handle-xorg-configuration gdm-configuration
1173 (service-type (name 'gdm)
1175 (list (service-extension shepherd-root-service-type
1176 gdm-shepherd-service)
1177 (service-extension account-service-type
1178 (const %gdm-accounts))
1179 (service-extension dconf-service-type
1181 (service-extension pam-root-service-type
1183 (service-extension polkit-service-type
1185 (service-extension profile-service-type
1186 gdm-configuration-gnome-shell-assets)
1187 (service-extension dbus-root-service-type
1189 gdm-configuration-gdm))
1190 (service-extension localed-service-type
1192 xorg-configuration-keyboard-layout
1193 gdm-configuration-xorg))))
1194 (default-value (gdm-configuration))
1196 "Run the GNOME Desktop Manager (GDM), a program that allows
1197 you to log in in a graphical session, whether or not you use GNOME."))))
1199 ;; Since GDM depends on Rust (gdm -> gnome-shell -> gjs -> mozjs -> rust)
1200 ;; and Rust is currently unavailable on non-x86_64 platforms, default to
1201 ;; SDDM there (FIXME).
1202 (define* (set-xorg-configuration config
1204 (login-manager-service-type
1205 (if (target-x86-64?)
1207 sddm-service-type)))
1208 "Tell the log-in manager (of type @var{login-manager-service-type}) to use
1209 @var{config}, an <xorg-configuration> record."
1210 (simple-service 'set-xorg-configuration
1211 login-manager-service-type
1214 ;;; xorg.scm ends here