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