xorg.scm 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Andy Wingo <wingo@igalia.com>
  3. ;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu services xorg)
  21. #:use-module (gnu artwork)
  22. #:use-module (gnu services)
  23. #:use-module (gnu services shepherd)
  24. #:use-module (gnu system pam)
  25. #:use-module (gnu services dbus)
  26. #:use-module ((gnu packages base) #:select (canonical-package))
  27. #:use-module (gnu packages guile)
  28. #:use-module (gnu packages xorg)
  29. #:use-module (gnu packages gl)
  30. #:use-module (gnu packages display-managers)
  31. #:use-module (gnu packages gnustep)
  32. #:use-module (gnu packages gnome)
  33. #:use-module (gnu packages admin)
  34. #:use-module (gnu packages bash)
  35. #:use-module (gnu system shadow)
  36. #:use-module (guix gexp)
  37. #:use-module (guix store)
  38. #:use-module (guix packages)
  39. #:use-module (guix derivations)
  40. #:use-module (guix records)
  41. #:use-module (srfi srfi-1)
  42. #:use-module (srfi srfi-9)
  43. #:use-module (srfi srfi-26)
  44. #:use-module (ice-9 match)
  45. #:export (xorg-configuration-file
  46. %default-xorg-modules
  47. %default-xorg-fonts
  48. xorg-wrapper
  49. xorg-start-command
  50. xinitrc
  51. %default-slim-theme
  52. %default-slim-theme-name
  53. slim-configuration
  54. slim-configuration?
  55. slim-configuration-slim
  56. slim-configuration-allow-empty-passwords?
  57. slim-configuration-auto-login?
  58. slim-configuration-default-user
  59. slim-configuration-theme
  60. slim-configuration-theme-name
  61. slim-configuration-xauth
  62. slim-configuration-shepherd
  63. slim-configuration-auto-login-session
  64. slim-configuration-startx
  65. slim-service-type
  66. slim-service
  67. screen-locker
  68. screen-locker?
  69. screen-locker-service-type
  70. screen-locker-service
  71. gdm-configuration
  72. gdm-service-type
  73. gdm-service))
  74. ;;; Commentary:
  75. ;;;
  76. ;;; Services that relate to the X Window System.
  77. ;;;
  78. ;;; Code:
  79. (define %default-xorg-modules
  80. ;; Default list of modules loaded by the server. Note that the order
  81. ;; matters since it determines which driver is going to be used when there's
  82. ;; a choice.
  83. (list xf86-video-vesa
  84. xf86-video-fbdev
  85. xf86-video-ati
  86. xf86-video-cirrus
  87. xf86-video-intel
  88. xf86-video-mach64
  89. xf86-video-nouveau
  90. xf86-video-nv
  91. xf86-video-sis
  92. ;; Libinput is the new thing and is recommended over evdev/synaptics:
  93. ;; <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
  94. xf86-input-libinput
  95. xf86-input-evdev
  96. xf86-input-keyboard
  97. xf86-input-mouse
  98. xf86-input-synaptics))
  99. (define %default-xorg-fonts
  100. ;; Default list of fonts available to the X server.
  101. (list (file-append font-alias "/share/fonts/X11/75dpi")
  102. (file-append font-alias "/share/fonts/X11/100dpi")
  103. (file-append font-alias "/share/fonts/X11/misc")
  104. (file-append font-alias "/share/fonts/X11/cyrillic")
  105. (file-append font-misc-misc ;default fonts for xterm
  106. "/share/fonts/X11/misc")
  107. (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
  108. (define* (xorg-configuration-file #:key
  109. (modules %default-xorg-modules)
  110. (fonts %default-xorg-fonts)
  111. (drivers '()) (resolutions '())
  112. (extra-config '()))
  113. "Return a configuration file for the Xorg server containing search paths for
  114. all the common drivers.
  115. @var{modules} must be a list of @dfn{module packages} loaded by the Xorg
  116. server---e.g., @code{xf86-video-vesa}, @code{xf86-input-keyboard}, and so on.
  117. @var{fonts} must be a list of font directories to add to the server's
  118. @dfn{font path}.
  119. @var{drivers} must be either the empty list, in which case Xorg chooses a
  120. graphics driver automatically, or a list of driver names that will be tried in
  121. this order---e.g., @code{(\"modesetting\" \"vesa\")}.
  122. Likewise, when @var{resolutions} is the empty list, Xorg chooses an
  123. appropriate screen resolution; otherwise, it must be a list of
  124. resolutions---e.g., @code{((1024 768) (640 480))}.
  125. Last, @var{extra-config} is a list of strings or objects appended to the
  126. configuration file. It is used to pass extra text to be
  127. added verbatim to the configuration file."
  128. (define all-modules
  129. ;; 'xorg-server' provides 'fbdevhw.so' etc.
  130. (append modules (list xorg-server)))
  131. (define build
  132. #~(begin
  133. (use-modules (ice-9 match)
  134. (srfi srfi-1)
  135. (srfi srfi-26))
  136. (call-with-output-file #$output
  137. (lambda (port)
  138. (define drivers
  139. '#$drivers)
  140. (define (device-section driver)
  141. (string-append "
  142. Section \"Device\"
  143. Identifier \"device-" driver "\"
  144. Driver \"" driver "\"
  145. EndSection"))
  146. (define (screen-section driver resolutions)
  147. (string-append "
  148. Section \"Screen\"
  149. Identifier \"screen-" driver "\"
  150. Device \"device-" driver "\"
  151. SubSection \"Display\"
  152. Modes "
  153. (string-join (map (match-lambda
  154. ((x y)
  155. (string-append "\"" (number->string x)
  156. "x" (number->string y) "\"")))
  157. resolutions)) "
  158. EndSubSection
  159. EndSection"))
  160. (define (expand modules)
  161. ;; Append to MODULES the relevant /lib/xorg/modules
  162. ;; sub-directories.
  163. (append-map (lambda (module)
  164. (filter-map (lambda (directory)
  165. (let ((full (string-append module
  166. directory)))
  167. (and (file-exists? full)
  168. full)))
  169. '("/lib/xorg/modules/drivers"
  170. "/lib/xorg/modules/input"
  171. "/lib/xorg/modules/multimedia"
  172. "/lib/xorg/modules/extensions")))
  173. modules))
  174. (display "Section \"Files\"\n" port)
  175. (for-each (lambda (font)
  176. (format port " FontPath \"~a\"~%" font))
  177. '#$fonts)
  178. (for-each (lambda (module)
  179. (format port
  180. " ModulePath \"~a\"~%"
  181. module))
  182. (append (expand '#$all-modules)
  183. ;; For fbdevhw.so and so on.
  184. (list #$(file-append xorg-server
  185. "/lib/xorg/modules"))))
  186. (display "EndSection\n" port)
  187. (display "
  188. Section \"ServerFlags\"
  189. Option \"AllowMouseOpenFail\" \"on\"
  190. EndSection\n" port)
  191. (display (string-join (map device-section drivers) "\n")
  192. port)
  193. (newline port)
  194. (display (string-join
  195. (map (cut screen-section <> '#$resolutions)
  196. drivers)
  197. "\n")
  198. port)
  199. (newline port)
  200. (for-each (lambda (config)
  201. (display config port))
  202. '#$extra-config)))))
  203. (computed-file "xserver.conf" build))
  204. (define (xorg-configuration-directory modules)
  205. "Return a directory that contains the @code{.conf} files for X.org that
  206. includes the @code{share/X11/xorg.conf.d} directories of each package listed
  207. in @var{modules}."
  208. (with-imported-modules '((guix build utils))
  209. (computed-file "xorg.conf.d"
  210. #~(begin
  211. (use-modules (guix build utils)
  212. (srfi srfi-1))
  213. (define files
  214. (append-map (lambda (module)
  215. (find-files (string-append
  216. module
  217. "/share/X11/xorg.conf.d")
  218. "\\.conf$"))
  219. (list #$@modules)))
  220. (mkdir #$output)
  221. (for-each (lambda (file)
  222. (symlink file
  223. (string-append #$output "/"
  224. (basename file))))
  225. files)
  226. #t))))
  227. (define* (xorg-wrapper #:key
  228. (guile (canonical-package guile-2.0))
  229. (modules %default-xorg-modules)
  230. (configuration-file (xorg-configuration-file
  231. #:modules modules))
  232. (xorg-server xorg-server))
  233. "Return a derivation that builds a @var{guile} script to start the X server
  234. from @var{xorg-server}. @var{configuration-file} is the server configuration
  235. file or a derivation that builds it; when omitted, the result of
  236. @code{xorg-configuration-file} is used. The resulting script should be used
  237. in place of @code{/usr/bin/X}."
  238. (define exp
  239. ;; Write a small wrapper around the X server.
  240. #~(begin
  241. (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
  242. (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
  243. (let ((X (string-append #$xorg-server "/bin/X")))
  244. (apply execl X X
  245. "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
  246. "-config" #$configuration-file
  247. "-configdir" #$(xorg-configuration-directory modules)
  248. (cdr (command-line))))))
  249. (program-file "X-wrapper" exp))
  250. (define* (xorg-start-command #:key
  251. (guile (canonical-package guile-2.0))
  252. (modules %default-xorg-modules)
  253. (fonts %default-xorg-fonts)
  254. (configuration-file
  255. (xorg-configuration-file #:modules modules
  256. #:fonts fonts))
  257. (xorg-server xorg-server))
  258. "Return a @code{startx} script in which @var{modules}, a list of X module
  259. packages, and @var{fonts}, a list of X font directories, are available. See
  260. @code{xorg-wrapper} for more details on the arguments. The result should be
  261. used in place of @code{startx}."
  262. (define X
  263. (xorg-wrapper #:guile guile
  264. #:configuration-file configuration-file
  265. #:modules modules
  266. #:xorg-server xorg-server))
  267. (define exp
  268. ;; Write a small wrapper around the X server.
  269. #~(apply execl #$X #$X ;; Second #$X is for argv[0].
  270. "-logverbose" "-verbose" "-nolisten" "tcp" "-terminate"
  271. (cdr (command-line))))
  272. (program-file "startx" exp))
  273. (define* (xinitrc #:key
  274. (guile (canonical-package guile-2.0))
  275. fallback-session)
  276. "Return a system-wide xinitrc script that starts the specified X session,
  277. which should be passed to this script as the first argument. If not, the
  278. @var{fallback-session} will be used or, if @var{fallback-session} is false, a
  279. desktop session from the system or user profile will be used."
  280. (define builder
  281. #~(begin
  282. (use-modules (ice-9 match)
  283. (ice-9 regex)
  284. (ice-9 ftw)
  285. (srfi srfi-1)
  286. (srfi srfi-26))
  287. (define (close-all-fdes)
  288. ;; Close all the open file descriptors except 0 to 2.
  289. (let loop ((fd 3))
  290. (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
  291. (false-if-exception (close-fdes fd))
  292. (loop (+ 1 fd)))))
  293. (define (exec-from-login-shell command . args)
  294. ;; Run COMMAND from a login shell so that it gets to see the same
  295. ;; environment variables that one gets when logging in on a tty, for
  296. ;; instance.
  297. (let* ((pw (getpw (getuid)))
  298. (shell (passwd:shell pw)))
  299. ;; Close any open file descriptors. This is all the more
  300. ;; important that SLiM itself exec's us directly without closing
  301. ;; its own file descriptors!
  302. (close-all-fdes)
  303. ;; The '--login' option is supported at least by Bash and zsh.
  304. (execl shell shell "--login" "-c"
  305. (string-join (cons command args)))))
  306. (define system-profile
  307. "/run/current-system/profile")
  308. (define user-profile
  309. (and=> (getpw (getuid))
  310. (lambda (pw)
  311. (string-append (passwd:dir pw) "/.guix-profile"))))
  312. (define (xsession-command desktop-file)
  313. ;; Read from DESKTOP-FILE its X session command and return it as a
  314. ;; list.
  315. (define exec-regexp
  316. (make-regexp "^[[:blank:]]*Exec=(.*)$"))
  317. (call-with-input-file desktop-file
  318. (lambda (port)
  319. (let loop ()
  320. (match (read-line port)
  321. ((? eof-object?) #f)
  322. ((= (cut regexp-exec exec-regexp <>) result)
  323. (if result
  324. (string-tokenize (match:substring result 1))
  325. (loop))))))))
  326. (define (find-session profile)
  327. ;; Return an X session command from PROFILE or #f if none was found.
  328. (let ((directory (string-append profile "/share/xsessions")))
  329. (match (scandir directory
  330. (cut string-suffix? ".desktop" <>))
  331. ((or () #f)
  332. #f)
  333. ((sessions ...)
  334. (any xsession-command
  335. (map (cut string-append directory "/" <>)
  336. sessions))))))
  337. (let* ((home (getenv "HOME"))
  338. (xsession-file (string-append home "/.xsession"))
  339. (session (match (command-line)
  340. ((_)
  341. #$(if fallback-session
  342. #~(list #$fallback-session)
  343. #f))
  344. ((_ x ..1)
  345. x))))
  346. (if (file-exists? xsession-file)
  347. ;; Run ~/.xsession when it exists.
  348. (apply exec-from-login-shell xsession-file
  349. (or session '()))
  350. ;; Otherwise, start the specified session or a fallback.
  351. (apply exec-from-login-shell
  352. (or session
  353. (find-session user-profile)
  354. (find-session system-profile)))))))
  355. (program-file "xinitrc" builder))
  356. ;;;
  357. ;;; SLiM log-in manager.
  358. ;;;
  359. (define %default-slim-theme
  360. ;; Theme based on work by Felipe López.
  361. (file-append %artwork-repository "/slim"))
  362. (define %default-slim-theme-name
  363. ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
  364. ;; contains the actual theme files.
  365. "0.x")
  366. (define-record-type* <slim-configuration>
  367. slim-configuration make-slim-configuration
  368. slim-configuration?
  369. (slim slim-configuration-slim
  370. (default slim))
  371. (allow-empty-passwords? slim-configuration-allow-empty-passwords?
  372. (default #t))
  373. (auto-login? slim-configuration-auto-login?
  374. (default #f))
  375. (default-user slim-configuration-default-user
  376. (default ""))
  377. (theme slim-configuration-theme
  378. (default %default-slim-theme))
  379. (theme-name slim-configuration-theme-name
  380. (default %default-slim-theme-name))
  381. (xauth slim-configuration-xauth
  382. (default xauth))
  383. (shepherd slim-configuration-shepherd
  384. (default shepherd))
  385. (auto-login-session slim-configuration-auto-login-session
  386. (default #f))
  387. (startx slim-configuration-startx
  388. (default (xorg-start-command))))
  389. (define (slim-pam-service config)
  390. "Return a PAM service for @command{slim}."
  391. (list (unix-pam-service
  392. "slim"
  393. #:allow-empty-passwords?
  394. (slim-configuration-allow-empty-passwords? config))))
  395. (define (slim-shepherd-service config)
  396. (define slim.cfg
  397. (let ((xinitrc (xinitrc #:fallback-session
  398. (slim-configuration-auto-login-session config)))
  399. (slim (slim-configuration-slim config))
  400. (xauth (slim-configuration-xauth config))
  401. (startx (slim-configuration-startx config))
  402. (shepherd (slim-configuration-shepherd config))
  403. (theme-name (slim-configuration-theme-name config)))
  404. (mixed-text-file "slim.cfg" "
  405. default_path /run/current-system/profile/bin
  406. default_xserver " startx "
  407. xserver_arguments :0 vt7
  408. xauth_path " xauth "/bin/xauth
  409. authfile /var/run/slim.auth
  410. # The login command. '%session' is replaced by the chosen session name, one
  411. # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
  412. login_cmd exec " xinitrc " %session
  413. sessiondir /run/current-system/profile/share/xsessions
  414. session_msg session (F1 to change):
  415. halt_cmd " shepherd "/sbin/halt
  416. reboot_cmd " shepherd "/sbin/reboot\n"
  417. (if (slim-configuration-auto-login? config)
  418. (string-append "auto_login yes\ndefault_user "
  419. (slim-configuration-default-user config) "\n")
  420. "")
  421. (if theme-name
  422. (string-append "current_theme " theme-name "\n")
  423. ""))))
  424. (define theme
  425. (slim-configuration-theme config))
  426. (list (shepherd-service
  427. (documentation "Xorg display server")
  428. (provision '(xorg-server))
  429. (requirement '(user-processes host-name udev))
  430. (start
  431. #~(lambda ()
  432. ;; A stale lock file can prevent SLiM from starting, so remove it to
  433. ;; be on the safe side.
  434. (false-if-exception (delete-file "/var/run/slim.lock"))
  435. (fork+exec-command
  436. (list (string-append #$slim "/bin/slim") "-nodaemon")
  437. #:environment-variables
  438. (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
  439. #$@(if theme
  440. (list #~(string-append "SLIM_THEMESDIR=" #$theme))
  441. #~())))))
  442. (stop #~(make-kill-destructor))
  443. (respawn? #t))))
  444. (define slim-service-type
  445. (service-type (name 'slim)
  446. (extensions
  447. (list (service-extension shepherd-root-service-type
  448. slim-shepherd-service)
  449. (service-extension pam-root-service-type
  450. slim-pam-service)
  451. ;; Unconditionally add xterm to the system profile, to
  452. ;; avoid bad surprises.
  453. (service-extension profile-service-type
  454. (const (list xterm)))))
  455. (default-value (slim-configuration))))
  456. (define* (slim-service #:key (slim slim) ;deprecated
  457. (allow-empty-passwords? #t) auto-login?
  458. (default-user "")
  459. (theme %default-slim-theme)
  460. (theme-name %default-slim-theme-name)
  461. (xauth xauth) (shepherd shepherd)
  462. (auto-login-session #f)
  463. (startx (xorg-start-command)))
  464. "Return a service that spawns the SLiM graphical login manager, which in
  465. turn starts the X display server with @var{startx}, a command as returned by
  466. @code{xorg-start-command}.
  467. @cindex X session
  468. SLiM automatically looks for session types described by the @file{.desktop}
  469. files in @file{/run/current-system/profile/share/xsessions} and allows users
  470. to choose a session from the log-in screen using @kbd{F1}. Packages such as
  471. @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
  472. adding them to the system-wide set of packages automatically makes them
  473. available at the log-in screen.
  474. In addition, @file{~/.xsession} files are honored. When available,
  475. @file{~/.xsession} must be an executable that starts a window manager
  476. and/or other X clients.
  477. When @var{allow-empty-passwords?} is true, allow logins with an empty
  478. password. When @var{auto-login?} is true, log in automatically as
  479. @var{default-user} with @var{auto-login-session}.
  480. If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
  481. @var{theme} must be a gexp denoting the name of a directory containing the
  482. theme to use. In that case, @var{theme-name} specifies the name of the
  483. theme."
  484. (service slim-service-type
  485. (slim-configuration
  486. (slim slim)
  487. (allow-empty-passwords? allow-empty-passwords?)
  488. (auto-login? auto-login?) (default-user default-user)
  489. (theme theme) (theme-name theme-name)
  490. (xauth xauth) (shepherd shepherd)
  491. (auto-login-session auto-login-session)
  492. (startx startx))))
  493. ;;;
  494. ;;; Screen lockers & co.
  495. ;;;
  496. (define-record-type <screen-locker>
  497. (screen-locker name program empty?)
  498. screen-locker?
  499. (name screen-locker-name) ;string
  500. (program screen-locker-program) ;gexp
  501. (empty? screen-locker-allows-empty-passwords?)) ;Boolean
  502. (define screen-locker-pam-services
  503. (match-lambda
  504. (($ <screen-locker> name _ empty?)
  505. (list (unix-pam-service name
  506. #:allow-empty-passwords? empty?)))))
  507. (define screen-locker-setuid-programs
  508. (compose list screen-locker-program))
  509. (define screen-locker-service-type
  510. (service-type (name 'screen-locker)
  511. (extensions
  512. (list (service-extension pam-root-service-type
  513. screen-locker-pam-services)
  514. (service-extension setuid-program-service-type
  515. screen-locker-setuid-programs)))))
  516. (define* (screen-locker-service package
  517. #:optional
  518. (program (package-name package))
  519. #:key allow-empty-passwords?)
  520. "Add @var{package}, a package for a screen-locker or screen-saver whose
  521. command is @var{program}, to the set of setuid programs and add a PAM entry
  522. for it. For example:
  523. @lisp
  524. (screen-locker-service xlockmore \"xlock\")
  525. @end lisp
  526. makes the good ol' XlockMore usable."
  527. (service screen-locker-service-type
  528. (screen-locker program
  529. (file-append package "/bin/" program)
  530. allow-empty-passwords?)))
  531. (define %gdm-accounts
  532. (list (user-group (name "gdm") (system? #t))
  533. (user-account
  534. (name "gdm")
  535. (group "gdm")
  536. (system? #t)
  537. (comment "GNOME Display Manager user")
  538. (home-directory "/var/lib/gdm")
  539. (shell (file-append shadow "/sbin/nologin")))))
  540. (define-record-type* <gdm-configuration>
  541. gdm-configuration make-gdm-configuration
  542. gdm-configuration?
  543. (gdm gdm-configuration-gdm (default gdm))
  544. (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
  545. (allow-root? gdm-configuration-allow-root? (default #t))
  546. (auto-login? gdm-configuration-auto-login? (default #f))
  547. (default-user gdm-configuration-default-user (default #f))
  548. (x-server gdm-configuration-x-server))
  549. (define (gdm-etc-service config)
  550. (define gdm-configuration-file
  551. (mixed-text-file "gdm-custom.conf"
  552. "[daemon]\n"
  553. "#User=gdm\n"
  554. "#Group=gdm\n"
  555. (if (gdm-configuration-auto-login? config)
  556. (string-append
  557. "AutomaticLoginEnable=true\n"
  558. "AutomaticLogin="
  559. (or (gdm-configuration-default-user config)
  560. (error "missing default user for auto-login"))
  561. "\n")
  562. (string-append
  563. "AutomaticLoginEnable=false\n"
  564. "#AutomaticLogin=\n"))
  565. "#TimedLoginEnable=false\n"
  566. "#TimedLogin=\n"
  567. "#TimedLoginDelay=0\n"
  568. "#InitialSetupEnable=true\n"
  569. ;; Enable me once X is working.
  570. "WaylandEnable=false\n"
  571. "\n"
  572. "[debug]\n"
  573. "Enable=true\n"
  574. "\n"
  575. "[security]\n"
  576. "#DisallowTCP=true\n"
  577. "#AllowRemoteAutoLogin=false\n"))
  578. `(("gdm" ,(file-union
  579. "gdm"
  580. `(("custom.conf" ,gdm-configuration-file))))))
  581. (define (gdm-pam-service config)
  582. "Return a PAM service for @command{gdm}."
  583. (list
  584. (pam-service
  585. (inherit (unix-pam-service "gdm-autologin"))
  586. (auth (list (pam-entry
  587. (control "[success=ok default=1]")
  588. (module (file-append (gdm-configuration-gdm config)
  589. "/lib/security/pam_gdm.so")))
  590. (pam-entry
  591. (control "sufficient")
  592. (module "pam_permit.so")))))
  593. (pam-service
  594. (inherit (unix-pam-service "gdm-launch-environment"))
  595. (auth (list (pam-entry
  596. (control "required")
  597. (module "pam_permit.so")))))
  598. (unix-pam-service
  599. "gdm-password"
  600. #:allow-empty-passwords? (gdm-configuration-allow-empty-passwords? config)
  601. #:allow-root? (gdm-configuration-allow-root? config))))
  602. (define (gdm-shepherd-service config)
  603. (list (shepherd-service
  604. (documentation "Xorg display server (GDM)")
  605. (provision '(xorg-server))
  606. (requirement '(dbus-system user-processes host-name udev))
  607. ;; While this service isn't working properly, turn off auto-start.
  608. (auto-start? #f)
  609. (start #~(lambda ()
  610. (fork+exec-command
  611. (list #$(file-append (gdm-configuration-gdm config)
  612. "/bin/gdm"))
  613. #:environment-variables
  614. (list (string-append
  615. "GDM_X_SERVER="
  616. #$(gdm-configuration-x-server config))
  617. ;; XXX: GDM requires access to a handful of
  618. ;; programs and components from Gnome (gnome-shell,
  619. ;; dbus, and gnome-session among others). The
  620. ;; following variables only work provided Gnome is
  621. ;; installed.
  622. "XDG_DATA_DIRS=/run/current-system/profile/share"
  623. "PATH=/run/current-system/profile/bin"))))
  624. (stop #~(make-kill-destructor))
  625. (respawn? #t))))
  626. (define gdm-service-type
  627. (service-type (name 'gdm)
  628. (extensions
  629. (list (service-extension shepherd-root-service-type
  630. gdm-shepherd-service)
  631. (service-extension account-service-type
  632. (const %gdm-accounts))
  633. (service-extension pam-root-service-type
  634. gdm-pam-service)
  635. (service-extension etc-service-type
  636. gdm-etc-service)
  637. (service-extension dbus-root-service-type
  638. (compose list gdm-configuration-gdm))))))
  639. ;; This service isn't working yet; it gets as far as starting to run the
  640. ;; greeter from gnome-shell but doesn't get any further. It is here because
  641. ;; it doesn't hurt anyone and perhaps it inspires someone to fix it :)
  642. (define* (gdm-service #:key (gdm gdm)
  643. (allow-empty-passwords? #t)
  644. (x-server (xorg-wrapper)))
  645. "Return a service that spawns the GDM graphical login manager, which in turn
  646. starts the X display server with @var{X}, a command as returned by
  647. @code{xorg-wrapper}.
  648. @cindex X session
  649. GDM automatically looks for session types described by the @file{.desktop}
  650. files in @file{/run/current-system/profile/share/xsessions} and allows users
  651. to choose a session from the log-in screen using @kbd{F1}. Packages such as
  652. @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
  653. adding them to the system-wide set of packages automatically makes them
  654. available at the log-in screen.
  655. In addition, @file{~/.xsession} files are honored. When available,
  656. @file{~/.xsession} must be an executable that starts a window manager
  657. and/or other X clients.
  658. When @var{allow-empty-passwords?} is true, allow logins with an empty
  659. password."
  660. (service gdm-service-type
  661. (gdm-configuration
  662. (gdm gdm)
  663. (allow-empty-passwords? allow-empty-passwords?)
  664. (x-server x-server))))
  665. ;;; xorg.scm ends here