1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (gnu services xorg)
21 #:use-module (gnu artwork)
22 #:use-module (gnu services)
23 #:use-module (gnu services dmd)
24 #:use-module (gnu system linux) ; 'pam-service'
25 #:use-module ((gnu packages base) #:select (canonical-package))
26 #:use-module (gnu packages guile)
27 #:use-module (gnu packages xorg)
28 #:use-module (gnu packages gl)
29 #:use-module (gnu packages slim)
30 #:use-module (gnu packages gnustep)
31 #:use-module (gnu packages admin)
32 #:use-module (gnu packages bash)
33 #:use-module (guix gexp)
34 #:use-module (guix store)
35 #:use-module (guix packages)
36 #:use-module (guix derivations)
37 #:use-module (guix records)
38 #:use-module (srfi srfi-1)
39 #:use-module (srfi srfi-9)
40 #:use-module (srfi srfi-26)
41 #:use-module (ice-9 match)
42 #:export (xorg-configuration-file
45 %default-slim-theme-name
48 screen-locker-service-type
49 screen-locker-service))
53 ;;; Services that relate to the X Window System.
57 (define* (xorg-configuration-file #:key (drivers '()) (resolutions '())
59 "Return a configuration file for the Xorg server containing search paths for
60 all the common drivers.
62 @var{drivers} must be either the empty list, in which case Xorg chooses a
63 graphics driver automatically, or a list of driver names that will be tried in
64 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
66 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
67 appropriate screen resolution; otherwise, it must be a list of
68 resolutions---e.g., @code{((1024 768) (640 480))}.
70 Last, @var{extra-config} is a list of strings or objects appended to the
71 @code{mixed-text-file} argument list. It is used to pass extra text to be
72 added verbatim to the configuration file."
73 (define (device-section driver)
76 Identifier \"device-" driver "\"
80 (define (screen-section driver resolutions)
83 Identifier \"screen-" driver "\"
84 Device \"device-" driver "\"
85 SubSection \"Display\"
87 (string-join (map (match-lambda
89 (string-append "\"" (number->string x)
90 "x" (number->string y) "\"")))
95 (apply mixed-text-file "xserver.conf" "
97 FontPath \"" font-alias "/share/fonts/X11/75dpi\"
98 FontPath \"" font-alias "/share/fonts/X11/100dpi\"
99 FontPath \"" font-alias "/share/fonts/X11/misc\"
100 FontPath \"" font-alias "/share/fonts/X11/cyrillic\"
101 FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\"
102 ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
103 ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\"
104 ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\"
105 ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\"
106 ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\"
107 ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\"
108 ModulePath \"" xf86-video-nouveau "/lib/xorg/modules/drivers\"
109 ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
110 ModulePath \"" xf86-video-sis "/lib/xorg/modules/drivers\"
112 # Libinput is the new thing and is recommended over evdev/synaptics
114 # <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
115 ModulePath \"" xf86-input-libinput "/lib/xorg/modules/input\"
117 ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\"
118 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
119 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
120 ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
121 ModulePath \"" xorg-server "/lib/xorg/modules\"
122 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
123 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
126 Section \"ServerFlags\"
127 Option \"AllowMouseOpenFail\" \"on\"
130 (string-join (map device-section drivers) "\n") "\n"
131 (string-join (map (cut screen-section <> resolutions)
138 (define* (xorg-start-command #:key
139 (guile (canonical-package guile-2.0))
140 (configuration-file (xorg-configuration-file))
141 (xorg-server xorg-server))
142 "Return a derivation that builds a @var{guile} script to start the X server
143 from @var{xorg-server}. @var{configuration-file} is the server configuration
144 file or a derivation that builds it; when omitted, the result of
145 @code{xorg-configuration-file} is used.
147 Usually the X server is started by a login manager."
149 ;; Write a small wrapper around the X server.
151 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
152 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
154 (apply execl (string-append #$xorg-server "/bin/X")
155 (string-append #$xorg-server "/bin/X") ;argv[0]
156 "-logverbose" "-verbose"
157 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
158 "-config" #$configuration-file
159 "-nolisten" "tcp" "-terminate"
161 ;; Note: SLiM and other display managers add the
162 ;; '-auth' flag by themselves.
163 (cdr (command-line)))))
165 (program-file "start-xorg" exp))
167 (define* (xinitrc #:key
168 (guile (canonical-package guile-2.0))
170 "Return a system-wide xinitrc script that starts the specified X session,
171 which should be passed to this script as the first argument. If not, the
172 @var{fallback-session} will be used."
175 (use-modules (ice-9 match))
177 (define (close-all-fdes)
178 ;; Close all the open file descriptors except 0 to 2.
180 (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
181 (false-if-exception (close-fdes fd))
184 (define (exec-from-login-shell command . args)
185 ;; Run COMMAND from a login shell so that it gets to see the same
186 ;; environment variables that one gets when logging in on a tty, for
188 (let* ((pw (getpw (getuid)))
189 (shell (passwd:shell pw)))
190 ;; Close any open file descriptors. This is all the more
191 ;; important that SLiM itself exec's us directly without closing
192 ;; its own file descriptors!
195 ;; The '--login' option is supported at least by Bash and zsh.
196 (execl shell shell "--login" "-c"
197 (string-join (cons command args)))))
199 (let* ((home (getenv "HOME"))
200 (xsession-file (string-append home "/.xsession"))
201 (session (match (command-line)
203 (_ #$fallback-session))))
204 (if (file-exists? xsession-file)
205 ;; Run ~/.xsession when it exists.
206 (exec-from-login-shell xsession-file session)
207 ;; Otherwise, start the specified session.
208 (exec-from-login-shell session)))))
209 (program-file "xinitrc" builder))
213 ;;; SLiM log-in manager.
216 (define %default-slim-theme
217 ;; Theme based on work by Felipe López.
218 #~(string-append #$%artwork-repository "/slim"))
220 (define %default-slim-theme-name
221 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
222 ;; contains the actual theme files.
225 (define-record-type* <slim-configuration>
226 slim-configuration make-slim-configuration
228 (slim slim-configuration-slim
230 (allow-empty-passwords? slim-configuration-allow-empty-passwords?)
231 (auto-login? slim-configuration-auto-login?)
232 (default-user slim-configuration-default-user)
233 (theme slim-configuration-theme)
234 (theme-name slim-configuration-theme-name)
235 (xauth slim-configuration-xauth
237 (dmd slim-configuration-dmd
239 (bash slim-configuration-bash
241 (auto-login-session slim-configuration-auto-login-session)
242 (startx slim-configuration-startx))
244 (define (slim-pam-service config)
245 "Return a PAM service for @command{slim}."
246 (list (unix-pam-service
248 #:allow-empty-passwords?
249 (slim-configuration-allow-empty-passwords? config))))
251 (define (slim-dmd-service config)
253 (let ((xinitrc (xinitrc #:fallback-session
254 (slim-configuration-auto-login-session config)))
255 (slim (slim-configuration-slim config))
256 (xauth (slim-configuration-xauth config))
257 (startx (slim-configuration-startx config))
258 (dmd (slim-configuration-dmd config))
259 (theme-name (slim-configuration-theme-name config)))
260 (mixed-text-file "slim.cfg" "
261 default_path /run/current-system/profile/bin
262 default_xserver " startx "
263 xserver_arguments :0 vt7
264 xauth_path " xauth "/bin/xauth
265 authfile /var/run/slim.auth
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.
269 login_cmd exec " xinitrc " %session
270 sessiondir /run/current-system/profile/share/xsessions
271 session_msg session (F1 to change):
273 halt_cmd " dmd "/sbin/halt
274 reboot_cmd " dmd "/sbin/reboot\n"
275 (if (slim-configuration-auto-login? config)
276 (string-append "auto_login yes\ndefault_user "
277 (slim-configuration-default-user config) "\n")
280 (string-append "current_theme " theme-name "\n")
284 (slim-configuration-theme config))
287 (documentation "Xorg display server")
288 (provision '(xorg-server))
289 (requirement '(user-processes host-name udev))
292 ;; A stale lock file can prevent SLiM from starting, so remove it to
293 ;; be on the safe side.
294 (false-if-exception (delete-file "/var/run/slim.lock"))
297 (list (string-append #$slim "/bin/slim") "-nodaemon")
298 #:environment-variables
299 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
301 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
303 (stop #~(make-kill-destructor))
306 (define slim-service-type
307 (service-type (name 'slim)
309 (list (service-extension dmd-root-service-type
311 (service-extension pam-root-service-type
314 ;; Unconditionally add xterm to the system profile, to
315 ;; avoid bad surprises.
316 (service-extension profile-service-type
317 (const (list xterm)))))))
319 (define* (slim-service #:key (slim slim)
320 (allow-empty-passwords? #t) auto-login?
322 (theme %default-slim-theme)
323 (theme-name %default-slim-theme-name)
324 (xauth xauth) (dmd dmd) (bash bash)
325 (auto-login-session #~(string-append #$windowmaker
327 (startx (xorg-start-command)))
328 "Return a service that spawns the SLiM graphical login manager, which in
329 turn starts the X display server with @var{startx}, a command as returned by
330 @code{xorg-start-command}.
334 SLiM automatically looks for session types described by the @file{.desktop}
335 files in @file{/run/current-system/profile/share/xsessions} and allows users
336 to choose a session from the log-in screen using @kbd{F1}. Packages such as
337 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
338 adding them to the system-wide set of packages automatically makes them
339 available at the log-in screen.
341 In addition, @file{~/.xsession} files are honored. When available,
342 @file{~/.xsession} must be an executable that starts a window manager
343 and/or other X clients.
345 When @var{allow-empty-passwords?} is true, allow logins with an empty
346 password. When @var{auto-login?} is true, log in automatically as
347 @var{default-user} with @var{auto-login-session}.
349 If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
350 @var{theme} must be a gexp denoting the name of a directory containing the
351 theme to use. In that case, @var{theme-name} specifies the name of the
353 (service slim-service-type
356 (allow-empty-passwords? allow-empty-passwords?)
357 (auto-login? auto-login?) (default-user default-user)
358 (theme theme) (theme-name theme-name)
359 (xauth xauth) (dmd dmd) (bash bash)
360 (auto-login-session auto-login-session)
365 ;;; Screen lockers & co.
368 (define-record-type <screen-locker>
369 (screen-locker name program empty?)
371 (name screen-locker-name) ;string
372 (program screen-locker-program) ;gexp
373 (empty? screen-locker-allows-empty-passwords?)) ;Boolean
375 (define screen-locker-pam-services
377 (($ <screen-locker> name _ empty?)
378 (list (unix-pam-service name
379 #:allow-empty-passwords? empty?)))))
381 (define screen-locker-setuid-programs
382 (compose list screen-locker-program))
384 (define screen-locker-service-type
385 (service-type (name 'screen-locker)
387 (list (service-extension pam-root-service-type
388 screen-locker-pam-services)
389 (service-extension setuid-program-service-type
390 screen-locker-setuid-programs)))))
392 (define* (screen-locker-service package
394 (program (package-name package))
395 #:key allow-empty-passwords?)
396 "Add @var{package}, a package for a screen-locker or screen-saver whose
397 command is @var{program}, to the set of setuid programs and add a PAM entry
401 (screen-locker-service xlockmore \"xlock\")
404 makes the good ol' XlockMore usable."
405 (service screen-locker-service-type
406 (screen-locker program
407 #~(string-append #$package
408 #$(string-append "/bin/" program))
409 allow-empty-passwords?)))
411 ;;; xorg.scm ends here