hydra: Make USB installation image bigger.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
CommitLineData
db4fdc04
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
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)
20 #:use-module (gnu services)
21 #:use-module (gnu system linux) ; 'pam-service'
bdb36958
LC
22 #:use-module ((gnu packages base) #:select (canonical-package))
23 #:use-module (gnu packages guile)
db4fdc04
LC
24 #:use-module (gnu packages xorg)
25 #:use-module (gnu packages gl)
26 #:use-module (gnu packages slim)
27 #:use-module (gnu packages ratpoison)
9e4eddb4 28 #:use-module (gnu packages gnustep)
db4fdc04
LC
29 #:use-module (gnu packages admin)
30 #:use-module (gnu packages bash)
b5f4e686 31 #:use-module (guix gexp)
db4fdc04
LC
32 #:use-module (guix monads)
33 #:use-module (guix derivations)
d2e59637
LC
34 #:use-module (srfi srfi-1)
35 #:use-module (srfi srfi-26)
36 #:use-module (ice-9 match)
db4fdc04
LC
37 #:export (xorg-start-command
38 slim-service))
39
40;;; Commentary:
41;;;
42;;; Services that relate to the X Window System.
43;;;
44;;; Code:
45
46(define* (xorg-start-command #:key
bdb36958 47 (guile (canonical-package guile-2.0))
f703413e 48 (xorg-server xorg-server)
d2e59637 49 (drivers '()) (resolutions '()))
f703413e
LC
50 "Return a derivation that builds a @var{guile} script to start the X server
51from @var{xorg-server}. Usually the X server is started by a login manager.
52
53@var{drivers} must be either the empty list, in which case Xorg chooses a
54graphics driver automatically, or a list of driver names that will be tried in
d2e59637
LC
55this order---e.g., @code{(\"modesetting\" \"vesa\")}.
56
57Likewise, when @var{resolutions} is the empty list, Xorg chooses an
58appropriate screen resolution; otherwise, it must be a list of
59resolutions---e.g., @code{((1024 768) (640 480))}."
f703413e
LC
60
61 (define (device-section driver)
62 (string-append "
63Section \"Device\"
64 Identifier \"device-" driver "\"
65 Driver \"" driver "\"
66EndSection"))
db4fdc04 67
d2e59637
LC
68 (define (screen-section driver resolutions)
69 (string-append "
70Section \"Screen\"
71 Identifier \"screen-" driver "\"
72 Device \"device-" driver "\"
73 SubSection \"Display\"
74 Modes "
75 (string-join (map (match-lambda
76 ((x y)
77 (string-append "\"" (number->string x)
78 "x" (number->string y) "\"")))
79 resolutions)) "
80 EndSubSection
81EndSection"))
82
db4fdc04
LC
83 (define (xserver.conf)
84 (text-file* "xserver.conf" "
85Section \"Files\"
378377eb 86 FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\"
db4fdc04 87 ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
0adb027b 88 ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\"
41d07f5e
LC
89# FIXME: Commented out due to libdrm incompatibility.
90# ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\"
0adb027b
LC
91 ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\"
92 ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\"
93 ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\"
94 ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
db4fdc04 95 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
0adb027b
LC
96 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
97 ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
db4fdc04
LC
98 ModulePath \"" xorg-server "/lib/xorg/modules\"
99 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
100 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
101EndSection
102
103Section \"ServerFlags\"
e30442b5 104 Option \"AllowMouseOpenFail\" \"on\"
db4fdc04 105EndSection
f703413e 106"
d2e59637
LC
107 (string-join (map device-section drivers) "\n")
108 (string-join (map (cut screen-section <> resolutions)
109 drivers)
110 "\n")))
db4fdc04 111
8779d342
LC
112 (mlet %store-monad ((config (xserver.conf)))
113 (define script
db4fdc04 114 ;; Write a small wrapper around the X server.
8779d342
LC
115 #~(begin
116 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
117 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
118
119 (apply execl (string-append #$xorg-server "/bin/X")
91cc5aff 120 (string-append #$xorg-server "/bin/X") ;argv[0]
594340bc 121 "-logverbose" "-verbose"
8779d342
LC
122 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
123 "-config" #$config
124 "-nolisten" "tcp" "-terminate"
125
126 ;; Note: SLiM and other display managers add the
127 ;; '-auth' flag by themselves.
128 (cdr (command-line)))))
129
130 (gexp->script "start-xorg" script)))
db4fdc04 131
9e4eddb4 132(define* (xinitrc #:key
bdb36958 133 (guile (canonical-package guile-2.0))
9e4eddb4
LC
134 (ratpoison ratpoison)
135 (windowmaker windowmaker))
136 "Return a system-wide xinitrc script that starts the specified X session."
8779d342
LC
137 (define builder
138 #~(begin
139 (use-modules (ice-9 match))
140
d9372161
LC
141 ;; First, try to run ~/.xsession.
142 (let* ((home (getenv "HOME"))
143 (file (string-append home "/.xsession")))
144 (false-if-exception (execl file file)))
145
146 ;; Then try a pre-configured session type.
8779d342
LC
147 (match (command-line)
148 ((_ "ratpoison")
149 (execl (string-append #$ratpoison "/bin/ratpoison")))
150 (_
151 (execl (string-append #$windowmaker "/bin/wmaker"))))))
152
153 (gexp->script "xinitrc" builder))
9e4eddb4 154
db4fdc04
LC
155(define* (slim-service #:key (slim slim)
156 (allow-empty-passwords? #t) auto-login?
157 (default-user "")
158 (xauth xauth) (dmd dmd) (bash bash)
159 startx)
160 "Return a service that spawns the SLiM graphical login manager, which in
51da7ca0
LC
161turn starts the X display server with @var{startx}, a command as returned by
162@code{xorg-start-command}.
db4fdc04 163
51da7ca0
LC
164When @var{allow-empty-passwords?} is true, allow logins with an empty
165password. When @var{auto-login?} is true, log in automatically as
166@var{default-user}."
db4fdc04 167 (define (slim.cfg)
9e4eddb4
LC
168 (mlet %store-monad ((startx (or startx (xorg-start-command)))
169 (xinitrc (xinitrc)))
db4fdc04 170 (text-file* "slim.cfg" "
b4140694 171default_path /run/current-system/profile/bin
db4fdc04
LC
172default_xserver " startx "
173xserver_arguments :0 vt7
174xauth_path " xauth "/bin/xauth
175authfile /var/run/slim.auth
176
177# The login command. '%session' is replaced by the chosen session name, one
178# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
057d6ce5 179login_cmd exec " xinitrc " %session
9e4eddb4 180sessions wmaker,ratpoison
db4fdc04
LC
181
182halt_cmd " dmd "/sbin/halt
183reboot_cmd " dmd "/sbin/reboot
184" (if auto-login?
185 (string-append "auto_login yes\ndefault_user " default-user)
186 ""))))
187
b5f4e686 188 (mlet %store-monad ((slim.cfg (slim.cfg)))
db4fdc04
LC
189 (return
190 (service
191 (documentation "Xorg display server")
192 (provision '(xorg-server))
8dbab712 193 (requirement '(user-processes host-name udev))
db4fdc04 194 (start
47b73c34
LC
195 #~(lambda ()
196 ;; A stale lock file can prevent SLiM from starting, so remove it
197 ;; to be on the safe side.
198 (false-if-exception (delete-file "/var/run/slim.lock"))
199
200 (fork+exec-command
201 (list (string-append #$slim "/bin/slim") "-nodaemon")
202 #:environment-variables
203 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)))))
b5f4e686 204 (stop #~(make-kill-destructor))
db4fdc04
LC
205 (respawn? #t)
206 (pam-services
207 ;; Tell PAM about 'slim'.
208 (list (unix-pam-service
209 "slim"
210 #:allow-empty-passwords? allow-empty-passwords?)))))))
211
212;;; xorg.scm ends here