gnu: tesseract-ocr: Update to 3.04.01.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
CommitLineData
db4fdc04 1;;; GNU Guix --- Functional package management for GNU
c510cbb4 2;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4bd43bbe 3;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
db4fdc04
LC
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu services xorg)
84dfb458 21 #:use-module (gnu artwork)
db4fdc04 22 #:use-module (gnu services)
0190c1c0 23 #:use-module (gnu services shepherd)
6e828634 24 #:use-module (gnu system pam)
bdb36958
LC
25 #:use-module ((gnu packages base) #:select (canonical-package))
26 #:use-module (gnu packages guile)
db4fdc04
LC
27 #:use-module (gnu packages xorg)
28 #:use-module (gnu packages gl)
29 #:use-module (gnu packages slim)
9e4eddb4 30 #:use-module (gnu packages gnustep)
db4fdc04
LC
31 #:use-module (gnu packages admin)
32 #:use-module (gnu packages bash)
b5f4e686 33 #:use-module (guix gexp)
e87f0591 34 #:use-module (guix store)
6726282b 35 #:use-module (guix packages)
db4fdc04 36 #:use-module (guix derivations)
ffc3a02b 37 #:use-module (guix records)
d2e59637 38 #:use-module (srfi srfi-1)
6726282b 39 #:use-module (srfi srfi-9)
d2e59637
LC
40 #:use-module (srfi srfi-26)
41 #:use-module (ice-9 match)
d1cdd7ba 42 #:export (xorg-configuration-file
79fd74fa 43 %default-xorg-modules
d1cdd7ba 44 xorg-start-command
0ecc3bf3
LC
45 %default-slim-theme
46 %default-slim-theme-name
4b7513e0
DT
47 slim-configuration
48 slim-service-type
6726282b
LC
49 slim-service
50
51 screen-locker-service-type
52 screen-locker-service))
db4fdc04
LC
53
54;;; Commentary:
55;;;
56;;; Services that relate to the X Window System.
57;;;
58;;; Code:
59
12422c9d
LC
60(define* (xorg-configuration-file #:key (drivers '()) (resolutions '())
61 (extra-config '()))
d1cdd7ba
LC
62 "Return a configuration file for the Xorg server containing search paths for
63all the common drivers.
f703413e
LC
64
65@var{drivers} must be either the empty list, in which case Xorg chooses a
66graphics driver automatically, or a list of driver names that will be tried in
d2e59637
LC
67this order---e.g., @code{(\"modesetting\" \"vesa\")}.
68
69Likewise, when @var{resolutions} is the empty list, Xorg chooses an
70appropriate screen resolution; otherwise, it must be a list of
12422c9d
LC
71resolutions---e.g., @code{((1024 768) (640 480))}.
72
73Last, @var{extra-config} is a list of strings or objects appended to the
be1c2c54
LC
74@code{mixed-text-file} argument list. It is used to pass extra text to be
75added verbatim to the configuration file."
f703413e
LC
76 (define (device-section driver)
77 (string-append "
78Section \"Device\"
79 Identifier \"device-" driver "\"
80 Driver \"" driver "\"
81EndSection"))
db4fdc04 82
d2e59637
LC
83 (define (screen-section driver resolutions)
84 (string-append "
85Section \"Screen\"
86 Identifier \"screen-" driver "\"
87 Device \"device-" driver "\"
88 SubSection \"Display\"
89 Modes "
90 (string-join (map (match-lambda
d1cdd7ba
LC
91 ((x y)
92 (string-append "\"" (number->string x)
93 "x" (number->string y) "\"")))
d2e59637
LC
94 resolutions)) "
95 EndSubSection
96EndSection"))
97
be1c2c54 98 (apply mixed-text-file "xserver.conf" "
db4fdc04 99Section \"Files\"
d1ccd094
EB
100 FontPath \"" font-alias "/share/fonts/X11/75dpi\"
101 FontPath \"" font-alias "/share/fonts/X11/100dpi\"
102 FontPath \"" font-alias "/share/fonts/X11/misc\"
103 FontPath \"" font-alias "/share/fonts/X11/cyrillic\"
378377eb 104 FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\"
db4fdc04 105 ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
0adb027b 106 ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\"
3fc4eb21 107 ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\"
0adb027b
LC
108 ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\"
109 ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\"
110 ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\"
ca63770a 111 ModulePath \"" xf86-video-nouveau "/lib/xorg/modules/drivers\"
0adb027b 112 ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
2c37a34c 113 ModulePath \"" xf86-video-sis "/lib/xorg/modules/drivers\"
c2ee19e6
LC
114
115 # Libinput is the new thing and is recommended over evdev/synaptics
116 # by those who know:
117 # <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
118 ModulePath \"" xf86-input-libinput "/lib/xorg/modules/input\"
119
073cd609 120 ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\"
db4fdc04 121 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
0adb027b
LC
122 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
123 ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
db4fdc04
LC
124 ModulePath \"" xorg-server "/lib/xorg/modules\"
125 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
126 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
127EndSection
128
129Section \"ServerFlags\"
e30442b5 130 Option \"AllowMouseOpenFail\" \"on\"
db4fdc04 131EndSection
f703413e 132"
12422c9d 133 (string-join (map device-section drivers) "\n") "\n"
d2e59637
LC
134 (string-join (map (cut screen-section <> resolutions)
135 drivers)
12422c9d
LC
136 "\n")
137
138 "\n"
139 extra-config))
db4fdc04 140
79fd74fa
AW
141(define %default-xorg-modules
142 (list xf86-video-vesa
143 xf86-video-fbdev
144 xf86-video-modesetting
145 xf86-video-cirrus
146 xf86-video-intel
147 xf86-video-mach64
148 xf86-video-nouveau
149 xf86-video-nv
150 xf86-video-sis
151 xf86-input-libinput
152 xf86-input-evdev
153 xf86-input-keyboard
154 xf86-input-mouse
155 xf86-input-synaptics))
156
157(define (xorg-configuration-directory modules)
158 "Return a directory that contains the @code{.conf} files for X.org that
159includes the @code{share/X11/xorg.conf.d} directories of each package listed
160in @var{modules}."
4ee96a79
LC
161 (with-imported-modules '((guix build utils))
162 (computed-file "xorg.conf.d"
163 #~(begin
164 (use-modules (guix build utils)
165 (srfi srfi-1))
166
167 (define files
168 (append-map (lambda (module)
169 (find-files (string-append
170 module
171 "/share/X11/xorg.conf.d")
172 "\\.conf$"))
173 (list #$@modules)))
174
175 (mkdir #$output)
176 (for-each (lambda (file)
177 (symlink file
178 (string-append #$output "/"
179 (basename file))))
180 files)
181 #t))))
79fd74fa 182
d1cdd7ba
LC
183(define* (xorg-start-command #:key
184 (guile (canonical-package guile-2.0))
be1c2c54 185 (configuration-file (xorg-configuration-file))
79fd74fa 186 (modules %default-xorg-modules)
d1cdd7ba
LC
187 (xorg-server xorg-server))
188 "Return a derivation that builds a @var{guile} script to start the X server
189from @var{xorg-server}. @var{configuration-file} is the server configuration
190file or a derivation that builds it; when omitted, the result of
191@code{xorg-configuration-file} is used.
192
193Usually the X server is started by a login manager."
be1c2c54
LC
194 (define exp
195 ;; Write a small wrapper around the X server.
196 #~(begin
197 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
198 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
199
200 (apply execl (string-append #$xorg-server "/bin/X")
201 (string-append #$xorg-server "/bin/X") ;argv[0]
202 "-logverbose" "-verbose"
203 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
204 "-config" #$configuration-file
79fd74fa 205 "-configdir" #$(xorg-configuration-directory modules)
be1c2c54
LC
206 "-nolisten" "tcp" "-terminate"
207
208 ;; Note: SLiM and other display managers add the
209 ;; '-auth' flag by themselves.
210 (cdr (command-line)))))
211
212 (program-file "start-xorg" exp))
db4fdc04 213
9e4eddb4 214(define* (xinitrc #:key
bdb36958 215 (guile (canonical-package guile-2.0))
24d56899
SB
216 fallback-session)
217 "Return a system-wide xinitrc script that starts the specified X session,
218which should be passed to this script as the first argument. If not, the
219@var{fallback-session} will be used."
8779d342
LC
220 (define builder
221 #~(begin
222 (use-modules (ice-9 match))
223
16c33bfb
LC
224 (define (close-all-fdes)
225 ;; Close all the open file descriptors except 0 to 2.
226 (let loop ((fd 3))
227 (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
228 (false-if-exception (close-fdes fd))
229 (loop (+ 1 fd)))))
230
b2bd7c25
LC
231 (define (exec-from-login-shell command . args)
232 ;; Run COMMAND from a login shell so that it gets to see the same
233 ;; environment variables that one gets when logging in on a tty, for
234 ;; instance.
235 (let* ((pw (getpw (getuid)))
e0b85670
SB
236 (shell (passwd:shell pw)))
237 ;; Close any open file descriptors. This is all the more
238 ;; important that SLiM itself exec's us directly without closing
239 ;; its own file descriptors!
240 (close-all-fdes)
241
242 ;; The '--login' option is supported at least by Bash and zsh.
243 (execl shell shell "--login" "-c"
244 (string-join (cons command args)))))
245
246 (let* ((home (getenv "HOME"))
247 (xsession-file (string-append home "/.xsession"))
248 (session (match (command-line)
c510cbb4
LC
249 ((_) (list #$fallback-session))
250 ((_ x ..1) x))))
e0b85670
SB
251 (if (file-exists? xsession-file)
252 ;; Run ~/.xsession when it exists.
f2ab9250 253 (apply exec-from-login-shell xsession-file session)
e0b85670 254 ;; Otherwise, start the specified session.
c510cbb4
LC
255 (apply exec-from-login-shell session)))))
256
be1c2c54 257 (program-file "xinitrc" builder))
9e4eddb4 258
0ecc3bf3
LC
259\f
260;;;
261;;; SLiM log-in manager.
262;;;
263
0ecc3bf3
LC
264(define %default-slim-theme
265 ;; Theme based on work by Felipe López.
266 #~(string-append #$%artwork-repository "/slim"))
267
268(define %default-slim-theme-name
269 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
270 ;; contains the actual theme files.
cf2abac8 271 "0.x")
0ecc3bf3 272
0adfe95a
LC
273(define-record-type* <slim-configuration>
274 slim-configuration make-slim-configuration
275 slim-configuration?
276 (slim slim-configuration-slim
277 (default slim))
278 (allow-empty-passwords? slim-configuration-allow-empty-passwords?)
279 (auto-login? slim-configuration-auto-login?)
280 (default-user slim-configuration-default-user)
281 (theme slim-configuration-theme)
282 (theme-name slim-configuration-theme-name)
283 (xauth slim-configuration-xauth
284 (default xauth))
26b94866
AK
285 (shepherd slim-configuration-shepherd
286 (default shepherd))
0adfe95a
LC
287 (bash slim-configuration-bash
288 (default bash))
289 (auto-login-session slim-configuration-auto-login-session)
290 (startx slim-configuration-startx))
291
292(define (slim-pam-service config)
293 "Return a PAM service for @command{slim}."
294 (list (unix-pam-service
295 "slim"
296 #:allow-empty-passwords?
297 (slim-configuration-allow-empty-passwords? config))))
298
d4053c71 299(define (slim-shepherd-service config)
0adfe95a
LC
300 (define slim.cfg
301 (let ((xinitrc (xinitrc #:fallback-session
302 (slim-configuration-auto-login-session config)))
303 (slim (slim-configuration-slim config))
304 (xauth (slim-configuration-xauth config))
305 (startx (slim-configuration-startx config))
26b94866 306 (shepherd (slim-configuration-shepherd config))
0adfe95a
LC
307 (theme-name (slim-configuration-theme-name config)))
308 (mixed-text-file "slim.cfg" "
309default_path /run/current-system/profile/bin
310default_xserver " startx "
311xserver_arguments :0 vt7
312xauth_path " xauth "/bin/xauth
313authfile /var/run/slim.auth
314
315# The login command. '%session' is replaced by the chosen session name, one
316# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
317login_cmd exec " xinitrc " %session
318sessiondir /run/current-system/profile/share/xsessions
319session_msg session (F1 to change):
320
26b94866
AK
321halt_cmd " shepherd "/sbin/halt
322reboot_cmd " shepherd "/sbin/reboot\n"
0adfe95a
LC
323(if (slim-configuration-auto-login? config)
324 (string-append "auto_login yes\ndefault_user "
325 (slim-configuration-default-user config) "\n")
326 "")
327(if theme-name
328 (string-append "current_theme " theme-name "\n")
329 ""))))
330
331 (define theme
332 (slim-configuration-theme config))
333
d4053c71 334 (list (shepherd-service
0adfe95a
LC
335 (documentation "Xorg display server")
336 (provision '(xorg-server))
337 (requirement '(user-processes host-name udev))
338 (start
339 #~(lambda ()
340 ;; A stale lock file can prevent SLiM from starting, so remove it to
341 ;; be on the safe side.
342 (false-if-exception (delete-file "/var/run/slim.lock"))
343
344 (fork+exec-command
345 (list (string-append #$slim "/bin/slim") "-nodaemon")
346 #:environment-variables
347 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
348 #$@(if theme
349 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
350 #~())))))
351 (stop #~(make-kill-destructor))
352 (respawn? #t))))
353
354(define slim-service-type
355 (service-type (name 'slim)
356 (extensions
d4053c71
AK
357 (list (service-extension shepherd-root-service-type
358 slim-shepherd-service)
0adfe95a 359 (service-extension pam-root-service-type
e9b82124
LC
360 slim-pam-service)
361
362 ;; Unconditionally add xterm to the system profile, to
363 ;; avoid bad surprises.
364 (service-extension profile-service-type
365 (const (list xterm)))))))
0adfe95a 366
db4fdc04
LC
367(define* (slim-service #:key (slim slim)
368 (allow-empty-passwords? #t) auto-login?
369 (default-user "")
0ecc3bf3
LC
370 (theme %default-slim-theme)
371 (theme-name %default-slim-theme-name)
26b94866 372 (xauth xauth) (shepherd shepherd) (bash bash)
24d56899
SB
373 (auto-login-session #~(string-append #$windowmaker
374 "/bin/wmaker"))
be1c2c54 375 (startx (xorg-start-command)))
db4fdc04 376 "Return a service that spawns the SLiM graphical login manager, which in
51da7ca0
LC
377turn starts the X display server with @var{startx}, a command as returned by
378@code{xorg-start-command}.
db4fdc04 379
04e4e6ab
LC
380@cindex X session
381
382SLiM automatically looks for session types described by the @file{.desktop}
383files in @file{/run/current-system/profile/share/xsessions} and allows users
384to choose a session from the log-in screen using @kbd{F1}. Packages such as
385@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
386adding them to the system-wide set of packages automatically makes them
387available at the log-in screen.
388
389In addition, @file{~/.xsession} files are honored. When available,
390@file{~/.xsession} must be an executable that starts a window manager
391and/or other X clients.
392
51da7ca0
LC
393When @var{allow-empty-passwords?} is true, allow logins with an empty
394password. When @var{auto-login?} is true, log in automatically as
24d56899 395@var{default-user} with @var{auto-login-session}.
0ecc3bf3
LC
396
397If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
398@var{theme} must be a gexp denoting the name of a directory containing the
399theme to use. In that case, @var{theme-name} specifies the name of the
4bd43bbe 400theme."
0adfe95a
LC
401 (service slim-service-type
402 (slim-configuration
403 (slim slim)
404 (allow-empty-passwords? allow-empty-passwords?)
405 (auto-login? auto-login?) (default-user default-user)
406 (theme theme) (theme-name theme-name)
26b94866 407 (xauth xauth) (shepherd shepherd) (bash bash)
0adfe95a
LC
408 (auto-login-session auto-login-session)
409 (startx startx))))
db4fdc04 410
6726282b
LC
411\f
412;;;
413;;; Screen lockers & co.
414;;;
415
416(define-record-type <screen-locker>
417 (screen-locker name program empty?)
418 screen-locker?
419 (name screen-locker-name) ;string
420 (program screen-locker-program) ;gexp
421 (empty? screen-locker-allows-empty-passwords?)) ;Boolean
422
423(define screen-locker-pam-services
424 (match-lambda
425 (($ <screen-locker> name _ empty?)
426 (list (unix-pam-service name
427 #:allow-empty-passwords? empty?)))))
428
429(define screen-locker-setuid-programs
430 (compose list screen-locker-program))
431
432(define screen-locker-service-type
433 (service-type (name 'screen-locker)
434 (extensions
435 (list (service-extension pam-root-service-type
436 screen-locker-pam-services)
437 (service-extension setuid-program-service-type
438 screen-locker-setuid-programs)))))
439
440(define* (screen-locker-service package
441 #:optional
442 (program (package-name package))
443 #:key allow-empty-passwords?)
444 "Add @var{package}, a package for a screen-locker or screen-saver whose
445command is @var{program}, to the set of setuid programs and add a PAM entry
446for it. For example:
447
448@lisp
449(screen-locker-service xlockmore \"xlock\")
450@end lisp
451
452makes the good ol' XlockMore usable."
453 (service screen-locker-service-type
454 (screen-locker program
455 #~(string-append #$package
456 #$(string-append "/bin/" program))
457 allow-empty-passwords?)))
458
db4fdc04 459;;; xorg.scm ends here