Commit | Line | Data |
---|---|---|
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) | |
20 | #:use-module (gnu services) | |
21 | #:use-module (gnu system linux) ; 'pam-service' | |
bdb36958 LC |
22 | #:use-module ((gnu packages base) #:select (canonical-package)) |
23 | #:use-module (gnu packages guile) | |
db4fdc04 LC |
24 | #:use-module (gnu packages xorg) |
25 | #:use-module (gnu packages gl) | |
26 | #:use-module (gnu packages slim) | |
27 | #:use-module (gnu packages ratpoison) | |
9e4eddb4 | 28 | #:use-module (gnu packages gnustep) |
db4fdc04 LC |
29 | #:use-module (gnu packages admin) |
30 | #:use-module (gnu packages bash) | |
b5f4e686 | 31 | #:use-module (guix gexp) |
db4fdc04 LC |
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 | |
bdb36958 | 44 | (guile (canonical-package guile-2.0)) |
db4fdc04 LC |
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\" | |
378377eb | 52 | FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\" |
db4fdc04 | 53 | ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\" |
0adb027b | 54 | ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\" |
41d07f5e LC |
55 | # FIXME: Commented out due to libdrm incompatibility. |
56 | # ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\" | |
0adb027b LC |
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\" | |
db4fdc04 | 61 | ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\" |
0adb027b LC |
62 | ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\" |
63 | ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\" | |
db4fdc04 LC |
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 | |
971436c6 | 72 | ")) |
db4fdc04 | 73 | |
8779d342 LC |
74 | (mlet %store-monad ((config (xserver.conf))) |
75 | (define script | |
db4fdc04 | 76 | ;; Write a small wrapper around the X server. |
8779d342 LC |
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))) | |
db4fdc04 | 92 | |
9e4eddb4 | 93 | (define* (xinitrc #:key |
bdb36958 | 94 | (guile (canonical-package guile-2.0)) |
9e4eddb4 LC |
95 | (ratpoison ratpoison) |
96 | (windowmaker windowmaker)) | |
97 | "Return a system-wide xinitrc script that starts the specified X session." | |
8779d342 LC |
98 | (define builder |
99 | #~(begin | |
100 | (use-modules (ice-9 match)) | |
101 | ||
d9372161 LC |
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. | |
8779d342 LC |
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)) | |
9e4eddb4 | 115 | |
db4fdc04 LC |
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 | |
51da7ca0 LC |
122 | turn starts the X display server with @var{startx}, a command as returned by |
123 | @code{xorg-start-command}. | |
db4fdc04 | 124 | |
51da7ca0 LC |
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}." | |
db4fdc04 | 128 | (define (slim.cfg) |
9e4eddb4 LC |
129 | (mlet %store-monad ((startx (or startx (xorg-start-command))) |
130 | (xinitrc (xinitrc))) | |
db4fdc04 | 131 | (text-file* "slim.cfg" " |
b4140694 | 132 | default_path /run/current-system/profile/bin |
db4fdc04 LC |
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. | |
057d6ce5 | 140 | login_cmd exec " xinitrc " %session |
9e4eddb4 | 141 | sessions wmaker,ratpoison |
db4fdc04 LC |
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 | ||
b5f4e686 | 149 | (mlet %store-monad ((slim.cfg (slim.cfg))) |
db4fdc04 LC |
150 | (return |
151 | (service | |
152 | (documentation "Xorg display server") | |
153 | (provision '(xorg-server)) | |
8dbab712 | 154 | (requirement '(user-processes host-name udev)) |
db4fdc04 | 155 | (start |
47b73c34 LC |
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))))) | |
b5f4e686 | 165 | (stop #~(make-kill-destructor)) |
db4fdc04 LC |
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 |