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