gnu: gdm: Run dbus-daemon via a wrapper script.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
CommitLineData
db4fdc04 1;;; GNU Guix --- Functional package management for GNU
92753a8b 2;;; Copyright © 2017 Andy Wingo <wingo@igalia.com>
01b3625d 3;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
4bd43bbe 4;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
e57c2adb 5;;; Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
db4fdc04
LC
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify it
10;;; under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 3 of the License, or (at
12;;; your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful, but
15;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22(define-module (gnu services xorg)
84dfb458 23 #:use-module (gnu artwork)
db4fdc04 24 #:use-module (gnu services)
0190c1c0 25 #:use-module (gnu services shepherd)
6e828634 26 #:use-module (gnu system pam)
6e99c01b 27 #:use-module (gnu services dbus)
bdb36958
LC
28 #:use-module ((gnu packages base) #:select (canonical-package))
29 #:use-module (gnu packages guile)
db4fdc04
LC
30 #:use-module (gnu packages xorg)
31 #:use-module (gnu packages gl)
1f564c15 32 #:use-module (gnu packages glib)
5fd66a37 33 #:use-module (gnu packages display-managers)
9e4eddb4 34 #:use-module (gnu packages gnustep)
6e99c01b 35 #:use-module (gnu packages gnome)
db4fdc04
LC
36 #:use-module (gnu packages admin)
37 #:use-module (gnu packages bash)
6e99c01b 38 #:use-module (gnu system shadow)
b5f4e686 39 #:use-module (guix gexp)
e87f0591 40 #:use-module (guix store)
6726282b 41 #:use-module (guix packages)
db4fdc04 42 #:use-module (guix derivations)
ffc3a02b 43 #:use-module (guix records)
65a67bf7 44 #:use-module (guix deprecation)
d2e59637 45 #:use-module (srfi srfi-1)
6726282b 46 #:use-module (srfi srfi-9)
d2e59637
LC
47 #:use-module (srfi srfi-26)
48 #:use-module (ice-9 match)
d1cdd7ba 49 #:export (xorg-configuration-file
79fd74fa 50 %default-xorg-modules
d344f5a5 51 %default-xorg-fonts
92753a8b 52 xorg-wrapper
d1cdd7ba 53 xorg-start-command
f2901d82
DC
54 xinitrc
55
0ecc3bf3
LC
56 %default-slim-theme
57 %default-slim-theme-name
b37f86d7 58
4b7513e0 59 slim-configuration
b37f86d7
LC
60 slim-configuration?
61 slim-configuration-slim
62 slim-configuration-allow-empty-passwords?
63 slim-configuration-auto-login?
64 slim-configuration-default-user
65 slim-configuration-theme
66 slim-configuration-theme-name
67 slim-configuration-xauth
68 slim-configuration-shepherd
69 slim-configuration-auto-login-session
70 slim-configuration-startx
71
4b7513e0 72 slim-service-type
6726282b
LC
73 slim-service
74
24e96431
75 screen-locker
76 screen-locker?
6726282b 77 screen-locker-service-type
6e99c01b
AW
78 screen-locker-service
79
80 gdm-configuration
81 gdm-service-type
82 gdm-service))
db4fdc04
LC
83
84;;; Commentary:
85;;;
86;;; Services that relate to the X Window System.
87;;;
88;;; Code:
89
d344f5a5 90(define %default-xorg-modules
fd96f94f
PN
91 ;; Default list of modules loaded by the server. When multiple drivers
92 ;; match, the first one in the list is loaded.
d344f5a5
LC
93 (list xf86-video-vesa
94 xf86-video-fbdev
fd96f94f 95 xf86-video-amdgpu
d344f5a5
LC
96 xf86-video-ati
97 xf86-video-cirrus
98 xf86-video-intel
99 xf86-video-mach64
100 xf86-video-nouveau
101 xf86-video-nv
102 xf86-video-sis
103
104 ;; Libinput is the new thing and is recommended over evdev/synaptics:
105 ;; <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
106 xf86-input-libinput
107
108 xf86-input-evdev
109 xf86-input-keyboard
110 xf86-input-mouse
111 xf86-input-synaptics))
112
113(define %default-xorg-fonts
114 ;; Default list of fonts available to the X server.
115 (list (file-append font-alias "/share/fonts/X11/75dpi")
116 (file-append font-alias "/share/fonts/X11/100dpi")
117 (file-append font-alias "/share/fonts/X11/misc")
118 (file-append font-alias "/share/fonts/X11/cyrillic")
4afc903a
LC
119 (file-append font-misc-misc ;default fonts for xterm
120 "/share/fonts/X11/misc")
d344f5a5
LC
121 (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
122
123(define* (xorg-configuration-file #:key
124 (modules %default-xorg-modules)
125 (fonts %default-xorg-fonts)
126 (drivers '()) (resolutions '())
12422c9d 127 (extra-config '()))
d1cdd7ba
LC
128 "Return a configuration file for the Xorg server containing search paths for
129all the common drivers.
f703413e 130
d344f5a5
LC
131@var{modules} must be a list of @dfn{module packages} loaded by the Xorg
132server---e.g., @code{xf86-video-vesa}, @code{xf86-input-keyboard}, and so on.
133@var{fonts} must be a list of font directories to add to the server's
134@dfn{font path}.
135
f703413e
LC
136@var{drivers} must be either the empty list, in which case Xorg chooses a
137graphics driver automatically, or a list of driver names that will be tried in
d2e59637
LC
138this order---e.g., @code{(\"modesetting\" \"vesa\")}.
139
140Likewise, when @var{resolutions} is the empty list, Xorg chooses an
141appropriate screen resolution; otherwise, it must be a list of
12422c9d
LC
142resolutions---e.g., @code{((1024 768) (640 480))}.
143
144Last, @var{extra-config} is a list of strings or objects appended to the
d344f5a5 145configuration file. It is used to pass extra text to be
be1c2c54 146added verbatim to the configuration file."
d344f5a5
LC
147 (define all-modules
148 ;; 'xorg-server' provides 'fbdevhw.so' etc.
149 (append modules (list xorg-server)))
150
151 (define build
152 #~(begin
153 (use-modules (ice-9 match)
154 (srfi srfi-1)
155 (srfi srfi-26))
156
157 (call-with-output-file #$output
158 (lambda (port)
159 (define drivers
160 '#$drivers)
161
162 (define (device-section driver)
163 (string-append "
f703413e
LC
164Section \"Device\"
165 Identifier \"device-" driver "\"
166 Driver \"" driver "\"
167EndSection"))
db4fdc04 168
d344f5a5
LC
169 (define (screen-section driver resolutions)
170 (string-append "
d2e59637
LC
171Section \"Screen\"
172 Identifier \"screen-" driver "\"
173 Device \"device-" driver "\"
174 SubSection \"Display\"
175 Modes "
176 (string-join (map (match-lambda
d1cdd7ba
LC
177 ((x y)
178 (string-append "\"" (number->string x)
179 "x" (number->string y) "\"")))
d2e59637
LC
180 resolutions)) "
181 EndSubSection
182EndSection"))
183
d344f5a5
LC
184 (define (expand modules)
185 ;; Append to MODULES the relevant /lib/xorg/modules
186 ;; sub-directories.
187 (append-map (lambda (module)
188 (filter-map (lambda (directory)
189 (let ((full (string-append module
190 directory)))
191 (and (file-exists? full)
192 full)))
193 '("/lib/xorg/modules/drivers"
194 "/lib/xorg/modules/input"
195 "/lib/xorg/modules/multimedia"
196 "/lib/xorg/modules/extensions")))
197 modules))
db4fdc04 198
d344f5a5
LC
199 (display "Section \"Files\"\n" port)
200 (for-each (lambda (font)
201 (format port " FontPath \"~a\"~%" font))
202 '#$fonts)
203 (for-each (lambda (module)
204 (format port
205 " ModulePath \"~a\"~%"
206 module))
207 (append (expand '#$all-modules)
208
209 ;; For fbdevhw.so and so on.
210 (list #$(file-append xorg-server
211 "/lib/xorg/modules"))))
212 (display "EndSection\n" port)
213 (display "
db4fdc04 214Section \"ServerFlags\"
e30442b5 215 Option \"AllowMouseOpenFail\" \"on\"
d344f5a5 216EndSection\n" port)
12422c9d 217
d344f5a5
LC
218 (display (string-join (map device-section drivers) "\n")
219 port)
220 (newline port)
221 (display (string-join
222 (map (cut screen-section <> '#$resolutions)
223 drivers)
224 "\n")
225 port)
226 (newline port)
227
228 (for-each (lambda (config)
229 (display config port))
230 '#$extra-config)))))
231
232 (computed-file "xserver.conf" build))
db4fdc04 233
79fd74fa
AW
234
235(define (xorg-configuration-directory modules)
236 "Return a directory that contains the @code{.conf} files for X.org that
237includes the @code{share/X11/xorg.conf.d} directories of each package listed
238in @var{modules}."
4ee96a79
LC
239 (with-imported-modules '((guix build utils))
240 (computed-file "xorg.conf.d"
241 #~(begin
242 (use-modules (guix build utils)
243 (srfi srfi-1))
244
245 (define files
246 (append-map (lambda (module)
247 (find-files (string-append
248 module
249 "/share/X11/xorg.conf.d")
250 "\\.conf$"))
251 (list #$@modules)))
252
253 (mkdir #$output)
254 (for-each (lambda (file)
255 (symlink file
256 (string-append #$output "/"
257 (basename file))))
258 files)
259 #t))))
79fd74fa 260
92753a8b
AW
261(define* (xorg-wrapper #:key
262 (guile (canonical-package guile-2.0))
92753a8b 263 (modules %default-xorg-modules)
d344f5a5
LC
264 (configuration-file (xorg-configuration-file
265 #:modules modules))
92753a8b 266 (xorg-server xorg-server))
d1cdd7ba
LC
267 "Return a derivation that builds a @var{guile} script to start the X server
268from @var{xorg-server}. @var{configuration-file} is the server configuration
269file or a derivation that builds it; when omitted, the result of
92753a8b
AW
270@code{xorg-configuration-file} is used. The resulting script should be used
271in place of @code{/usr/bin/X}."
be1c2c54
LC
272 (define exp
273 ;; Write a small wrapper around the X server.
274 #~(begin
275 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
276 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
277
92753a8b
AW
278 (let ((X (string-append #$xorg-server "/bin/X")))
279 (apply execl X X
280 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
281 "-config" #$configuration-file
282 "-configdir" #$(xorg-configuration-directory modules)
283 (cdr (command-line))))))
284
285 (program-file "X-wrapper" exp))
be1c2c54 286
92753a8b
AW
287(define* (xorg-start-command #:key
288 (guile (canonical-package guile-2.0))
92753a8b 289 (modules %default-xorg-modules)
d344f5a5
LC
290 (fonts %default-xorg-fonts)
291 (configuration-file
292 (xorg-configuration-file #:modules modules
293 #:fonts fonts))
92753a8b 294 (xorg-server xorg-server))
d344f5a5
LC
295 "Return a @code{startx} script in which @var{modules}, a list of X module
296packages, and @var{fonts}, a list of X font directories, are available. See
297@code{xorg-wrapper} for more details on the arguments. The result should be
298used in place of @code{startx}."
92753a8b
AW
299 (define X
300 (xorg-wrapper #:guile guile
301 #:configuration-file configuration-file
302 #:modules modules
303 #:xorg-server xorg-server))
304 (define exp
305 ;; Write a small wrapper around the X server.
306 #~(apply execl #$X #$X ;; Second #$X is for argv[0].
307 "-logverbose" "-verbose" "-nolisten" "tcp" "-terminate"
308 (cdr (command-line))))
be1c2c54 309
92753a8b 310 (program-file "startx" exp))
db4fdc04 311
9e4eddb4 312(define* (xinitrc #:key
bdb36958 313 (guile (canonical-package guile-2.0))
24d56899
SB
314 fallback-session)
315 "Return a system-wide xinitrc script that starts the specified X session,
316which should be passed to this script as the first argument. If not, the
65c0f436
LC
317@var{fallback-session} will be used or, if @var{fallback-session} is false, a
318desktop session from the system or user profile will be used."
8779d342
LC
319 (define builder
320 #~(begin
65c0f436
LC
321 (use-modules (ice-9 match)
322 (ice-9 regex)
323 (ice-9 ftw)
4e1efba4 324 (ice-9 rdelim)
65c0f436
LC
325 (srfi srfi-1)
326 (srfi srfi-26))
8779d342 327
16c33bfb
LC
328 (define (close-all-fdes)
329 ;; Close all the open file descriptors except 0 to 2.
330 (let loop ((fd 3))
331 (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
332 (false-if-exception (close-fdes fd))
333 (loop (+ 1 fd)))))
334
b2bd7c25
LC
335 (define (exec-from-login-shell command . args)
336 ;; Run COMMAND from a login shell so that it gets to see the same
337 ;; environment variables that one gets when logging in on a tty, for
338 ;; instance.
339 (let* ((pw (getpw (getuid)))
e0b85670
SB
340 (shell (passwd:shell pw)))
341 ;; Close any open file descriptors. This is all the more
342 ;; important that SLiM itself exec's us directly without closing
343 ;; its own file descriptors!
344 (close-all-fdes)
345
346 ;; The '--login' option is supported at least by Bash and zsh.
347 (execl shell shell "--login" "-c"
348 (string-join (cons command args)))))
349
65c0f436
LC
350 (define system-profile
351 "/run/current-system/profile")
352
353 (define user-profile
354 (and=> (getpw (getuid))
355 (lambda (pw)
356 (string-append (passwd:dir pw) "/.guix-profile"))))
357
358 (define (xsession-command desktop-file)
359 ;; Read from DESKTOP-FILE its X session command and return it as a
360 ;; list.
361 (define exec-regexp
362 (make-regexp "^[[:blank:]]*Exec=(.*)$"))
363
364 (call-with-input-file desktop-file
365 (lambda (port)
366 (let loop ()
367 (match (read-line port)
368 ((? eof-object?) #f)
369 ((= (cut regexp-exec exec-regexp <>) result)
370 (if result
371 (string-tokenize (match:substring result 1))
372 (loop))))))))
373
374 (define (find-session profile)
375 ;; Return an X session command from PROFILE or #f if none was found.
376 (let ((directory (string-append profile "/share/xsessions")))
377 (match (scandir directory
378 (cut string-suffix? ".desktop" <>))
379 ((or () #f)
380 #f)
381 ((sessions ...)
382 (any xsession-command
383 (map (cut string-append directory "/" <>)
384 sessions))))))
385
e0b85670
SB
386 (let* ((home (getenv "HOME"))
387 (xsession-file (string-append home "/.xsession"))
388 (session (match (command-line)
65c0f436
LC
389 ((_)
390 #$(if fallback-session
391 #~(list #$fallback-session)
392 #f))
393 ((_ x ..1)
394 x))))
e0b85670
SB
395 (if (file-exists? xsession-file)
396 ;; Run ~/.xsession when it exists.
617e87bf
LC
397 (apply exec-from-login-shell xsession-file
398 (or session '()))
65c0f436
LC
399 ;; Otherwise, start the specified session or a fallback.
400 (apply exec-from-login-shell
401 (or session
402 (find-session user-profile)
403 (find-session system-profile)))))))
c510cbb4 404
be1c2c54 405 (program-file "xinitrc" builder))
9e4eddb4 406
0ecc3bf3
LC
407\f
408;;;
409;;; SLiM log-in manager.
410;;;
411
0ecc3bf3
LC
412(define %default-slim-theme
413 ;; Theme based on work by Felipe López.
9e41130b 414 (file-append %artwork-repository "/slim"))
0ecc3bf3
LC
415
416(define %default-slim-theme-name
417 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
418 ;; contains the actual theme files.
cf2abac8 419 "0.x")
0ecc3bf3 420
0adfe95a
LC
421(define-record-type* <slim-configuration>
422 slim-configuration make-slim-configuration
423 slim-configuration?
424 (slim slim-configuration-slim
425 (default slim))
b37f86d7
LC
426 (allow-empty-passwords? slim-configuration-allow-empty-passwords?
427 (default #t))
428 (auto-login? slim-configuration-auto-login?
429 (default #f))
430 (default-user slim-configuration-default-user
431 (default ""))
432 (theme slim-configuration-theme
433 (default %default-slim-theme))
434 (theme-name slim-configuration-theme-name
435 (default %default-slim-theme-name))
0adfe95a
LC
436 (xauth slim-configuration-xauth
437 (default xauth))
26b94866
AK
438 (shepherd slim-configuration-shepherd
439 (default shepherd))
b37f86d7 440 (auto-login-session slim-configuration-auto-login-session
65c0f436 441 (default #f))
b37f86d7 442 (startx slim-configuration-startx
736e45a2
DM
443 (default (xorg-start-command)))
444 (sessreg slim-configuration-sessreg
445 (default sessreg)))
0adfe95a
LC
446
447(define (slim-pam-service config)
448 "Return a PAM service for @command{slim}."
449 (list (unix-pam-service
450 "slim"
451 #:allow-empty-passwords?
452 (slim-configuration-allow-empty-passwords? config))))
453
d4053c71 454(define (slim-shepherd-service config)
0adfe95a
LC
455 (define slim.cfg
456 (let ((xinitrc (xinitrc #:fallback-session
457 (slim-configuration-auto-login-session config)))
458 (slim (slim-configuration-slim config))
459 (xauth (slim-configuration-xauth config))
460 (startx (slim-configuration-startx config))
26b94866 461 (shepherd (slim-configuration-shepherd config))
736e45a2
DM
462 (theme-name (slim-configuration-theme-name config))
463 (sessreg (slim-configuration-sessreg config)))
0adfe95a
LC
464 (mixed-text-file "slim.cfg" "
465default_path /run/current-system/profile/bin
466default_xserver " startx "
467xserver_arguments :0 vt7
468xauth_path " xauth "/bin/xauth
469authfile /var/run/slim.auth
470
471# The login command. '%session' is replaced by the chosen session name, one
472# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
473login_cmd exec " xinitrc " %session
474sessiondir /run/current-system/profile/share/xsessions
475session_msg session (F1 to change):
736e45a2
DM
476sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
477sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
0adfe95a 478
26b94866
AK
479halt_cmd " shepherd "/sbin/halt
480reboot_cmd " shepherd "/sbin/reboot\n"
0adfe95a
LC
481(if (slim-configuration-auto-login? config)
482 (string-append "auto_login yes\ndefault_user "
483 (slim-configuration-default-user config) "\n")
484 "")
485(if theme-name
486 (string-append "current_theme " theme-name "\n")
487 ""))))
488
489 (define theme
490 (slim-configuration-theme config))
491
d4053c71 492 (list (shepherd-service
0adfe95a
LC
493 (documentation "Xorg display server")
494 (provision '(xorg-server))
495 (requirement '(user-processes host-name udev))
496 (start
497 #~(lambda ()
498 ;; A stale lock file can prevent SLiM from starting, so remove it to
499 ;; be on the safe side.
500 (false-if-exception (delete-file "/var/run/slim.lock"))
501
502 (fork+exec-command
503 (list (string-append #$slim "/bin/slim") "-nodaemon")
504 #:environment-variables
505 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
506 #$@(if theme
507 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
508 #~())))))
509 (stop #~(make-kill-destructor))
510 (respawn? #t))))
511
512(define slim-service-type
513 (service-type (name 'slim)
514 (extensions
d4053c71
AK
515 (list (service-extension shepherd-root-service-type
516 slim-shepherd-service)
0adfe95a 517 (service-extension pam-root-service-type
e9b82124
LC
518 slim-pam-service)
519
520 ;; Unconditionally add xterm to the system profile, to
521 ;; avoid bad surprises.
522 (service-extension profile-service-type
b37f86d7
LC
523 (const (list xterm)))))
524 (default-value (slim-configuration))))
0adfe95a 525
65a67bf7
LC
526(define-deprecated (slim-service #:key (slim slim)
527 (allow-empty-passwords? #t) auto-login?
528 (default-user "")
529 (theme %default-slim-theme)
530 (theme-name %default-slim-theme-name)
531 (xauth xauth) (shepherd shepherd)
532 (auto-login-session #f)
533 (startx (xorg-start-command)))
534 slim-service-type
db4fdc04 535 "Return a service that spawns the SLiM graphical login manager, which in
51da7ca0
LC
536turn starts the X display server with @var{startx}, a command as returned by
537@code{xorg-start-command}.
db4fdc04 538
04e4e6ab
LC
539@cindex X session
540
541SLiM automatically looks for session types described by the @file{.desktop}
542files in @file{/run/current-system/profile/share/xsessions} and allows users
543to choose a session from the log-in screen using @kbd{F1}. Packages such as
544@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
545adding them to the system-wide set of packages automatically makes them
546available at the log-in screen.
547
548In addition, @file{~/.xsession} files are honored. When available,
549@file{~/.xsession} must be an executable that starts a window manager
550and/or other X clients.
551
51da7ca0
LC
552When @var{allow-empty-passwords?} is true, allow logins with an empty
553password. When @var{auto-login?} is true, log in automatically as
24d56899 554@var{default-user} with @var{auto-login-session}.
0ecc3bf3
LC
555
556If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
557@var{theme} must be a gexp denoting the name of a directory containing the
558theme to use. In that case, @var{theme-name} specifies the name of the
4bd43bbe 559theme."
0adfe95a
LC
560 (service slim-service-type
561 (slim-configuration
562 (slim slim)
563 (allow-empty-passwords? allow-empty-passwords?)
564 (auto-login? auto-login?) (default-user default-user)
565 (theme theme) (theme-name theme-name)
94b9abd9 566 (xauth xauth) (shepherd shepherd)
0adfe95a
LC
567 (auto-login-session auto-login-session)
568 (startx startx))))
db4fdc04 569
6726282b
LC
570\f
571;;;
572;;; Screen lockers & co.
573;;;
574
575(define-record-type <screen-locker>
576 (screen-locker name program empty?)
577 screen-locker?
578 (name screen-locker-name) ;string
579 (program screen-locker-program) ;gexp
580 (empty? screen-locker-allows-empty-passwords?)) ;Boolean
581
582(define screen-locker-pam-services
583 (match-lambda
584 (($ <screen-locker> name _ empty?)
585 (list (unix-pam-service name
586 #:allow-empty-passwords? empty?)))))
587
588(define screen-locker-setuid-programs
589 (compose list screen-locker-program))
590
591(define screen-locker-service-type
592 (service-type (name 'screen-locker)
593 (extensions
594 (list (service-extension pam-root-service-type
595 screen-locker-pam-services)
596 (service-extension setuid-program-service-type
597 screen-locker-setuid-programs)))))
598
599(define* (screen-locker-service package
600 #:optional
601 (program (package-name package))
602 #:key allow-empty-passwords?)
d64e1746 603 "Add @var{package}, a package for a screen locker or screen saver whose
6726282b
LC
604command is @var{program}, to the set of setuid programs and add a PAM entry
605for it. For example:
606
607@lisp
9e41130b 608 (screen-locker-service xlockmore \"xlock\")
6726282b
LC
609@end lisp
610
611makes the good ol' XlockMore usable."
612 (service screen-locker-service-type
613 (screen-locker program
9e41130b 614 (file-append package "/bin/" program)
6726282b
LC
615 allow-empty-passwords?)))
616
6e99c01b
AW
617(define %gdm-accounts
618 (list (user-group (name "gdm") (system? #t))
619 (user-account
620 (name "gdm")
621 (group "gdm")
622 (system? #t)
623 (comment "GNOME Display Manager user")
624 (home-directory "/var/lib/gdm")
625 (shell (file-append shadow "/sbin/nologin")))))
626
1f564c15
TS
627(define dbus-daemon-wrapper
628 (program-file "gdm-dbus-wrapper"
629 #~(begin
630 (setenv "XDG_CONFIG_DIRS"
631 "/run/current-system/profile/etc/xdg")
632 (setenv "XDG_DATA_DIRS"
633 "/run/current-system/profile/share")
634 (apply execl (string-append #$dbus "/bin/dbus-daemon")
635 (program-arguments)))))
636
6e99c01b
AW
637(define-record-type* <gdm-configuration>
638 gdm-configuration make-gdm-configuration
639 gdm-configuration?
640 (gdm gdm-configuration-gdm (default gdm))
641 (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
6e99c01b 642 (auto-login? gdm-configuration-auto-login? (default #f))
1f564c15 643 (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
6e99c01b 644 (default-user gdm-configuration-default-user (default #f))
01b3625d
LC
645 (x-server gdm-configuration-x-server
646 (default (xorg-wrapper))))
6e99c01b 647
e57c2adb
TS
648(define (gdm-configuration-file config)
649 (mixed-text-file "gdm-custom.conf"
650 "[daemon]\n"
651 "#User=gdm\n"
652 "#Group=gdm\n"
653 (if (gdm-configuration-auto-login? config)
654 (string-append
655 "AutomaticLoginEnable=true\n"
656 "AutomaticLogin="
657 (or (gdm-configuration-default-user config)
658 (error "missing default user for auto-login"))
659 "\n")
660 (string-append
661 "AutomaticLoginEnable=false\n"
662 "#AutomaticLogin=\n"))
663 "#TimedLoginEnable=false\n"
664 "#TimedLogin=\n"
665 "#TimedLoginDelay=0\n"
666 "#InitialSetupEnable=true\n"
667 ;; Enable me once X is working.
668 "WaylandEnable=false\n"
669 "\n"
670 "[debug]\n"
671 "#Enable=true\n"
672 "\n"
673 "[security]\n"
674 "#DisallowTCP=true\n"
675 "#AllowRemoteAutoLogin=false\n"))
6e99c01b
AW
676
677(define (gdm-pam-service config)
678 "Return a PAM service for @command{gdm}."
679 (list
680 (pam-service
681 (inherit (unix-pam-service "gdm-autologin"))
682 (auth (list (pam-entry
683 (control "[success=ok default=1]")
684 (module (file-append (gdm-configuration-gdm config)
685 "/lib/security/pam_gdm.so")))
686 (pam-entry
687 (control "sufficient")
688 (module "pam_permit.so")))))
689 (pam-service
690 (inherit (unix-pam-service "gdm-launch-environment"))
691 (auth (list (pam-entry
692 (control "required")
693 (module "pam_permit.so")))))
de409e82
TS
694 (unix-pam-service "gdm-password"
695 #:allow-empty-passwords?
696 (gdm-configuration-allow-empty-passwords? config))))
6e99c01b
AW
697
698(define (gdm-shepherd-service config)
699 (list (shepherd-service
700 (documentation "Xorg display server (GDM)")
701 (provision '(xorg-server))
702 (requirement '(dbus-system user-processes host-name udev))
6e99c01b
AW
703 (start #~(lambda ()
704 (fork+exec-command
705 (list #$(file-append (gdm-configuration-gdm config)
706 "/bin/gdm"))
707 #:environment-variables
708 (list (string-append
e57c2adb
TS
709 "GDM_CUSTOM_CONF="
710 #$(gdm-configuration-file config))
1f564c15
TS
711 (string-append
712 "GDM_DBUS_DAEMON="
713 #$(gdm-configuration-dbus-daemon config))
e57c2adb 714 (string-append
6e99c01b 715 "GDM_X_SERVER="
3eda8dd6
TS
716 #$(gdm-configuration-x-server config))
717 ;; XXX: GDM requires access to a handful of
718 ;; programs and components from Gnome (gnome-shell,
719 ;; dbus, and gnome-session among others). The
720 ;; following variables only work provided Gnome is
721 ;; installed.
722 "XDG_DATA_DIRS=/run/current-system/profile/share"
723 "PATH=/run/current-system/profile/bin"))))
6e99c01b
AW
724 (stop #~(make-kill-destructor))
725 (respawn? #t))))
726
727(define gdm-service-type
728 (service-type (name 'gdm)
729 (extensions
730 (list (service-extension shepherd-root-service-type
731 gdm-shepherd-service)
732 (service-extension account-service-type
733 (const %gdm-accounts))
734 (service-extension pam-root-service-type
735 gdm-pam-service)
6e99c01b 736 (service-extension dbus-root-service-type
01b3625d
LC
737 (compose list
738 gdm-configuration-gdm))))
739 (default-value (gdm-configuration))
740 (description
741 "Run the GNOME Desktop Manager (GDM), a program that allows
742you to log in in a graphical session, whether or not you use GNOME.")))
6e99c01b
AW
743
744;; This service isn't working yet; it gets as far as starting to run the
745;; greeter from gnome-shell but doesn't get any further. It is here because
746;; it doesn't hurt anyone and perhaps it inspires someone to fix it :)
65a67bf7
LC
747(define-deprecated (gdm-service #:key (gdm gdm)
748 (allow-empty-passwords? #t)
749 (x-server (xorg-wrapper)))
750 gdm-service-type
6e99c01b
AW
751 "Return a service that spawns the GDM graphical login manager, which in turn
752starts the X display server with @var{X}, a command as returned by
753@code{xorg-wrapper}.
754
755@cindex X session
756
757GDM automatically looks for session types described by the @file{.desktop}
758files in @file{/run/current-system/profile/share/xsessions} and allows users
759to choose a session from the log-in screen using @kbd{F1}. Packages such as
760@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
761adding them to the system-wide set of packages automatically makes them
762available at the log-in screen.
763
764In addition, @file{~/.xsession} files are honored. When available,
765@file{~/.xsession} must be an executable that starts a window manager
766and/or other X clients.
767
768When @var{allow-empty-passwords?} is true, allow logins with an empty
769password."
770 (service gdm-service-type
771 (gdm-configuration
772 (gdm gdm)
773 (allow-empty-passwords? allow-empty-passwords?)
774 (x-server x-server))))
775
db4fdc04 776;;; xorg.scm ends here