Guest User

Untitled

a guest
Jul 10th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.35 KB | None | 0 0
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <[email protected]>
  3. ;;; Copyright © 2015 Sou Bunnbu <[email protected]>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  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.
  11. ;;;
  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.
  16. ;;;
  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/>.
  19.  
  20. (define-module (gnu services xorg)
  21. #:use-module (gnu artwork)
  22. #:use-module (gnu services)
  23. #:use-module (gnu system linux) ; 'pam-service'
  24. #:use-module ((gnu packages base) #:select (canonical-package))
  25. #:use-module (gnu packages guile)
  26. #:use-module (gnu packages xorg)
  27. #:use-module (gnu packages gl)
  28. #:use-module (gnu packages slim)
  29. #:use-module (gnu packages gnustep)
  30. #:use-module (gnu packages admin)
  31. #:use-module (gnu packages bash)
  32. #:use-module (guix gexp)
  33. #:use-module (guix store)
  34. #:use-module (guix monads)
  35. #:use-module (guix derivations)
  36. #:use-module (guix records)
  37. #:use-module (srfi srfi-1)
  38. #:use-module (srfi srfi-26)
  39. #:use-module (ice-9 match)
  40. #:export (xorg-configuration-file
  41. xorg-start-command
  42. %default-slim-theme
  43. %default-slim-theme-name
  44. slim-service))
  45.  
  46. ;;; Commentary:
  47. ;;;
  48. ;;; Services that relate to the X Window System.
  49. ;;;
  50. ;;; Code:
  51.  
  52. (define* (xorg-configuration-file #:key (drivers '()) (resolutions '())
  53. (extra-config '()))
  54. "Return a configuration file for the Xorg server containing search paths for
  55. all the common drivers.
  56.  
  57. @var{drivers} must be either the empty list, in which case Xorg chooses a
  58. graphics driver automatically, or a list of driver names that will be tried in
  59. this order---e.g., @code{(\"modesetting\" \"vesa\")}.
  60.  
  61. Likewise, when @var{resolutions} is the empty list, Xorg chooses an
  62. appropriate screen resolution; otherwise, it must be a list of
  63. resolutions---e.g., @code{((1024 768) (640 480))}.
  64.  
  65. Last, @var{extra-config} is a list of strings or objects appended to the
  66. @code{text-file*} argument list. It is used to pass extra text to be added
  67. verbatim to the configuration file."
  68. (define (device-section driver)
  69. (string-append "
  70. Section \"Device\"
  71. Identifier \"device-" driver "\"
  72. Driver \"" driver "\"
  73. EndSection"))
  74.  
  75. (define (screen-section driver resolutions)
  76. (string-append "
  77. Section \"Screen\"
  78. Identifier \"screen-" driver "\"
  79. Device \"device-" driver "\"
  80. SubSection \"Display\"
  81. Modes "
  82. (string-join (map (match-lambda
  83. ((x y)
  84. (string-append "\"" (number->string x)
  85. "x" (number->string y) "\"")))
  86. resolutions)) "
  87. EndSubSection
  88. EndSection"))
  89.  
  90. (apply text-file* "xserver.conf" "
  91. Section \"Files\"
  92. FontPath \"" font-adobe75dpi "/share/fonts/X11/75dpi\"
  93. ModulePath \"" xf86-video-ati "/lib/xorg/modules/drivers\"
  94. ModulePath \"" xf86-video-vesa "/lib/xorg/modules/drivers\"
  95. ModulePath \"" xf86-video-fbdev "/lib/xorg/modules/drivers\"
  96. ModulePath \"" xf86-video-modesetting "/lib/xorg/modules/drivers\"
  97. ModulePath \"" xf86-video-cirrus "/lib/xorg/modules/drivers\"
  98. ModulePath \"" xf86-video-intel "/lib/xorg/modules/drivers\"
  99. ModulePath \"" xf86-video-mach64 "/lib/xorg/modules/drivers\"
  100. ModulePath \"" xf86-video-nouveau "/lib/xorg/modules/drivers\"
  101. ModulePath \"" xf86-video-nv "/lib/xorg/modules/drivers\"
  102. ModulePath \"" xf86-video-sis "/lib/xorg/modules/drivers\"
  103.  
  104. # Libinput is the new thing and is recommended over evdev/synaptics
  105. # by those who know:
  106. # <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
  107. ModulePath \"" xf86-input-libinput "/lib/xorg/modules/input\"
  108.  
  109. ModulePath \"" xf86-input-evdev "/lib/xorg/modules/input\"
  110. ModulePath \"" xf86-input-keyboard "/lib/xorg/modules/input\"
  111. ModulePath \"" xf86-input-mouse "/lib/xorg/modules/input\"
  112. ModulePath \"" xf86-input-synaptics "/lib/xorg/modules/input\"
  113. ModulePath \"" xorg-server "/lib/xorg/modules\"
  114. ModulePath \"" xorg-server "/lib/xorg/modules/extensions\"
  115. ModulePath \"" xorg-server "/lib/xorg/modules/multimedia\"
  116. EndSection
  117.  
  118. Section \"ServerFlags\"
  119. Option \"AllowMouseOpenFail\" \"on\"
  120. EndSection
  121. "
  122. (string-join (map device-section drivers) "\n") "\n"
  123. (string-join (map (cut screen-section <> resolutions)
  124. drivers)
  125. "\n")
  126.  
  127. "\n"
  128. extra-config))
  129.  
  130. (define* (xorg-start-command #:key
  131. (guile (canonical-package guile-2.0))
  132. configuration-file
  133. (xorg-server xorg-server))
  134. "Return a derivation that builds a @var{guile} script to start the X server
  135. from @var{xorg-server}. @var{configuration-file} is the server configuration
  136. file or a derivation that builds it; when omitted, the result of
  137. @code{xorg-configuration-file} is used.
  138.  
  139. Usually the X server is started by a login manager."
  140. (mlet %store-monad ((config (if configuration-file
  141. (return configuration-file)
  142. (xorg-configuration-file))))
  143. (define script
  144. ;; Write a small wrapper around the X server.
  145. #~(begin
  146. (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
  147. (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
  148.  
  149. (apply execl (string-append #$xorg-server "/bin/X")
  150. (string-append #$xorg-server "/bin/X") ;argv[0]
  151. "-logverbose" "-verbose"
  152. "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
  153. "-config" #$config
  154. "-nolisten" "tcp" "-terminate"
  155.  
  156. ;; Note: SLiM and other display managers add the
  157. ;; '-auth' flag by themselves.
  158. (cdr (command-line)))))
  159.  
  160. (gexp->script "start-xorg" script)))
  161.  
  162. (define* (xinitrc #:key
  163. (guile (canonical-package guile-2.0))
  164. fallback-session)
  165. "Return a system-wide xinitrc script that starts the specified X session,
  166. which should be passed to this script as the first argument. If not, the
  167. @var{fallback-session} will be used."
  168. (define builder
  169. #~(begin
  170. (use-modules (ice-9 match))
  171.  
  172. (define (close-all-fdes)
  173. ;; Close all the open file descriptors except 0 to 2.
  174. (let loop ((fd 3))
  175. (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
  176. (false-if-exception (close-fdes fd))
  177. (loop (+ 1 fd)))))
  178.  
  179. (define (exec-from-login-shell command . args)
  180. ;; Run COMMAND from a login shell so that it gets to see the same
  181. ;; environment variables that one gets when logging in on a tty, for
  182. ;; instance.
  183. (let* ((pw (getpw (getuid)))
  184. (shell (passwd:shell pw)))
  185. ;; Close any open file descriptors. This is all the more
  186. ;; important that SLiM itself exec's us directly without closing
  187. ;; its own file descriptors!
  188. (close-all-fdes)
  189.  
  190. ;; The '--login' option is supported at least by Bash and zsh.
  191. (execl shell shell "--login" "-c"
  192. (string-join (cons command args)))))
  193.  
  194. (let* ((home (getenv "HOME"))
  195. (xsession-file (string-append home "/.xsession"))
  196. (session (match (command-line)
  197. ((_ x) x)
  198. (_ #$fallback-session))))
  199. (if (file-exists? xsession-file)
  200. ;; Run ~/.xsession when it exists.
  201. (exec-from-login-shell xsession-file session)
  202. ;; Otherwise, start the specified session.
  203. (exec-from-login-shell session)))))
  204. (gexp->script "xinitrc" builder))
  205.  
  206. ;;;
  207. ;;; SLiM log-in manager.
  208. ;;;
  209.  
  210. (define %default-slim-theme
  211. ;; Theme based on work by Felipe López.
  212. #~(string-append #$%artwork-repository "/slim"))
  213.  
  214. (define %default-slim-theme-name
  215. ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
  216. ;; contains the actual theme files.
  217. "0.x")
  218.  
  219. (define* (slim-service #:key (slim slim)
  220. (allow-empty-passwords? #t) auto-login?
  221. (default-user "")
  222. (theme %default-slim-theme)
  223. (theme-name %default-slim-theme-name)
  224. (xauth xauth) (dmd dmd) (bash bash)
  225. (auto-login-session #~(string-append #$windowmaker
  226. "/bin/wmaker"))
  227. startx)
  228. "Return a service that spawns the SLiM graphical login manager, which in
  229. turn starts the X display server with @var{startx}, a command as returned by
  230. @code{xorg-start-command}.
  231.  
  232. @cindex X session
  233.  
  234. SLiM automatically looks for session types described by the @file{.desktop}
  235. files in @file{/run/current-system/profile/share/xsessions} and allows users
  236. to choose a session from the log-in screen using @kbd{F1}. Packages such as
  237. @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
  238. adding them to the system-wide set of packages automatically makes them
  239. available at the log-in screen.
  240.  
  241. In addition, @file{~/.xsession} files are honored. When available,
  242. @file{~/.xsession} must be an executable that starts a window manager
  243. and/or other X clients.
  244.  
  245. When @var{allow-empty-passwords?} is true, allow logins with an empty
  246. password. When @var{auto-login?} is true, log in automatically as
  247. @var{default-user} with @var{auto-login-session}.
  248.  
  249. If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
  250. @var{theme} must be a gexp denoting the name of a directory containing the
  251. theme to use. In that case, @var{theme-name} specifies the name of the
  252. theme."
  253.  
  254. (define (slim.cfg)
  255. (mlet %store-monad ((startx (if startx
  256. (return startx)
  257. (xorg-start-command)))
  258. (xinitrc (xinitrc #:fallback-session
  259. auto-login-session)))
  260. (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
  266.  
  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):
  272.  
  273. halt_cmd " dmd "/sbin/halt
  274. reboot_cmd " dmd "/sbin/reboot
  275. "
  276. (if auto-login?
  277. (string-append "auto_login yes\ndefault_user " default-user "\n")
  278. "")
  279. (if theme-name
  280. (string-append "current_theme " theme-name "\n")
  281. ""))))
  282.  
  283. (mlet %store-monad ((slim.cfg (slim.cfg)))
  284. (return
  285. (service
  286. (documentation "Xorg display server")
  287. (provision '(xorg-server))
  288. (requirement '(user-processes host-name udev))
  289. (start
  290. #~(lambda ()
  291. ;; A stale lock file can prevent SLiM from starting, so remove it
  292. ;; to be on the safe side.
  293. (false-if-exception (delete-file "/var/run/slim.lock"))
  294.  
  295. (fork+exec-command
  296. (list (string-append #$slim "/bin/slim") "-nodaemon")
  297. #:environment-variables
  298. (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
  299. #$@(if theme
  300. (list #~(string-append "SLIM_THEMESDIR=" #$theme))
  301. #~())))))
  302. (stop #~(make-kill-destructor))
  303. (respawn? #t)
  304. (pam-services
  305. ;; Tell PAM about 'slim'.
  306. (list (unix-pam-service
  307. "slim"
  308. #:allow-empty-passwords? allow-empty-passwords?)))))))
  309.  
  310. ;;; xorg.scm ends here
Advertisement
Add Comment
Please, Sign In to add comment