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