1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 (guile-final))
23 #:use-module (gnu packages xorg)
24 #:use-module (gnu packages gl)
25 #:use-module (gnu packages slim)
26 #:use-module (gnu packages ratpoison)
27 #:use-module (gnu packages admin)
28 #:use-module (gnu packages bash)
29 #:use-module (guix monads)
30 #:use-module (guix derivations)
31 #:export (xorg-start-command
36 ;;; Services that relate to the X Window System.
40 (define* (xorg-start-command #:key
42 (xorg-server xorg-server))
43 "Return a derivation that builds a GUILE script to start the X server from
44 XORG-SERVER. Usually the X server is started by a login manager."
46 (define (xserver.conf)
47 (text-file* "xserver.conf" "
49 FontPath \"" font-adobe75dpi "/share/font/X11/75dpi\"
50 ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
51 ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
52 ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
53 ModulePath \"" xorg-server "/lib/xorg/modules\"
54 ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
55 ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
58 Section \"ServerFlags\"
59 Option \"AllowMouseOpenFail\" \"on""
63 Identifier \"Monitor[0]\"
66 Section \"InputClass\"
67 Identifier \"Generic keyboard\"
68 MatchIsKeyboard \"on\"
69 Option \"XkbRules\" \"base\"
70 Option \"XkbModel\" \"pc104\"
73 Section \"ServerLayout\"
75 Screen \"Screen-vesa\"
79 Identifier \"Device-vesa\"
84 Identifier \"Screen-vesa\"
85 Device \"Device-vesa\"
88 (mlet %store-monad ((guile-bin (package-file guile "bin/guile"))
89 (xorg-bin (package-file xorg-server "bin/X"))
90 (dri (package-file mesa "lib/dri"))
91 (xkbcomp-bin (package-file xkbcomp "bin"))
92 (xkb-dir (package-file xkeyboard-config
94 (config (xserver.conf)))
96 ;; Write a small wrapper around the X server.
97 `(let ((out (assoc-ref %outputs "out")))
98 (call-with-output-file out
100 (format port "#!~a --no-auto-compile~%!#~%" ,guile-bin)
102 (setenv "XORG_DRI_DRIVER_PATH" ,dri)
103 (setenv "XKB_BINDIR" ,xkbcomp-bin)
107 ,xorg-bin "-ac" "-logverbose" "-verbose"
109 "-config" ,(derivation->output-path config)
110 "-nolisten" "tcp" "-terminate"
112 ;; Note: SLiM and other display managers add the
113 ;; '-auth' flag by themselves.
114 (cdr (command-line))))
119 (mlet %store-monad ((inputs (lower-inputs
120 `(("xorg" ,xorg-server)
122 ("xkeyboard-config" ,xkeyboard-config)
125 ("xorg.conf" ,config)))))
126 (derivation-expression "start-xorg" builder
129 (define* (slim-service #:key (slim slim)
130 (allow-empty-passwords? #t) auto-login?
132 (xauth xauth) (dmd dmd) (bash bash)
134 "Return a service that spawns the SLiM graphical login manager, which in
135 turn start the X display server with STARTX, a command as returned by
136 'xorg-start-command'.
138 When ALLOW-EMPTY-PASSWORDS? is true, allow logins with an empty password.
139 When AUTO-LOGIN? is true, log in automatically as DEFAULT-USER."
141 ;; TODO: Run "bash -login ~/.xinitrc %session".
142 (mlet %store-monad ((startx (or startx (xorg-start-command))))
143 (text-file* "slim.cfg" "
144 default_path /run/current-system/bin
145 default_xserver " startx "
146 xserver_arguments :0 vt7
147 xauth_path " xauth "/bin/xauth
148 authfile /var/run/slim.auth
150 # The login command. '%session' is replaced by the chosen session name, one
151 # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
152 login_cmd exec " ratpoison "/bin/ratpoison
154 halt_cmd " dmd "/sbin/halt
155 reboot_cmd " dmd "/sbin/reboot
157 (string-append "auto_login yes\ndefault_user " default-user)
160 (mlet %store-monad ((slim-bin (package-file slim "bin/slim"))
161 (bash-bin (package-file bash "bin/bash"))
162 (slim.cfg (slim.cfg)))
165 (documentation "Xorg display server")
166 (provision '(xorg-server))
167 (requirement '(host-name))
169 ;; XXX: Work around the inability to specify env. vars. directly.
170 `(make-forkexec-constructor
172 ,(string-append "SLIM_CFGFILE=" (derivation->output-path slim.cfg)
175 (stop `(make-kill-destructor))
176 (inputs `(("slim" ,slim)
177 ("slim.cfg" ,slim.cfg)
181 ;; Tell PAM about 'slim'.
182 (list (unix-pam-service
184 #:allow-empty-passwords? allow-empty-passwords?)))))))
186 ;;; xorg.scm ends here