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