Commit | Line | Data |
---|---|---|
db4fdc04 | 1 | ;;; GNU Guix --- Functional package management for GNU |
e87f0591 | 2 | ;;; Copyright © 2013, 2014, 2015 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 LC |
22 | #:use-module (gnu services) |
23 | #:use-module (gnu system linux) ; 'pam-service' | |
bdb36958 LC |
24 | #:use-module ((gnu packages base) #:select (canonical-package)) |
25 | #:use-module (gnu packages guile) | |
db4fdc04 LC |
26 | #:use-module (gnu packages xorg) |
27 | #:use-module (gnu packages gl) | |
28 | #:use-module (gnu packages slim) | |
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) | |
ffc3a02b | 36 | #:use-module (guix records) |
d2e59637 LC |
37 | #:use-module (srfi srfi-1) |
38 | #:use-module (srfi srfi-26) | |
39 | #:use-module (ice-9 match) | |
d1cdd7ba LC |
40 | #:export (xorg-configuration-file |
41 | xorg-start-command | |
0ecc3bf3 LC |
42 | %default-slim-theme |
43 | %default-slim-theme-name | |
db4fdc04 LC |
44 | slim-service)) |
45 | ||
46 | ;;; Commentary: | |
47 | ;;; | |
48 | ;;; Services that relate to the X Window System. | |
49 | ;;; | |
50 | ;;; Code: | |
51 | ||
12422c9d LC |
52 | (define* (xorg-configuration-file #:key (drivers '()) (resolutions '()) |
53 | (extra-config '())) | |
d1cdd7ba LC |
54 | "Return a configuration file for the Xorg server containing search paths for |
55 | all the common drivers. | |
f703413e LC |
56 | |
57 | @var{drivers} must be either the empty list, in which case Xorg chooses a | |
58 | graphics driver automatically, or a list of driver names that will be tried in | |
d2e59637 LC |
59 | this order---e.g., @code{(\"modesetting\" \"vesa\")}. |
60 | ||
61 | Likewise, when @var{resolutions} is the empty list, Xorg chooses an | |
62 | appropriate screen resolution; otherwise, it must be a list of | |
12422c9d LC |
63 | resolutions---e.g., @code{((1024 768) (640 480))}. |
64 | ||
65 | Last, @var{extra-config} is a list of strings or objects appended to the | |
66 | @code{text-file*} argument list. It is used to pass extra text to be added | |
67 | verbatim to the configuration file." | |
f703413e LC |
68 | (define (device-section driver) |
69 | (string-append " | |
70 | Section \"Device\" | |
71 | Identifier \"device-" driver "\" | |
72 | Driver \"" driver "\" | |
73 | EndSection")) | |
db4fdc04 | 74 | |
d2e59637 LC |
75 | (define (screen-section driver resolutions) |
76 | (string-append " | |
77 | Section \"Screen\" | |
78 | Identifier \"screen-" driver "\" | |
79 | Device \"device-" driver "\" | |
80 | SubSection \"Display\" | |
81 | Modes " | |
82 | (string-join (map (match-lambda | |
d1cdd7ba LC |
83 | ((x y) |
84 | (string-append "\"" (number->string x) | |
85 | "x" (number->string y) "\""))) | |
d2e59637 LC |
86 | resolutions)) " |
87 | EndSubSection | |
88 | EndSection")) | |
89 | ||
12422c9d | 90 | (apply text-file* "xserver.conf" " |
db4fdc04 | 91 | Section \"Files\" |
378377eb | 92 | FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\" |
db4fdc04 | 93 | ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\" |
0adb027b | 94 | ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\" |
3fc4eb21 | 95 | ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\" |
0adb027b LC |
96 | ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\" |
97 | ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\" | |
98 | ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\" | |
ca63770a | 99 | ModulePath \"" xf86-video-nouveau "/lib/xorg/modules/drivers\" |
0adb027b | 100 | ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\" |
2c37a34c | 101 | ModulePath \"" xf86-video-sis "/lib/xorg/modules/drivers\" |
c2ee19e6 LC |
102 | |
103 | # Libinput is the new thing and is recommended over evdev/synaptics | |
104 | # by those who know: | |
105 | # <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>. | |
106 | ModulePath \"" xf86-input-libinput "/lib/xorg/modules/input\" | |
107 | ||
073cd609 | 108 | ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\" |
db4fdc04 | 109 | ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\" |
0adb027b LC |
110 | ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\" |
111 | ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\" | |
db4fdc04 LC |
112 | ModulePath \"" xorg-server "/lib/xorg/modules\" |
113 | ModulePath \"" xorg-server "/lib/xorg/modules/extensions\" | |
114 | ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\" | |
115 | EndSection | |
116 | ||
117 | Section \"ServerFlags\" | |
e30442b5 | 118 | Option \"AllowMouseOpenFail\" \"on\" |
db4fdc04 | 119 | EndSection |
f703413e | 120 | " |
12422c9d | 121 | (string-join (map device-section drivers) "\n") "\n" |
d2e59637 LC |
122 | (string-join (map (cut screen-section <> resolutions) |
123 | drivers) | |
12422c9d LC |
124 | "\n") |
125 | ||
126 | "\n" | |
127 | extra-config)) | |
db4fdc04 | 128 | |
d1cdd7ba LC |
129 | (define* (xorg-start-command #:key |
130 | (guile (canonical-package guile-2.0)) | |
131 | configuration-file | |
132 | (xorg-server xorg-server)) | |
133 | "Return a derivation that builds a @var{guile} script to start the X server | |
134 | from @var{xorg-server}. @var{configuration-file} is the server configuration | |
135 | file or a derivation that builds it; when omitted, the result of | |
136 | @code{xorg-configuration-file} is used. | |
137 | ||
138 | Usually the X server is started by a login manager." | |
139 | (mlet %store-monad ((config (if configuration-file | |
140 | (return configuration-file) | |
141 | (xorg-configuration-file)))) | |
8779d342 | 142 | (define script |
db4fdc04 | 143 | ;; Write a small wrapper around the X server. |
8779d342 LC |
144 | #~(begin |
145 | (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri")) | |
146 | (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin")) | |
147 | ||
148 | (apply execl (string-append #$xorg-server "/bin/X") | |
91cc5aff | 149 | (string-append #$xorg-server "/bin/X") ;argv[0] |
594340bc | 150 | "-logverbose" "-verbose" |
8779d342 LC |
151 | "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb") |
152 | "-config" #$config | |
153 | "-nolisten" "tcp" "-terminate" | |
154 | ||
155 | ;; Note: SLiM and other display managers add the | |
156 | ;; '-auth' flag by themselves. | |
157 | (cdr (command-line))))) | |
158 | ||
159 | (gexp->script "start-xorg" script))) | |
db4fdc04 | 160 | |
9e4eddb4 | 161 | (define* (xinitrc #:key |
bdb36958 | 162 | (guile (canonical-package guile-2.0)) |
24d56899 SB |
163 | fallback-session) |
164 | "Return a system-wide xinitrc script that starts the specified X session, | |
165 | which should be passed to this script as the first argument. If not, the | |
166 | @var{fallback-session} will be used." | |
8779d342 LC |
167 | (define builder |
168 | #~(begin | |
169 | (use-modules (ice-9 match)) | |
170 | ||
16c33bfb LC |
171 | (define (close-all-fdes) |
172 | ;; Close all the open file descriptors except 0 to 2. | |
173 | (let loop ((fd 3)) | |
174 | (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX | |
175 | (false-if-exception (close-fdes fd)) | |
176 | (loop (+ 1 fd))))) | |
177 | ||
b2bd7c25 LC |
178 | (define (exec-from-login-shell command . args) |
179 | ;; Run COMMAND from a login shell so that it gets to see the same | |
180 | ;; environment variables that one gets when logging in on a tty, for | |
181 | ;; instance. | |
182 | (let* ((pw (getpw (getuid))) | |
e0b85670 SB |
183 | (shell (passwd:shell pw))) |
184 | ;; Close any open file descriptors. This is all the more | |
185 | ;; important that SLiM itself exec's us directly without closing | |
186 | ;; its own file descriptors! | |
187 | (close-all-fdes) | |
188 | ||
189 | ;; The '--login' option is supported at least by Bash and zsh. | |
190 | (execl shell shell "--login" "-c" | |
191 | (string-join (cons command args))))) | |
192 | ||
193 | (let* ((home (getenv "HOME")) | |
194 | (xsession-file (string-append home "/.xsession")) | |
195 | (session (match (command-line) | |
196 | ((_ x) x) | |
197 | (_ #$fallback-session)))) | |
198 | (if (file-exists? xsession-file) | |
199 | ;; Run ~/.xsession when it exists. | |
482dbe6a | 200 | (exec-from-login-shell xsession-file session) |
e0b85670 SB |
201 | ;; Otherwise, start the specified session. |
202 | (exec-from-login-shell session))))) | |
8779d342 | 203 | (gexp->script "xinitrc" builder)) |
9e4eddb4 | 204 | |
0ecc3bf3 LC |
205 | \f |
206 | ;;; | |
207 | ;;; SLiM log-in manager. | |
208 | ;;; | |
209 | ||
0ecc3bf3 LC |
210 | (define %default-slim-theme |
211 | ;; Theme based on work by Felipe López. | |
212 | #~(string-append #$%artwork-repository "/slim")) | |
213 | ||
214 | (define %default-slim-theme-name | |
215 | ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that | |
216 | ;; contains the actual theme files. | |
cf2abac8 | 217 | "0.x") |
0ecc3bf3 | 218 | |
db4fdc04 LC |
219 | (define* (slim-service #:key (slim slim) |
220 | (allow-empty-passwords? #t) auto-login? | |
221 | (default-user "") | |
0ecc3bf3 LC |
222 | (theme %default-slim-theme) |
223 | (theme-name %default-slim-theme-name) | |
db4fdc04 | 224 | (xauth xauth) (dmd dmd) (bash bash) |
24d56899 SB |
225 | (auto-login-session #~(string-append #$windowmaker |
226 | "/bin/wmaker")) | |
db4fdc04 LC |
227 | startx) |
228 | "Return a service that spawns the SLiM graphical login manager, which in | |
51da7ca0 LC |
229 | turn starts the X display server with @var{startx}, a command as returned by |
230 | @code{xorg-start-command}. | |
db4fdc04 | 231 | |
04e4e6ab LC |
232 | @cindex X session |
233 | ||
234 | SLiM automatically looks for session types described by the @file{.desktop} | |
235 | files in @file{/run/current-system/profile/share/xsessions} and allows users | |
236 | to choose a session from the log-in screen using @kbd{F1}. Packages such as | |
237 | @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files; | |
238 | adding them to the system-wide set of packages automatically makes them | |
239 | available at the log-in screen. | |
240 | ||
241 | In addition, @file{~/.xsession} files are honored. When available, | |
242 | @file{~/.xsession} must be an executable that starts a window manager | |
243 | and/or other X clients. | |
244 | ||
51da7ca0 LC |
245 | When @var{allow-empty-passwords?} is true, allow logins with an empty |
246 | password. When @var{auto-login?} is true, log in automatically as | |
24d56899 | 247 | @var{default-user} with @var{auto-login-session}. |
0ecc3bf3 LC |
248 | |
249 | If @var{theme} is @code{#f}, the use the default log-in theme; otherwise | |
250 | @var{theme} must be a gexp denoting the name of a directory containing the | |
251 | theme to use. In that case, @var{theme-name} specifies the name of the | |
4bd43bbe | 252 | theme." |
0ecc3bf3 | 253 | |
db4fdc04 | 254 | (define (slim.cfg) |
1eca6c36 LC |
255 | (mlet %store-monad ((startx (if startx |
256 | (return startx) | |
257 | (xorg-start-command))) | |
24d56899 | 258 | (xinitrc (xinitrc #:fallback-session |
4bd43bbe | 259 | auto-login-session))) |
db4fdc04 | 260 | (text-file* "slim.cfg" " |
b4140694 | 261 | default_path /run/current-system/profile/bin |
db4fdc04 LC |
262 | default_xserver " startx " |
263 | xserver_arguments :0 vt7 | |
264 | xauth_path " xauth "/bin/xauth | |
265 | authfile /var/run/slim.auth | |
266 | ||
267 | # The login command. '%session' is replaced by the chosen session name, one | |
268 | # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc. | |
057d6ce5 | 269 | login_cmd exec " xinitrc " %session |
4bd43bbe | 270 | sessiondir /run/current-system/profile/share/xsessions |
e1509174 | 271 | session_msg session (F1 to change): |
db4fdc04 LC |
272 | |
273 | halt_cmd " dmd "/sbin/halt | |
274 | reboot_cmd " dmd "/sbin/reboot | |
0ecc3bf3 LC |
275 | " |
276 | (if auto-login? | |
277 | (string-append "auto_login yes\ndefault_user " default-user "\n") | |
278 | "") | |
279 | (if theme-name | |
280 | (string-append "current_theme " theme-name "\n") | |
281 | "")))) | |
db4fdc04 | 282 | |
b5f4e686 | 283 | (mlet %store-monad ((slim.cfg (slim.cfg))) |
db4fdc04 LC |
284 | (return |
285 | (service | |
286 | (documentation "Xorg display server") | |
287 | (provision '(xorg-server)) | |
8dbab712 | 288 | (requirement '(user-processes host-name udev)) |
db4fdc04 | 289 | (start |
47b73c34 LC |
290 | #~(lambda () |
291 | ;; A stale lock file can prevent SLiM from starting, so remove it | |
292 | ;; to be on the safe side. | |
293 | (false-if-exception (delete-file "/var/run/slim.lock")) | |
294 | ||
295 | (fork+exec-command | |
296 | (list (string-append #$slim "/bin/slim") "-nodaemon") | |
297 | #:environment-variables | |
0ecc3bf3 LC |
298 | (list (string-append "SLIM_CFGFILE=" #$slim.cfg) |
299 | #$@(if theme | |
300 | (list #~(string-append "SLIM_THEMESDIR=" #$theme)) | |
301 | #~()))))) | |
b5f4e686 | 302 | (stop #~(make-kill-destructor)) |
db4fdc04 LC |
303 | (respawn? #t) |
304 | (pam-services | |
305 | ;; Tell PAM about 'slim'. | |
306 | (list (unix-pam-service | |
307 | "slim" | |
308 | #:allow-empty-passwords? allow-empty-passwords?))))))) | |
309 | ||
310 | ;;; xorg.scm ends here |