substitute-binary: Let the user know when the cache is being updated.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
CommitLineData
db4fdc04 1;;; GNU Guix --- Functional package management for GNU
e87f0591 2;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
db4fdc04
LC
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu services xorg)
84dfb458 20 #:use-module (gnu artwork)
db4fdc04
LC
21 #:use-module (gnu services)
22 #:use-module (gnu system linux) ; 'pam-service'
bdb36958
LC
23 #:use-module ((gnu packages base) #:select (canonical-package))
24 #:use-module (gnu packages guile)
db4fdc04
LC
25 #:use-module (gnu packages xorg)
26 #:use-module (gnu packages gl)
27 #:use-module (gnu packages slim)
28 #:use-module (gnu packages ratpoison)
9e4eddb4 29 #:use-module (gnu packages gnustep)
db4fdc04
LC
30 #:use-module (gnu packages admin)
31 #:use-module (gnu packages bash)
b5f4e686 32 #:use-module (guix gexp)
e87f0591 33 #:use-module (guix store)
db4fdc04
LC
34 #:use-module (guix monads)
35 #:use-module (guix derivations)
d2e59637
LC
36 #:use-module (srfi srfi-1)
37 #:use-module (srfi srfi-26)
38 #:use-module (ice-9 match)
db4fdc04 39 #:export (xorg-start-command
24d56899 40 %default-xsessions
0ecc3bf3
LC
41 %default-slim-theme
42 %default-slim-theme-name
db4fdc04
LC
43 slim-service))
44
45;;; Commentary:
46;;;
47;;; Services that relate to the X Window System.
48;;;
49;;; Code:
50
51(define* (xorg-start-command #:key
bdb36958 52 (guile (canonical-package guile-2.0))
f703413e 53 (xorg-server xorg-server)
d2e59637 54 (drivers '()) (resolutions '()))
f703413e
LC
55 "Return a derivation that builds a @var{guile} script to start the X server
56from @var{xorg-server}. Usually the X server is started by a login manager.
57
58@var{drivers} must be either the empty list, in which case Xorg chooses a
59graphics driver automatically, or a list of driver names that will be tried in
d2e59637
LC
60this order---e.g., @code{(\"modesetting\" \"vesa\")}.
61
62Likewise, when @var{resolutions} is the empty list, Xorg chooses an
63appropriate screen resolution; otherwise, it must be a list of
64resolutions---e.g., @code{((1024 768) (640 480))}."
f703413e
LC
65
66 (define (device-section driver)
67 (string-append "
68Section \"Device\"
69 Identifier \"device-" driver "\"
70 Driver \"" driver "\"
71EndSection"))
db4fdc04 72
d2e59637
LC
73 (define (screen-section driver resolutions)
74 (string-append "
75Section \"Screen\"
76 Identifier \"screen-" driver "\"
77 Device \"device-" driver "\"
78 SubSection \"Display\"
79 Modes "
80 (string-join (map (match-lambda
81 ((x y)
82 (string-append "\"" (number->string x)
83 "x" (number->string y) "\"")))
84 resolutions)) "
85 EndSubSection
86EndSection"))
87
db4fdc04
LC
88 (define (xserver.conf)
89 (text-file* "xserver.conf" "
90Section \"Files\"
378377eb 91 FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\"
db4fdc04 92 ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
0adb027b 93 ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\"
3fc4eb21 94 ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\"
0adb027b
LC
95 ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\"
96 ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\"
97 ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\"
98 ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
2c37a34c 99 ModulePath \"" xf86-video-sis "/lib/xorg/modules/drivers\"
073cd609 100 ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\"
db4fdc04 101 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
0adb027b
LC
102 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
103 ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
db4fdc04
LC
104 ModulePath \"" xorg-server "/lib/xorg/modules\"
105 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
106 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
107EndSection
108
109Section \"ServerFlags\"
e30442b5 110 Option \"AllowMouseOpenFail\" \"on\"
db4fdc04 111EndSection
f703413e 112"
d2e59637
LC
113 (string-join (map device-section drivers) "\n")
114 (string-join (map (cut screen-section <> resolutions)
115 drivers)
116 "\n")))
db4fdc04 117
8779d342
LC
118 (mlet %store-monad ((config (xserver.conf)))
119 (define script
db4fdc04 120 ;; Write a small wrapper around the X server.
8779d342
LC
121 #~(begin
122 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
123 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
124
125 (apply execl (string-append #$xorg-server "/bin/X")
91cc5aff 126 (string-append #$xorg-server "/bin/X") ;argv[0]
594340bc 127 "-logverbose" "-verbose"
8779d342
LC
128 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
129 "-config" #$config
130 "-nolisten" "tcp" "-terminate"
131
132 ;; Note: SLiM and other display managers add the
133 ;; '-auth' flag by themselves.
134 (cdr (command-line)))))
135
136 (gexp->script "start-xorg" script)))
db4fdc04 137
9e4eddb4 138(define* (xinitrc #:key
bdb36958 139 (guile (canonical-package guile-2.0))
24d56899
SB
140 fallback-session)
141 "Return a system-wide xinitrc script that starts the specified X session,
142which should be passed to this script as the first argument. If not, the
143@var{fallback-session} will be used."
8779d342
LC
144 (define builder
145 #~(begin
146 (use-modules (ice-9 match))
147
b2bd7c25
LC
148 (define (exec-from-login-shell command . args)
149 ;; Run COMMAND from a login shell so that it gets to see the same
150 ;; environment variables that one gets when logging in on a tty, for
151 ;; instance.
152 (let* ((pw (getpw (getuid)))
153 (shell (passwd:shell pw))
154 (st (stat command #f)))
155 (when (and st (not (zero? (logand (stat:mode st) #o100))))
156 ;; The '--login' option is supported at least by Bash and zsh.
157 (execl shell shell "--login" "-c"
158 (string-join (cons command args))))))
159
24d56899
SB
160 (let ((home (getenv "HOME"))
161 (session (match (command-line)
162 ((_ x) x)
163 (_ #$fallback-session))))
164 ;; First, try to run ~/.xsession.
165 (exec-from-login-shell (string-append home "/.xsession"))
166 ;; Then try to start the specified session.
167 (exec-from-login-shell session))))
8779d342 168 (gexp->script "xinitrc" builder))
9e4eddb4 169
0ecc3bf3
LC
170\f
171;;;
172;;; SLiM log-in manager.
173;;;
174
24d56899
SB
175(define %default-xsessions
176 ;; Default xsessions available for log-in manager, representing as a list of
177 ;; monadic desktop entries.
178 (list (text-file* "wmaker.desktop" "
179[Desktop Entry]
180Name=Window Maker
181Exec=" windowmaker "/bin/wmaker
182Type=Application
183")
184 (text-file* "ratpoison.desktop" "
185[Desktop Entry]
186Name=Ratpoison
187Exec=" ratpoison "/bin/ratpoison
188Type=Application
189")))
190
191(define (xsessions-directory sessions)
192 "Return a directory containing SESSIONS, which should be a list of monadic
193desktop entries."
194 (mlet %store-monad ((sessions (sequence %store-monad sessions)))
195 (define builder
196 #~(begin
197 (mkdir #$output)
198 (for-each (lambda (session)
199 (symlink session (string-append #$output "/"
200 (basename session))))
201 '#$sessions)))
202 (gexp->derivation "xsessions-dir" builder)))
203
0ecc3bf3
LC
204(define %default-slim-theme
205 ;; Theme based on work by Felipe López.
206 #~(string-append #$%artwork-repository "/slim"))
207
208(define %default-slim-theme-name
209 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
210 ;; contains the actual theme files.
211 "0.8")
212
db4fdc04
LC
213(define* (slim-service #:key (slim slim)
214 (allow-empty-passwords? #t) auto-login?
215 (default-user "")
0ecc3bf3
LC
216 (theme %default-slim-theme)
217 (theme-name %default-slim-theme-name)
db4fdc04 218 (xauth xauth) (dmd dmd) (bash bash)
24d56899
SB
219 (sessions %default-xsessions)
220 (auto-login-session #~(string-append #$windowmaker
221 "/bin/wmaker"))
db4fdc04
LC
222 startx)
223 "Return a service that spawns the SLiM graphical login manager, which in
51da7ca0
LC
224turn starts the X display server with @var{startx}, a command as returned by
225@code{xorg-start-command}.
db4fdc04 226
51da7ca0
LC
227When @var{allow-empty-passwords?} is true, allow logins with an empty
228password. When @var{auto-login?} is true, log in automatically as
24d56899 229@var{default-user} with @var{auto-login-session}.
0ecc3bf3
LC
230
231If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
232@var{theme} must be a gexp denoting the name of a directory containing the
233theme to use. In that case, @var{theme-name} specifies the name of the
234theme."
235
db4fdc04 236 (define (slim.cfg)
9e4eddb4 237 (mlet %store-monad ((startx (or startx (xorg-start-command)))
24d56899
SB
238 (xinitrc (xinitrc #:fallback-session
239 auto-login-session))
240 (sessiondir (xsessions-directory sessions)))
db4fdc04 241 (text-file* "slim.cfg" "
b4140694 242default_path /run/current-system/profile/bin
db4fdc04
LC
243default_xserver " startx "
244xserver_arguments :0 vt7
245xauth_path " xauth "/bin/xauth
246authfile /var/run/slim.auth
247
248# The login command. '%session' is replaced by the chosen session name, one
249# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
057d6ce5 250login_cmd exec " xinitrc " %session
24d56899 251sessiondir " sessiondir "
db4fdc04
LC
252
253halt_cmd " dmd "/sbin/halt
254reboot_cmd " dmd "/sbin/reboot
0ecc3bf3
LC
255"
256(if auto-login?
257 (string-append "auto_login yes\ndefault_user " default-user "\n")
258 "")
259(if theme-name
260 (string-append "current_theme " theme-name "\n")
261 ""))))
db4fdc04 262
b5f4e686 263 (mlet %store-monad ((slim.cfg (slim.cfg)))
db4fdc04
LC
264 (return
265 (service
266 (documentation "Xorg display server")
267 (provision '(xorg-server))
8dbab712 268 (requirement '(user-processes host-name udev))
db4fdc04 269 (start
47b73c34
LC
270 #~(lambda ()
271 ;; A stale lock file can prevent SLiM from starting, so remove it
272 ;; to be on the safe side.
273 (false-if-exception (delete-file "/var/run/slim.lock"))
274
275 (fork+exec-command
276 (list (string-append #$slim "/bin/slim") "-nodaemon")
277 #:environment-variables
0ecc3bf3
LC
278 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
279 #$@(if theme
280 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
281 #~())))))
b5f4e686 282 (stop #~(make-kill-destructor))
db4fdc04
LC
283 (respawn? #t)
284 (pam-services
285 ;; Tell PAM about 'slim'.
286 (list (unix-pam-service
287 "slim"
288 #:allow-empty-passwords? allow-empty-passwords?)))))))
289
290;;; xorg.scm ends here