gnu: xorg: Add SLiM theme based on work by Felipe López.
[jackhill/guix/guix.git] / gnu / services / xorg.scm
CommitLineData
db4fdc04
LC
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)
0ecc3bf3
LC
20 #:use-module (guix packages)
21 #:use-module (guix git-download)
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)
29 #:use-module (gnu packages ratpoison)
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)
db4fdc04
LC
34 #:use-module (guix monads)
35 #:use-module (guix derivations)
d2e59637
LC
36 #:use-module (srfi srfi-1)
37 #:use-module (srfi srfi-26)
38 #:use-module (ice-9 match)
db4fdc04 39 #:export (xorg-start-command
0ecc3bf3
LC
40
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
56from @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
59graphics driver automatically, or a list of driver names that will be tried in
d2e59637
LC
60this order---e.g., @code{(\"modesetting\" \"vesa\")}.
61
62Likewise, when @var{resolutions} is the empty list, Xorg chooses an
63appropriate screen resolution; otherwise, it must be a list of
64resolutions---e.g., @code{((1024 768) (640 480))}."
f703413e
LC
65
66 (define (device-section driver)
67 (string-append "
68Section \"Device\"
69 Identifier \"device-" driver "\"
70 Driver \"" driver "\"
71EndSection"))
db4fdc04 72
d2e59637
LC
73 (define (screen-section driver resolutions)
74 (string-append "
75Section \"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
86EndSection"))
87
db4fdc04
LC
88 (define (xserver.conf)
89 (text-file* "xserver.conf" "
90Section \"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\"
41d07f5e
LC
94# FIXME: Commented out due to libdrm incompatibility.
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\"
99 ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
db4fdc04 100 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
0adb027b
LC
101 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
102 ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
db4fdc04
LC
103 ModulePath \"" xorg-server "/lib/xorg/modules\"
104 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
105 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
106EndSection
107
108Section \"ServerFlags\"
e30442b5 109 Option \"AllowMouseOpenFail\" \"on\"
db4fdc04 110EndSection
f703413e 111"
d2e59637
LC
112 (string-join (map device-section drivers) "\n")
113 (string-join (map (cut screen-section <> resolutions)
114 drivers)
115 "\n")))
db4fdc04 116
8779d342
LC
117 (mlet %store-monad ((config (xserver.conf)))
118 (define script
db4fdc04 119 ;; Write a small wrapper around the X server.
8779d342
LC
120 #~(begin
121 (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
122 (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
123
124 (apply execl (string-append #$xorg-server "/bin/X")
91cc5aff 125 (string-append #$xorg-server "/bin/X") ;argv[0]
594340bc 126 "-logverbose" "-verbose"
8779d342
LC
127 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
128 "-config" #$config
129 "-nolisten" "tcp" "-terminate"
130
131 ;; Note: SLiM and other display managers add the
132 ;; '-auth' flag by themselves.
133 (cdr (command-line)))))
134
135 (gexp->script "start-xorg" script)))
db4fdc04 136
9e4eddb4 137(define* (xinitrc #:key
bdb36958 138 (guile (canonical-package guile-2.0))
9e4eddb4
LC
139 (ratpoison ratpoison)
140 (windowmaker windowmaker))
141 "Return a system-wide xinitrc script that starts the specified X session."
8779d342
LC
142 (define builder
143 #~(begin
144 (use-modules (ice-9 match))
145
d9372161
LC
146 ;; First, try to run ~/.xsession.
147 (let* ((home (getenv "HOME"))
148 (file (string-append home "/.xsession")))
149 (false-if-exception (execl file file)))
150
151 ;; Then try a pre-configured session type.
8779d342
LC
152 (match (command-line)
153 ((_ "ratpoison")
154 (execl (string-append #$ratpoison "/bin/ratpoison")))
155 (_
156 (execl (string-append #$windowmaker "/bin/wmaker"))))))
157
158 (gexp->script "xinitrc" builder))
9e4eddb4 159
0ecc3bf3
LC
160\f
161;;;
162;;; SLiM log-in manager.
163;;;
164
165(define %artwork-repository
166 (origin
167 (method git-fetch)
168 (uri (git-reference
169 (url "git://git.savannah.gnu.org/guix/guix-artwork.git")
170 (commit "71d77b1")))
171 (sha256
172 (base32
173 "03j0fwh6j5knzbfjj3cs0a30cssy706p18b8x7d1p91p29hlzjif"))))
174
175(define %default-slim-theme
176 ;; Theme based on work by Felipe López.
177 #~(string-append #$%artwork-repository "/slim"))
178
179(define %default-slim-theme-name
180 ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
181 ;; contains the actual theme files.
182 "0.8")
183
db4fdc04
LC
184(define* (slim-service #:key (slim slim)
185 (allow-empty-passwords? #t) auto-login?
186 (default-user "")
0ecc3bf3
LC
187 (theme %default-slim-theme)
188 (theme-name %default-slim-theme-name)
db4fdc04
LC
189 (xauth xauth) (dmd dmd) (bash bash)
190 startx)
191 "Return a service that spawns the SLiM graphical login manager, which in
51da7ca0
LC
192turn starts the X display server with @var{startx}, a command as returned by
193@code{xorg-start-command}.
db4fdc04 194
51da7ca0
LC
195When @var{allow-empty-passwords?} is true, allow logins with an empty
196password. When @var{auto-login?} is true, log in automatically as
0ecc3bf3
LC
197@var{default-user}.
198
199If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
200@var{theme} must be a gexp denoting the name of a directory containing the
201theme to use. In that case, @var{theme-name} specifies the name of the
202theme."
203
db4fdc04 204 (define (slim.cfg)
9e4eddb4
LC
205 (mlet %store-monad ((startx (or startx (xorg-start-command)))
206 (xinitrc (xinitrc)))
db4fdc04 207 (text-file* "slim.cfg" "
b4140694 208default_path /run/current-system/profile/bin
db4fdc04
LC
209default_xserver " startx "
210xserver_arguments :0 vt7
211xauth_path " xauth "/bin/xauth
212authfile /var/run/slim.auth
213
214# The login command. '%session' is replaced by the chosen session name, one
215# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
057d6ce5 216login_cmd exec " xinitrc " %session
9e4eddb4 217sessions wmaker,ratpoison
db4fdc04
LC
218
219halt_cmd " dmd "/sbin/halt
220reboot_cmd " dmd "/sbin/reboot
0ecc3bf3
LC
221"
222(if auto-login?
223 (string-append "auto_login yes\ndefault_user " default-user "\n")
224 "")
225(if theme-name
226 (string-append "current_theme " theme-name "\n")
227 ""))))
db4fdc04 228
b5f4e686 229 (mlet %store-monad ((slim.cfg (slim.cfg)))
db4fdc04
LC
230 (return
231 (service
232 (documentation "Xorg display server")
233 (provision '(xorg-server))
8dbab712 234 (requirement '(user-processes host-name udev))
db4fdc04 235 (start
47b73c34
LC
236 #~(lambda ()
237 ;; A stale lock file can prevent SLiM from starting, so remove it
238 ;; to be on the safe side.
239 (false-if-exception (delete-file "/var/run/slim.lock"))
240
241 (fork+exec-command
242 (list (string-append #$slim "/bin/slim") "-nodaemon")
243 #:environment-variables
0ecc3bf3
LC
244 (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
245 #$@(if theme
246 (list #~(string-append "SLIM_THEMESDIR=" #$theme))
247 #~())))))
b5f4e686 248 (stop #~(make-kill-destructor))
db4fdc04
LC
249 (respawn? #t)
250 (pam-services
251 ;; Tell PAM about 'slim'.
252 (list (unix-pam-service
253 "slim"
254 #:allow-empty-passwords? allow-empty-passwords?)))))))
255
256;;; xorg.scm ends here