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\" |
073cd609 | 102 | ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\" |
db4fdc04 | 103 | ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\" |
0adb027b LC |
104 | ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\" |
105 | ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\" | |
db4fdc04 LC |
106 | ModulePath \"" xorg-server "/lib/xorg/modules\" |
107 | ModulePath \"" xorg-server "/lib/xorg/modules/extensions\" | |
108 | ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\" | |
109 | EndSection | |
110 | ||
111 | Section \"ServerFlags\" | |
e30442b5 | 112 | Option \"AllowMouseOpenFail\" \"on\" |
db4fdc04 | 113 | EndSection |
f703413e | 114 | " |
12422c9d | 115 | (string-join (map device-section drivers) "\n") "\n" |
d2e59637 LC |
116 | (string-join (map (cut screen-section <> resolutions) |
117 | drivers) | |
12422c9d LC |
118 | "\n") |
119 | ||
120 | "\n" | |
121 | extra-config)) | |
db4fdc04 | 122 | |
d1cdd7ba LC |
123 | (define* (xorg-start-command #:key |
124 | (guile (canonical-package guile-2.0)) | |
125 | configuration-file | |
126 | (xorg-server xorg-server)) | |
127 | "Return a derivation that builds a @var{guile} script to start the X server | |
128 | from @var{xorg-server}. @var{configuration-file} is the server configuration | |
129 | file or a derivation that builds it; when omitted, the result of | |
130 | @code{xorg-configuration-file} is used. | |
131 | ||
132 | Usually the X server is started by a login manager." | |
133 | (mlet %store-monad ((config (if configuration-file | |
134 | (return configuration-file) | |
135 | (xorg-configuration-file)))) | |
8779d342 | 136 | (define script |
db4fdc04 | 137 | ;; Write a small wrapper around the X server. |
8779d342 LC |
138 | #~(begin |
139 | (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri")) | |
140 | (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin")) | |
141 | ||
142 | (apply execl (string-append #$xorg-server "/bin/X") | |
91cc5aff | 143 | (string-append #$xorg-server "/bin/X") ;argv[0] |
594340bc | 144 | "-logverbose" "-verbose" |
8779d342 LC |
145 | "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb") |
146 | "-config" #$config | |
147 | "-nolisten" "tcp" "-terminate" | |
148 | ||
149 | ;; Note: SLiM and other display managers add the | |
150 | ;; '-auth' flag by themselves. | |
151 | (cdr (command-line))))) | |
152 | ||
153 | (gexp->script "start-xorg" script))) | |
db4fdc04 | 154 | |
9e4eddb4 | 155 | (define* (xinitrc #:key |
bdb36958 | 156 | (guile (canonical-package guile-2.0)) |
24d56899 SB |
157 | fallback-session) |
158 | "Return a system-wide xinitrc script that starts the specified X session, | |
159 | which should be passed to this script as the first argument. If not, the | |
160 | @var{fallback-session} will be used." | |
8779d342 LC |
161 | (define builder |
162 | #~(begin | |
163 | (use-modules (ice-9 match)) | |
164 | ||
16c33bfb LC |
165 | (define (close-all-fdes) |
166 | ;; Close all the open file descriptors except 0 to 2. | |
167 | (let loop ((fd 3)) | |
168 | (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX | |
169 | (false-if-exception (close-fdes fd)) | |
170 | (loop (+ 1 fd))))) | |
171 | ||
b2bd7c25 LC |
172 | (define (exec-from-login-shell command . args) |
173 | ;; Run COMMAND from a login shell so that it gets to see the same | |
174 | ;; environment variables that one gets when logging in on a tty, for | |
175 | ;; instance. | |
176 | (let* ((pw (getpw (getuid))) | |
e0b85670 SB |
177 | (shell (passwd:shell pw))) |
178 | ;; Close any open file descriptors. This is all the more | |
179 | ;; important that SLiM itself exec's us directly without closing | |
180 | ;; its own file descriptors! | |
181 | (close-all-fdes) | |
182 | ||
183 | ;; The '--login' option is supported at least by Bash and zsh. | |
184 | (execl shell shell "--login" "-c" | |
185 | (string-join (cons command args))))) | |
186 | ||
187 | (let* ((home (getenv "HOME")) | |
188 | (xsession-file (string-append home "/.xsession")) | |
189 | (session (match (command-line) | |
190 | ((_ x) x) | |
191 | (_ #$fallback-session)))) | |
192 | (if (file-exists? xsession-file) | |
193 | ;; Run ~/.xsession when it exists. | |
482dbe6a | 194 | (exec-from-login-shell xsession-file session) |
e0b85670 SB |
195 | ;; Otherwise, start the specified session. |
196 | (exec-from-login-shell session))))) | |
8779d342 | 197 | (gexp->script "xinitrc" builder)) |
9e4eddb4 | 198 | |
0ecc3bf3 LC |
199 | \f |
200 | ;;; | |
201 | ;;; SLiM log-in manager. | |
202 | ;;; | |
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. | |
cf2abac8 | 211 | "0.x") |
0ecc3bf3 | 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 | (auto-login-session #~(string-append #$windowmaker |
220 | "/bin/wmaker")) | |
db4fdc04 LC |
221 | startx) |
222 | "Return a service that spawns the SLiM graphical login manager, which in | |
51da7ca0 LC |
223 | turn starts the X display server with @var{startx}, a command as returned by |
224 | @code{xorg-start-command}. | |
db4fdc04 | 225 | |
04e4e6ab LC |
226 | @cindex X session |
227 | ||
228 | SLiM automatically looks for session types described by the @file{.desktop} | |
229 | files in @file{/run/current-system/profile/share/xsessions} and allows users | |
230 | to choose a session from the log-in screen using @kbd{F1}. Packages such as | |
231 | @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files; | |
232 | adding them to the system-wide set of packages automatically makes them | |
233 | available at the log-in screen. | |
234 | ||
235 | In addition, @file{~/.xsession} files are honored. When available, | |
236 | @file{~/.xsession} must be an executable that starts a window manager | |
237 | and/or other X clients. | |
238 | ||
51da7ca0 LC |
239 | When @var{allow-empty-passwords?} is true, allow logins with an empty |
240 | password. When @var{auto-login?} is true, log in automatically as | |
24d56899 | 241 | @var{default-user} with @var{auto-login-session}. |
0ecc3bf3 LC |
242 | |
243 | If @var{theme} is @code{#f}, the use the default log-in theme; otherwise | |
244 | @var{theme} must be a gexp denoting the name of a directory containing the | |
245 | theme to use. In that case, @var{theme-name} specifies the name of the | |
4bd43bbe | 246 | theme." |
0ecc3bf3 | 247 | |
db4fdc04 | 248 | (define (slim.cfg) |
1eca6c36 LC |
249 | (mlet %store-monad ((startx (if startx |
250 | (return startx) | |
251 | (xorg-start-command))) | |
24d56899 | 252 | (xinitrc (xinitrc #:fallback-session |
4bd43bbe | 253 | auto-login-session))) |
db4fdc04 | 254 | (text-file* "slim.cfg" " |
b4140694 | 255 | default_path /run/current-system/profile/bin |
db4fdc04 LC |
256 | default_xserver " startx " |
257 | xserver_arguments :0 vt7 | |
258 | xauth_path " xauth "/bin/xauth | |
259 | authfile /var/run/slim.auth | |
260 | ||
261 | # The login command. '%session' is replaced by the chosen session name, one | |
262 | # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc. | |
057d6ce5 | 263 | login_cmd exec " xinitrc " %session |
4bd43bbe | 264 | sessiondir /run/current-system/profile/share/xsessions |
e1509174 | 265 | session_msg session (F1 to change): |
db4fdc04 LC |
266 | |
267 | halt_cmd " dmd "/sbin/halt | |
268 | reboot_cmd " dmd "/sbin/reboot | |
0ecc3bf3 LC |
269 | " |
270 | (if auto-login? | |
271 | (string-append "auto_login yes\ndefault_user " default-user "\n") | |
272 | "") | |
273 | (if theme-name | |
274 | (string-append "current_theme " theme-name "\n") | |
275 | "")))) | |
db4fdc04 | 276 | |
b5f4e686 | 277 | (mlet %store-monad ((slim.cfg (slim.cfg))) |
db4fdc04 LC |
278 | (return |
279 | (service | |
280 | (documentation "Xorg display server") | |
281 | (provision '(xorg-server)) | |
8dbab712 | 282 | (requirement '(user-processes host-name udev)) |
db4fdc04 | 283 | (start |
47b73c34 LC |
284 | #~(lambda () |
285 | ;; A stale lock file can prevent SLiM from starting, so remove it | |
286 | ;; to be on the safe side. | |
287 | (false-if-exception (delete-file "/var/run/slim.lock")) | |
288 | ||
289 | (fork+exec-command | |
290 | (list (string-append #$slim "/bin/slim") "-nodaemon") | |
291 | #:environment-variables | |
0ecc3bf3 LC |
292 | (list (string-append "SLIM_CFGFILE=" #$slim.cfg) |
293 | #$@(if theme | |
294 | (list #~(string-append "SLIM_THEMESDIR=" #$theme)) | |
295 | #~()))))) | |
b5f4e686 | 296 | (stop #~(make-kill-destructor)) |
db4fdc04 LC |
297 | (respawn? #t) |
298 | (pam-services | |
299 | ;; Tell PAM about 'slim'. | |
300 | (list (unix-pam-service | |
301 | "slim" | |
302 | #:allow-empty-passwords? allow-empty-passwords?))))))) | |
303 | ||
304 | ;;; xorg.scm ends here |