gnu: Add xf86-video-modesetting.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu services xorg)
20 #:use-module (gnu services)
21 #:use-module (gnu system linux) ; 'pam-service'
22 #:use-module ((gnu packages base) #:select (canonical-package))
23 #:use-module (gnu packages guile)
24 #:use-module (gnu packages xorg)
25 #:use-module (gnu packages gl)
26 #:use-module (gnu packages slim)
27 #:use-module (gnu packages ratpoison)
28 #:use-module (gnu packages gnustep)
29 #:use-module (gnu packages admin)
30 #:use-module (gnu packages bash)
31 #:use-module (guix gexp)
32 #:use-module (guix monads)
33 #:use-module (guix derivations)
34 #:export (xorg-start-command
35 slim-service))
36
37 ;;; Commentary:
38 ;;;
39 ;;; Services that relate to the X Window System.
40 ;;;
41 ;;; Code:
42
43 (define* (xorg-start-command #:key
44 (guile (canonical-package guile-2.0))
45 (xorg-server xorg-server))
46 "Return a derivation that builds a GUILE script to start the X server from
47 XORG-SERVER. Usually the X server is started by a login manager."
48
49 (define (xserver.conf)
50 (text-file* "xserver.conf" "
51 Section \"Files\"
52 FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\"
53 ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
54 ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\"
55 # FIXME: Commented out due to libdrm incompatibility.
56 # ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\"
57 ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\"
58 ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\"
59 ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\"
60 ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
61 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
62 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
63 ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
64 ModulePath \"" xorg-server "/lib/xorg/modules\"
65 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
66 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
67 EndSection
68
69 Section \"ServerFlags\"
70 Option \"AllowMouseOpenFail\" \"on""
71 EndSection
72 "))
73
74 (mlet %store-monad ((config (xserver.conf)))
75 (define script
76 ;; Write a small wrapper around the X server.
77 #~(begin
78 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
79 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
80
81 (apply execl (string-append #$xorg-server "/bin/X")
82 "-ac" "-logverbose" "-verbose"
83 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
84 "-config" #$config
85 "-nolisten" "tcp" "-terminate"
86
87 ;; Note: SLiM and other display managers add the
88 ;; '-auth' flag by themselves.
89 (cdr (command-line)))))
90
91 (gexp->script "start-xorg" script)))
92
93 (define* (xinitrc #:key
94 (guile (canonical-package guile-2.0))
95 (ratpoison ratpoison)
96 (windowmaker windowmaker))
97 "Return a system-wide xinitrc script that starts the specified X session."
98 (define builder
99 #~(begin
100 (use-modules (ice-9 match))
101
102 ;; First, try to run ~/.xsession.
103 (let* ((home (getenv "HOME"))
104 (file (string-append home "/.xsession")))
105 (false-if-exception (execl file file)))
106
107 ;; Then try a pre-configured session type.
108 (match (command-line)
109 ((_ "ratpoison")
110 (execl (string-append #$ratpoison "/bin/ratpoison")))
111 (_
112 (execl (string-append #$windowmaker "/bin/wmaker"))))))
113
114 (gexp->script "xinitrc" builder))
115
116 (define* (slim-service #:key (slim slim)
117 (allow-empty-passwords? #t) auto-login?
118 (default-user "")
119 (xauth xauth) (dmd dmd) (bash bash)
120 startx)
121 "Return a service that spawns the SLiM graphical login manager, which in
122 turn starts the X display server with @var{startx}, a command as returned by
123 @code{xorg-start-command}.
124
125 When @var{allow-empty-passwords?} is true, allow logins with an empty
126 password. When @var{auto-login?} is true, log in automatically as
127 @var{default-user}."
128 (define (slim.cfg)
129 (mlet %store-monad ((startx (or startx (xorg-start-command)))
130 (xinitrc (xinitrc)))
131 (text-file* "slim.cfg" "
132 default_path /run/current-system/profile/bin
133 default_xserver " startx "
134 xserver_arguments :0 vt7
135 xauth_path " xauth "/bin/xauth
136 authfile /var/run/slim.auth
137
138 # The login command. '%session' is replaced by the chosen session name, one
139 # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
140 login_cmd exec " xinitrc " %session
141 sessions wmaker,ratpoison
142
143 halt_cmd " dmd "/sbin/halt
144 reboot_cmd " dmd "/sbin/reboot
145 " (if auto-login?
146 (string-append "auto_login yes\ndefault_user " default-user)
147 ""))))
148
149 (mlet %store-monad ((slim.cfg (slim.cfg)))
150 (return
151 (service
152 (documentation "Xorg display server")
153 (provision '(xorg-server))
154 (requirement '(user-processes host-name udev))
155 (start
156 #~(lambda ()
157 ;; A stale lock file can prevent SLiM from starting, so remove it
158 ;; to be on the safe side.
159 (false-if-exception (delete-file "/var/run/slim.lock"))
160
161 (fork+exec-command
162 (list (string-append #$slim "/bin/slim") "-nodaemon")
163 #:environment-variables
164 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)))))
165 (stop #~(make-kill-destructor))
166 (respawn? #t)
167 (pam-services
168 ;; Tell PAM about 'slim'.
169 (list (unix-pam-service
170 "slim"
171 #:allow-empty-passwords? allow-empty-passwords?)))))))
172
173 ;;; xorg.scm ends here