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) | |
db4fdc04 | 40 | #:export (xorg-start-command |
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 |
56 | from @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 | |
59 | graphics driver automatically, or a list of driver names that will be tried in | |
d2e59637 LC |
60 | this order---e.g., @code{(\"modesetting\" \"vesa\")}. |
61 | ||
62 | Likewise, when @var{resolutions} is the empty list, Xorg chooses an | |
63 | appropriate screen resolution; otherwise, it must be a list of | |
64 | resolutions---e.g., @code{((1024 768) (640 480))}." | |
f703413e LC |
65 | |
66 | (define (device-section driver) | |
67 | (string-append " | |
68 | Section \"Device\" | |
69 | Identifier \"device-" driver "\" | |
70 | Driver \"" driver "\" | |
71 | EndSection")) | |
db4fdc04 | 72 | |
d2e59637 LC |
73 | (define (screen-section driver resolutions) |
74 | (string-append " | |
75 | Section \"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 | |
86 | EndSection")) | |
87 | ||
db4fdc04 LC |
88 | (define (xserver.conf) |
89 | (text-file* "xserver.conf" " | |
90 | Section \"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\" | |
ca63770a | 98 | ModulePath \"" xf86-video-nouveau "/lib/xorg/modules/drivers\" |
0adb027b | 99 | ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\" |
2c37a34c | 100 | ModulePath \"" xf86-video-sis "/lib/xorg/modules/drivers\" |
073cd609 | 101 | ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\" |
db4fdc04 | 102 | ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\" |
0adb027b LC |
103 | ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\" |
104 | ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\" | |
db4fdc04 LC |
105 | ModulePath \"" xorg-server "/lib/xorg/modules\" |
106 | ModulePath \"" xorg-server "/lib/xorg/modules/extensions\" | |
107 | ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\" | |
108 | EndSection | |
109 | ||
110 | Section \"ServerFlags\" | |
e30442b5 | 111 | Option \"AllowMouseOpenFail\" \"on\" |
db4fdc04 | 112 | EndSection |
f703413e | 113 | " |
d2e59637 LC |
114 | (string-join (map device-section drivers) "\n") |
115 | (string-join (map (cut screen-section <> resolutions) | |
116 | drivers) | |
117 | "\n"))) | |
db4fdc04 | 118 | |
8779d342 LC |
119 | (mlet %store-monad ((config (xserver.conf))) |
120 | (define script | |
db4fdc04 | 121 | ;; Write a small wrapper around the X server. |
8779d342 LC |
122 | #~(begin |
123 | (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri")) | |
124 | (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin")) | |
125 | ||
126 | (apply execl (string-append #$xorg-server "/bin/X") | |
91cc5aff | 127 | (string-append #$xorg-server "/bin/X") ;argv[0] |
594340bc | 128 | "-logverbose" "-verbose" |
8779d342 LC |
129 | "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb") |
130 | "-config" #$config | |
131 | "-nolisten" "tcp" "-terminate" | |
132 | ||
133 | ;; Note: SLiM and other display managers add the | |
134 | ;; '-auth' flag by themselves. | |
135 | (cdr (command-line))))) | |
136 | ||
137 | (gexp->script "start-xorg" script))) | |
db4fdc04 | 138 | |
9e4eddb4 | 139 | (define* (xinitrc #:key |
bdb36958 | 140 | (guile (canonical-package guile-2.0)) |
24d56899 SB |
141 | fallback-session) |
142 | "Return a system-wide xinitrc script that starts the specified X session, | |
143 | which should be passed to this script as the first argument. If not, the | |
144 | @var{fallback-session} will be used." | |
8779d342 LC |
145 | (define builder |
146 | #~(begin | |
147 | (use-modules (ice-9 match)) | |
148 | ||
16c33bfb LC |
149 | (define (close-all-fdes) |
150 | ;; Close all the open file descriptors except 0 to 2. | |
151 | (let loop ((fd 3)) | |
152 | (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX | |
153 | (false-if-exception (close-fdes fd)) | |
154 | (loop (+ 1 fd))))) | |
155 | ||
b2bd7c25 LC |
156 | (define (exec-from-login-shell command . args) |
157 | ;; Run COMMAND from a login shell so that it gets to see the same | |
158 | ;; environment variables that one gets when logging in on a tty, for | |
159 | ;; instance. | |
160 | (let* ((pw (getpw (getuid))) | |
161 | (shell (passwd:shell pw)) | |
162 | (st (stat command #f))) | |
163 | (when (and st (not (zero? (logand (stat:mode st) #o100)))) | |
16c33bfb LC |
164 | ;; Close any open file descriptors. This is all the more |
165 | ;; important that SLiM itself exec's us directly without closing | |
166 | ;; its own file descriptors! | |
167 | (close-all-fdes) | |
168 | ||
b2bd7c25 LC |
169 | ;; The '--login' option is supported at least by Bash and zsh. |
170 | (execl shell shell "--login" "-c" | |
171 | (string-join (cons command args)))))) | |
172 | ||
24d56899 SB |
173 | (let ((home (getenv "HOME")) |
174 | (session (match (command-line) | |
175 | ((_ x) x) | |
176 | (_ #$fallback-session)))) | |
177 | ;; First, try to run ~/.xsession. | |
178 | (exec-from-login-shell (string-append home "/.xsession")) | |
179 | ;; Then try to start the specified session. | |
180 | (exec-from-login-shell session)))) | |
8779d342 | 181 | (gexp->script "xinitrc" builder)) |
9e4eddb4 | 182 | |
0ecc3bf3 LC |
183 | \f |
184 | ;;; | |
185 | ;;; SLiM log-in manager. | |
186 | ;;; | |
187 | ||
0ecc3bf3 LC |
188 | (define %default-slim-theme |
189 | ;; Theme based on work by Felipe López. | |
190 | #~(string-append #$%artwork-repository "/slim")) | |
191 | ||
192 | (define %default-slim-theme-name | |
193 | ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that | |
194 | ;; contains the actual theme files. | |
195 | "0.8") | |
196 | ||
db4fdc04 LC |
197 | (define* (slim-service #:key (slim slim) |
198 | (allow-empty-passwords? #t) auto-login? | |
199 | (default-user "") | |
0ecc3bf3 LC |
200 | (theme %default-slim-theme) |
201 | (theme-name %default-slim-theme-name) | |
db4fdc04 | 202 | (xauth xauth) (dmd dmd) (bash bash) |
24d56899 SB |
203 | (auto-login-session #~(string-append #$windowmaker |
204 | "/bin/wmaker")) | |
db4fdc04 LC |
205 | startx) |
206 | "Return a service that spawns the SLiM graphical login manager, which in | |
51da7ca0 LC |
207 | turn starts the X display server with @var{startx}, a command as returned by |
208 | @code{xorg-start-command}. | |
db4fdc04 | 209 | |
51da7ca0 LC |
210 | When @var{allow-empty-passwords?} is true, allow logins with an empty |
211 | password. When @var{auto-login?} is true, log in automatically as | |
24d56899 | 212 | @var{default-user} with @var{auto-login-session}. |
0ecc3bf3 LC |
213 | |
214 | If @var{theme} is @code{#f}, the use the default log-in theme; otherwise | |
215 | @var{theme} must be a gexp denoting the name of a directory containing the | |
216 | theme to use. In that case, @var{theme-name} specifies the name of the | |
4bd43bbe | 217 | theme." |
0ecc3bf3 | 218 | |
db4fdc04 | 219 | (define (slim.cfg) |
9e4eddb4 | 220 | (mlet %store-monad ((startx (or startx (xorg-start-command))) |
24d56899 | 221 | (xinitrc (xinitrc #:fallback-session |
4bd43bbe | 222 | auto-login-session))) |
db4fdc04 | 223 | (text-file* "slim.cfg" " |
b4140694 | 224 | default_path /run/current-system/profile/bin |
db4fdc04 LC |
225 | default_xserver " startx " |
226 | xserver_arguments :0 vt7 | |
227 | xauth_path " xauth "/bin/xauth | |
228 | authfile /var/run/slim.auth | |
229 | ||
230 | # The login command. '%session' is replaced by the chosen session name, one | |
231 | # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc. | |
057d6ce5 | 232 | login_cmd exec " xinitrc " %session |
4bd43bbe | 233 | sessiondir /run/current-system/profile/share/xsessions |
e1509174 | 234 | session_msg session (F1 to change): |
db4fdc04 LC |
235 | |
236 | halt_cmd " dmd "/sbin/halt | |
237 | reboot_cmd " dmd "/sbin/reboot | |
0ecc3bf3 LC |
238 | " |
239 | (if auto-login? | |
240 | (string-append "auto_login yes\ndefault_user " default-user "\n") | |
241 | "") | |
242 | (if theme-name | |
243 | (string-append "current_theme " theme-name "\n") | |
244 | "")))) | |
db4fdc04 | 245 | |
b5f4e686 | 246 | (mlet %store-monad ((slim.cfg (slim.cfg))) |
db4fdc04 LC |
247 | (return |
248 | (service | |
249 | (documentation "Xorg display server") | |
250 | (provision '(xorg-server)) | |
8dbab712 | 251 | (requirement '(user-processes host-name udev)) |
db4fdc04 | 252 | (start |
47b73c34 LC |
253 | #~(lambda () |
254 | ;; A stale lock file can prevent SLiM from starting, so remove it | |
255 | ;; to be on the safe side. | |
256 | (false-if-exception (delete-file "/var/run/slim.lock")) | |
257 | ||
258 | (fork+exec-command | |
259 | (list (string-append #$slim "/bin/slim") "-nodaemon") | |
260 | #:environment-variables | |
0ecc3bf3 LC |
261 | (list (string-append "SLIM_CFGFILE=" #$slim.cfg) |
262 | #$@(if theme | |
263 | (list #~(string-append "SLIM_THEMESDIR=" #$theme)) | |
264 | #~()))))) | |
b5f4e686 | 265 | (stop #~(make-kill-destructor)) |
db4fdc04 LC |
266 | (respawn? #t) |
267 | (pam-services | |
268 | ;; Tell PAM about 'slim'. | |
269 | (list (unix-pam-service | |
270 | "slim" | |
271 | #:allow-empty-passwords? allow-empty-passwords?))))))) | |
272 | ||
273 | ;;; xorg.scm ends here |