xorg.scm 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Andy Wingo <wingo@igalia.com>
  3. ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
  5. ;;; Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
  6. ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  7. ;;; Copyright © 2019 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
  8. ;;; Copyright © 2020 shtwzrd <shtwzrd@protonmail.com>
  9. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  10. ;;; Copyright © 2020 Alex Griffin <a@ajgrf.com>
  11. ;;;
  12. ;;; This file is part of GNU Guix.
  13. ;;;
  14. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  15. ;;; under the terms of the GNU General Public License as published by
  16. ;;; the Free Software Foundation; either version 3 of the License, or (at
  17. ;;; your option) any later version.
  18. ;;;
  19. ;;; GNU Guix is distributed in the hope that it will be useful, but
  20. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. ;;; GNU General Public License for more details.
  23. ;;;
  24. ;;; You should have received a copy of the GNU General Public License
  25. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  26. (define-module (gnu services xorg)
  27. #:use-module (gnu artwork)
  28. #:use-module (gnu services)
  29. #:use-module (gnu services shepherd)
  30. #:use-module (gnu system pam)
  31. #:use-module (gnu system keyboard)
  32. #:use-module (gnu services base)
  33. #:use-module (gnu services dbus)
  34. #:use-module (gnu packages base)
  35. #:use-module (gnu packages guile)
  36. #:use-module (gnu packages xorg)
  37. #:use-module (gnu packages fonts)
  38. #:use-module (gnu packages gl)
  39. #:use-module (gnu packages glib)
  40. #:use-module (gnu packages display-managers)
  41. #:use-module (gnu packages freedesktop)
  42. #:use-module (gnu packages gnustep)
  43. #:use-module (gnu packages gnome)
  44. #:use-module (gnu packages admin)
  45. #:use-module (gnu packages bash)
  46. #:use-module (gnu system shadow)
  47. #:use-module (guix gexp)
  48. #:use-module (guix store)
  49. #:use-module (guix packages)
  50. #:use-module (guix derivations)
  51. #:use-module (guix records)
  52. #:use-module (guix deprecation)
  53. #:use-module (srfi srfi-1)
  54. #:use-module (srfi srfi-9)
  55. #:use-module (srfi srfi-26)
  56. #:use-module (ice-9 match)
  57. #:export (xorg-configuration
  58. xorg-configuration?
  59. xorg-configuration-modules
  60. xorg-configuration-fonts
  61. xorg-configuration-drivers
  62. xorg-configuration-resolutions
  63. xorg-configuration-extra-config
  64. xorg-configuration-server
  65. xorg-configuration-server-arguments
  66. %default-xorg-modules
  67. %default-xorg-fonts
  68. xorg-wrapper
  69. xorg-start-command
  70. xinitrc
  71. %default-slim-theme
  72. %default-slim-theme-name
  73. slim-configuration
  74. slim-configuration?
  75. slim-configuration-slim
  76. slim-configuration-allow-empty-passwords?
  77. slim-configuration-auto-login?
  78. slim-configuration-default-user
  79. slim-configuration-theme
  80. slim-configuration-theme-name
  81. slim-configuration-xauth
  82. slim-configuration-shepherd
  83. slim-configuration-auto-login-session
  84. slim-configuration-xorg
  85. slim-configuration-display
  86. slim-configuration-vt
  87. slim-configuration-sessreg
  88. slim-service-type
  89. slim-service
  90. screen-locker
  91. screen-locker?
  92. screen-locker-service-type
  93. screen-locker-service
  94. localed-configuration
  95. localed-configuration?
  96. localed-service-type
  97. gdm-configuration
  98. gdm-service-type
  99. gdm-service
  100. handle-xorg-configuration
  101. set-xorg-configuration))
  102. ;;; Commentary:
  103. ;;;
  104. ;;; Services that relate to the X Window System.
  105. ;;;
  106. ;;; Code:
  107. (define %default-xorg-modules
  108. ;; Default list of modules loaded by the server. When multiple drivers
  109. ;; match, the first one in the list is loaded.
  110. (list xf86-video-vesa
  111. xf86-video-fbdev
  112. xf86-video-amdgpu
  113. xf86-video-ati
  114. xf86-video-cirrus
  115. xf86-video-intel
  116. xf86-video-mach64
  117. xf86-video-nouveau
  118. xf86-video-nv
  119. xf86-video-sis
  120. ;; Libinput is the new thing and is recommended over evdev/synaptics:
  121. ;; <http://who-t.blogspot.fr/2015/01/xf86-input-libinput-compatibility-with.html>.
  122. xf86-input-libinput
  123. xf86-input-evdev
  124. xf86-input-keyboard
  125. xf86-input-mouse
  126. xf86-input-synaptics))
  127. (define %default-xorg-fonts
  128. ;; Default list of fonts available to the X server.
  129. (list (file-append font-alias "/share/fonts/X11/75dpi")
  130. (file-append font-alias "/share/fonts/X11/100dpi")
  131. (file-append font-alias "/share/fonts/X11/misc")
  132. (file-append font-alias "/share/fonts/X11/cyrillic")
  133. (file-append font-misc-misc ;default fonts for xterm
  134. "/share/fonts/X11/misc")
  135. (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
  136. (define %default-xorg-server-arguments
  137. ;; Default command-line arguments for X.
  138. '("-nolisten" "tcp"))
  139. ;; Configuration of an Xorg server.
  140. (define-record-type* <xorg-configuration>
  141. xorg-configuration make-xorg-configuration
  142. xorg-configuration?
  143. (modules xorg-configuration-modules ;list of packages
  144. ; filter out modules not supported on current system
  145. (default (filter
  146. (lambda (p)
  147. (member (%current-system)
  148. (package-supported-systems p)))
  149. %default-xorg-modules)))
  150. (fonts xorg-configuration-fonts ;list of packges
  151. (default %default-xorg-fonts))
  152. (drivers xorg-configuration-drivers ;list of strings
  153. (default '()))
  154. (resolutions xorg-configuration-resolutions ;list of tuples
  155. (default '()))
  156. (keyboard-layout xorg-configuration-keyboard-layout ;#f | <keyboard-layout>
  157. (default #f))
  158. (extra-config xorg-configuration-extra-config ;list of strings
  159. (default '()))
  160. (server xorg-configuration-server ;package
  161. (default xorg-server))
  162. (server-arguments xorg-configuration-server-arguments ;list of strings
  163. (default %default-xorg-server-arguments)))
  164. (define (xorg-configuration->file config)
  165. "Compute an Xorg configuration file corresponding to CONFIG, an
  166. <xorg-configuration> record."
  167. (let ((xorg-server (xorg-configuration-server config)))
  168. (define all-modules
  169. ;; 'xorg-server' provides 'fbdevhw.so' etc.
  170. (append (xorg-configuration-modules config)
  171. (list xorg-server)))
  172. (define build
  173. #~(begin
  174. (use-modules (ice-9 match)
  175. (srfi srfi-1)
  176. (srfi srfi-26))
  177. (call-with-output-file #$output
  178. (lambda (port)
  179. (define drivers
  180. '#$(xorg-configuration-drivers config))
  181. (define (device-section driver)
  182. (string-append "
  183. Section \"Device\"
  184. Identifier \"device-" driver "\"
  185. Driver \"" driver "\"
  186. EndSection"))
  187. (define (screen-section driver resolutions)
  188. (string-append "
  189. Section \"Screen\"
  190. Identifier \"screen-" driver "\"
  191. Device \"device-" driver "\"
  192. SubSection \"Display\"
  193. Modes "
  194. (string-join (map (match-lambda
  195. ((x y)
  196. (string-append "\"" (number->string x)
  197. "x" (number->string y) "\"")))
  198. resolutions)) "
  199. EndSubSection
  200. EndSection"))
  201. (define (input-class-section layout variant model options)
  202. (string-append "
  203. Section \"InputClass\"
  204. Identifier \"evdev keyboard catchall\"
  205. MatchIsKeyboard \"on\"
  206. Option \"XkbLayout\" " (object->string layout)
  207. (if variant
  208. (string-append " Option \"XkbVariant\" \""
  209. variant "\"")
  210. "")
  211. (if model
  212. (string-append " Option \"XkbModel\" \""
  213. model "\"")
  214. "")
  215. (match options
  216. (()
  217. "")
  218. (_
  219. (string-append " Option \"XkbOptions\" \""
  220. (string-join options ",") "\""))) "
  221. MatchDevicePath \"/dev/input/event*\"
  222. Driver \"evdev\"
  223. EndSection\n"))
  224. (define (expand modules)
  225. ;; Append to MODULES the relevant /lib/xorg/modules
  226. ;; sub-directories.
  227. (append-map (lambda (module)
  228. (filter-map (lambda (directory)
  229. (let ((full (string-append module
  230. directory)))
  231. (and (file-exists? full)
  232. full)))
  233. '("/lib/xorg/modules/drivers"
  234. "/lib/xorg/modules/input"
  235. "/lib/xorg/modules/multimedia"
  236. "/lib/xorg/modules/extensions")))
  237. modules))
  238. (display "Section \"Files\"\n" port)
  239. (for-each (lambda (font)
  240. (format port " FontPath \"~a\"~%" font))
  241. '#$(xorg-configuration-fonts config))
  242. (for-each (lambda (module)
  243. (format port
  244. " ModulePath \"~a\"~%"
  245. module))
  246. (append (expand '#$all-modules)
  247. ;; For fbdevhw.so and so on.
  248. (list #$(file-append xorg-server
  249. "/lib/xorg/modules"))))
  250. (display "EndSection\n" port)
  251. (display "
  252. Section \"ServerFlags\"
  253. Option \"AllowMouseOpenFail\" \"on\"
  254. EndSection\n" port)
  255. (display (string-join (map device-section drivers) "\n")
  256. port)
  257. (newline port)
  258. (display (string-join
  259. (map (cut screen-section <>
  260. '#$(xorg-configuration-resolutions config))
  261. drivers)
  262. "\n")
  263. port)
  264. (newline port)
  265. (let ((layout #$(and=> (xorg-configuration-keyboard-layout config)
  266. keyboard-layout-name))
  267. (variant #$(and=> (xorg-configuration-keyboard-layout config)
  268. keyboard-layout-variant))
  269. (model #$(and=> (xorg-configuration-keyboard-layout config)
  270. keyboard-layout-model))
  271. (options '#$(and=> (xorg-configuration-keyboard-layout config)
  272. keyboard-layout-options)))
  273. (when layout
  274. (display (input-class-section layout variant model options)
  275. port)
  276. (newline port)))
  277. (for-each (lambda (config)
  278. (display config port))
  279. '#$(xorg-configuration-extra-config config))))))
  280. (computed-file "xserver.conf" build)))
  281. (define (xorg-configuration-directory modules)
  282. "Return a directory that contains the @code{.conf} files for X.org that
  283. includes the @code{share/X11/xorg.conf.d} directories of each package listed
  284. in @var{modules}."
  285. (with-imported-modules '((guix build utils))
  286. (computed-file "xorg.conf.d"
  287. #~(begin
  288. (use-modules (guix build utils)
  289. (srfi srfi-1))
  290. (define files
  291. (append-map (lambda (module)
  292. (find-files (string-append
  293. module
  294. "/share/X11/xorg.conf.d")
  295. "\\.conf$"))
  296. (list #$@modules)))
  297. (mkdir #$output)
  298. (for-each (lambda (file)
  299. (symlink file
  300. (string-append #$output "/"
  301. (basename file))))
  302. files)
  303. #t))))
  304. (define* (xorg-wrapper #:optional (config (xorg-configuration)))
  305. "Return a derivation that builds a script to start the X server with the
  306. given @var{config}. The resulting script should be used in place of
  307. @code{/usr/bin/X}."
  308. (define exp
  309. ;; Write a small wrapper around the X server.
  310. #~(begin
  311. (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
  312. (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
  313. (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
  314. (apply execl X X
  315. "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
  316. "-config" #$(xorg-configuration->file config)
  317. "-configdir" #$(xorg-configuration-directory
  318. (xorg-configuration-modules config))
  319. (cdr (command-line))))))
  320. (program-file "X-wrapper" exp))
  321. (define* (xorg-start-command #:optional (config (xorg-configuration)))
  322. "Return a @code{startx} script in which the modules, fonts, etc. specified
  323. in @var{config}, are available. The result should be used in place of
  324. @code{startx}."
  325. (define X
  326. (xorg-wrapper config))
  327. (define exp
  328. ;; Write a small wrapper around the X server.
  329. #~(apply execl #$X #$X ;; Second #$X is for argv[0].
  330. "-logverbose" "-verbose" "-terminate"
  331. #$@(xorg-configuration-server-arguments config)
  332. (cdr (command-line))))
  333. (program-file "startx" exp))
  334. (define* (xinitrc #:key fallback-session)
  335. "Return a system-wide xinitrc script that starts the specified X session,
  336. which should be passed to this script as the first argument. If not, the
  337. @var{fallback-session} will be used or, if @var{fallback-session} is false, a
  338. desktop session from the system or user profile will be used."
  339. (define builder
  340. #~(begin
  341. (use-modules (ice-9 match)
  342. (ice-9 regex)
  343. (ice-9 ftw)
  344. (ice-9 rdelim)
  345. (srfi srfi-1)
  346. (srfi srfi-26))
  347. (define (close-all-fdes)
  348. ;; Close all the open file descriptors except 0 to 2.
  349. (let loop ((fd 3))
  350. (when (< fd 4096) ;FIXME: use sysconf + _SC_OPEN_MAX
  351. (false-if-exception (close-fdes fd))
  352. (loop (+ 1 fd)))))
  353. (define (exec-from-login-shell command . args)
  354. ;; Run COMMAND from a login shell so that it gets to see the same
  355. ;; environment variables that one gets when logging in on a tty, for
  356. ;; instance.
  357. (let* ((pw (getpw (getuid)))
  358. (shell (passwd:shell pw)))
  359. ;; Close any open file descriptors. This is all the more
  360. ;; important that SLiM itself exec's us directly without closing
  361. ;; its own file descriptors!
  362. (close-all-fdes)
  363. ;; The '--login' option is supported at least by Bash and zsh.
  364. (execl shell shell "--login" "-c"
  365. (string-join (cons command args)))))
  366. (define system-profile
  367. "/run/current-system/profile")
  368. (define user-profile
  369. (and=> (getpw (getuid))
  370. (lambda (pw)
  371. (string-append (passwd:dir pw) "/.guix-profile"))))
  372. (define (xsession-command desktop-file)
  373. ;; Read from DESKTOP-FILE its X session command and return it as a
  374. ;; list.
  375. (define exec-regexp
  376. (make-regexp "^[[:blank:]]*Exec=(.*)$"))
  377. (call-with-input-file desktop-file
  378. (lambda (port)
  379. (let loop ()
  380. (match (read-line port)
  381. ((? eof-object?) #f)
  382. ((= (cut regexp-exec exec-regexp <>) result)
  383. (if result
  384. (string-tokenize (match:substring result 1))
  385. (loop))))))))
  386. (define (find-session profile)
  387. ;; Return an X session command from PROFILE or #f if none was found.
  388. (let ((directory (string-append profile "/share/xsessions")))
  389. (match (scandir directory
  390. (cut string-suffix? ".desktop" <>))
  391. ((or () #f)
  392. #f)
  393. ((sessions ...)
  394. (any xsession-command
  395. (map (cut string-append directory "/" <>)
  396. sessions))))))
  397. (let* ((home (getenv "HOME"))
  398. (xsession-file (string-append home "/.xsession"))
  399. (session (match (command-line)
  400. ((_)
  401. #$(if fallback-session
  402. #~(list #$fallback-session)
  403. #f))
  404. ((_ x ..1)
  405. x))))
  406. (if (file-exists? xsession-file)
  407. ;; Run ~/.xsession when it exists.
  408. (apply exec-from-login-shell xsession-file
  409. (or session '()))
  410. ;; Otherwise, start the specified session or a fallback.
  411. (apply exec-from-login-shell
  412. (or session
  413. (find-session user-profile)
  414. (find-session system-profile)))))))
  415. (program-file "xinitrc" builder))
  416. (define-syntax handle-xorg-configuration
  417. (syntax-rules ()
  418. "Generate the `compose' and `extend' entries of a login manager
  419. `service-type' to handle specifying the `xorg-configuration' through
  420. a `service-extension', as used by `set-xorg-configuration'."
  421. ((_ configuration-record service-type-definition)
  422. (service-type
  423. (inherit service-type-definition)
  424. (compose (lambda (extensions)
  425. (match extensions
  426. (() #f)
  427. ((config . _) config))))
  428. (extend (lambda (config xorg-configuration)
  429. (if xorg-configuration
  430. (configuration-record
  431. (inherit config)
  432. (xorg-configuration xorg-configuration))
  433. config)))))))
  434. ;;;
  435. ;;; SLiM log-in manager.
  436. ;;;
  437. (define %default-slim-theme
  438. ;; Theme based on work by Felipe López.
  439. (file-append %artwork-repository "/slim"))
  440. (define %default-slim-theme-name
  441. ;; This must be the name of the sub-directory in %DEFAULT-SLIM-THEME that
  442. ;; contains the actual theme files.
  443. "1.x")
  444. (define-record-type* <slim-configuration>
  445. slim-configuration make-slim-configuration
  446. slim-configuration?
  447. (slim slim-configuration-slim
  448. (default slim))
  449. (allow-empty-passwords? slim-configuration-allow-empty-passwords?
  450. (default #t))
  451. (auto-login? slim-configuration-auto-login?
  452. (default #f))
  453. (default-user slim-configuration-default-user
  454. (default ""))
  455. (theme slim-configuration-theme
  456. (default %default-slim-theme))
  457. (theme-name slim-configuration-theme-name
  458. (default %default-slim-theme-name))
  459. (xauth slim-configuration-xauth
  460. (default xauth))
  461. (shepherd slim-configuration-shepherd
  462. (default shepherd))
  463. (auto-login-session slim-configuration-auto-login-session
  464. (default #f))
  465. (xorg-configuration slim-configuration-xorg
  466. (default (xorg-configuration)))
  467. (display slim-configuration-display
  468. (default ":0"))
  469. (vt slim-configuration-vt
  470. (default "vt7"))
  471. (sessreg slim-configuration-sessreg
  472. (default sessreg)))
  473. (define (slim-pam-service config)
  474. "Return a PAM service for @command{slim}."
  475. (list (unix-pam-service
  476. "slim"
  477. #:login-uid? #t
  478. #:allow-empty-passwords?
  479. (slim-configuration-allow-empty-passwords? config))))
  480. (define (slim-shepherd-service config)
  481. (let* ((xinitrc (xinitrc #:fallback-session
  482. (slim-configuration-auto-login-session config)))
  483. (xauth (slim-configuration-xauth config))
  484. (startx (xorg-start-command (slim-configuration-xorg config)))
  485. (display (slim-configuration-display config))
  486. (vt (slim-configuration-vt config))
  487. (shepherd (slim-configuration-shepherd config))
  488. (theme-name (slim-configuration-theme-name config))
  489. (sessreg (slim-configuration-sessreg config))
  490. (lockfile (string-append "/var/run/slim-" vt ".lock")))
  491. (define slim.cfg
  492. (mixed-text-file "slim.cfg" "
  493. default_path /run/current-system/profile/bin
  494. default_xserver " startx "
  495. display_name " display "
  496. xserver_arguments " vt "
  497. xauth_path " xauth "/bin/xauth
  498. authfile /var/run/slim-" vt ".auth
  499. lockfile " lockfile "
  500. logfile /var/log/slim-" vt ".log
  501. # The login command. '%session' is replaced by the chosen session name, one
  502. # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
  503. login_cmd exec " xinitrc " %session
  504. sessiondir /run/current-system/profile/share/xsessions
  505. session_msg session (F1 to change):
  506. sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
  507. sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
  508. halt_cmd " shepherd "/sbin/halt
  509. reboot_cmd " shepherd "/sbin/reboot\n"
  510. (if (slim-configuration-auto-login? config)
  511. (string-append "auto_login yes\ndefault_user "
  512. (slim-configuration-default-user config) "\n")
  513. "")
  514. (if theme-name
  515. (string-append "current_theme " theme-name "\n")
  516. "")))
  517. (define theme
  518. (slim-configuration-theme config))
  519. (list (shepherd-service
  520. (documentation "Xorg display server")
  521. (provision (append
  522. ;; For compatibility, also provide 'xorg-server'.
  523. (if (string=? vt "vt7")
  524. '(xorg-server)
  525. '())
  526. (list (symbol-append 'xorg-server-
  527. (string->symbol vt)))))
  528. (requirement '(user-processes host-name udev))
  529. (start
  530. #~(lambda ()
  531. ;; A stale lock file can prevent SLiM from starting, so remove it to
  532. ;; be on the safe side.
  533. (false-if-exception (delete-file lockfile))
  534. (fork+exec-command
  535. (list (string-append #$(slim-configuration-slim config)
  536. "/bin/slim")
  537. "-nodaemon")
  538. #:environment-variables
  539. (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
  540. #$@(if theme
  541. (list #~(string-append "SLIM_THEMESDIR=" #$theme))
  542. #~())))))
  543. (stop #~(make-kill-destructor))
  544. (respawn? #t)))))
  545. (define slim-service-type
  546. (handle-xorg-configuration slim-configuration
  547. (service-type (name 'slim)
  548. (extensions
  549. (list (service-extension shepherd-root-service-type
  550. slim-shepherd-service)
  551. (service-extension pam-root-service-type
  552. slim-pam-service)
  553. ;; Unconditionally add xterm to the system profile, to
  554. ;; avoid bad surprises.
  555. (service-extension profile-service-type
  556. (const (list xterm)))))
  557. (default-value (slim-configuration))
  558. (description
  559. "Run the SLiM graphical login manager for X11."))))
  560. (define-deprecated (slim-service #:key (slim slim)
  561. (allow-empty-passwords? #t) auto-login?
  562. (default-user "")
  563. (theme %default-slim-theme)
  564. (theme-name %default-slim-theme-name)
  565. (xauth xauth) (shepherd shepherd)
  566. (auto-login-session #f)
  567. (startx (xorg-start-command)))
  568. slim-service-type
  569. "Return a service that spawns the SLiM graphical login manager, which in
  570. turn starts the X display server with @var{startx}, a command as returned by
  571. @code{xorg-start-command}.
  572. @cindex X session
  573. SLiM automatically looks for session types described by the @file{.desktop}
  574. files in @file{/run/current-system/profile/share/xsessions} and allows users
  575. to choose a session from the log-in screen using @kbd{F1}. Packages such as
  576. @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
  577. adding them to the system-wide set of packages automatically makes them
  578. available at the log-in screen.
  579. In addition, @file{~/.xsession} files are honored. When available,
  580. @file{~/.xsession} must be an executable that starts a window manager
  581. and/or other X clients.
  582. When @var{allow-empty-passwords?} is true, allow logins with an empty
  583. password. When @var{auto-login?} is true, log in automatically as
  584. @var{default-user} with @var{auto-login-session}.
  585. If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
  586. @var{theme} must be a gexp denoting the name of a directory containing the
  587. theme to use. In that case, @var{theme-name} specifies the name of the
  588. theme."
  589. (service slim-service-type
  590. (slim-configuration
  591. (slim slim)
  592. (allow-empty-passwords? allow-empty-passwords?)
  593. (auto-login? auto-login?) (default-user default-user)
  594. (theme theme) (theme-name theme-name)
  595. (xauth xauth) (shepherd shepherd)
  596. (auto-login-session auto-login-session))))
  597. ;;;
  598. ;;; Screen lockers & co.
  599. ;;;
  600. (define-record-type <screen-locker>
  601. (screen-locker name program empty?)
  602. screen-locker?
  603. (name screen-locker-name) ;string
  604. (program screen-locker-program) ;gexp
  605. (empty? screen-locker-allows-empty-passwords?)) ;Boolean
  606. (define screen-locker-pam-services
  607. (match-lambda
  608. (($ <screen-locker> name _ empty?)
  609. (list (unix-pam-service name
  610. #:allow-empty-passwords? empty?)))))
  611. (define screen-locker-setuid-programs
  612. (compose list screen-locker-program))
  613. (define screen-locker-service-type
  614. (service-type (name 'screen-locker)
  615. (extensions
  616. (list (service-extension pam-root-service-type
  617. screen-locker-pam-services)
  618. (service-extension setuid-program-service-type
  619. screen-locker-setuid-programs)))
  620. (description
  621. "Allow the given program to be used as a screen locker for
  622. the graphical server by making it setuid-root, so it can authenticate users,
  623. and by creating a PAM service for it.")))
  624. (define* (screen-locker-service package
  625. #:optional
  626. (program (package-name package))
  627. #:key allow-empty-passwords?)
  628. "Add @var{package}, a package for a screen locker or screen saver whose
  629. command is @var{program}, to the set of setuid programs and add a PAM entry
  630. for it. For example:
  631. @lisp
  632. (screen-locker-service xlockmore \"xlock\")
  633. @end lisp
  634. makes the good ol' XlockMore usable."
  635. (service screen-locker-service-type
  636. (screen-locker program
  637. (file-append package "/bin/" program)
  638. allow-empty-passwords?)))
  639. ;;;
  640. ;;; Locale service.
  641. ;;;
  642. (define-record-type* <localed-configuration>
  643. localed-configuration make-localed-configuration
  644. localed-configuration?
  645. (localed localed-configuration-localed
  646. (default localed))
  647. (keyboard-layout localed-configuration-keyboard-layout
  648. (default #f)))
  649. (define (localed-dbus-service config)
  650. "Return the 'localed' D-Bus service for @var{config}, a
  651. @code{<localed-configuration>} record."
  652. (define keyboard-layout
  653. (localed-configuration-keyboard-layout config))
  654. ;; The primary purpose of 'localed' is to tell GDM what the "current" Xorg
  655. ;; keyboard layout is. If 'localed' is missing, or if it's unable to
  656. ;; determine the current XKB layout, then GDM forcefully installs its
  657. ;; default XKB config (US English). Here we communicate the configured
  658. ;; layout through environment variables.
  659. (if keyboard-layout
  660. (let* ((layout (keyboard-layout-name keyboard-layout))
  661. (variant (keyboard-layout-variant keyboard-layout))
  662. (model (keyboard-layout-model keyboard-layout))
  663. (options (keyboard-layout-options keyboard-layout)))
  664. (list (wrapped-dbus-service
  665. (localed-configuration-localed config)
  666. "libexec/localed/localed"
  667. `(("GUIX_XKB_LAYOUT" ,layout)
  668. ,@(if variant
  669. `(("GUIX_XKB_VARIANT" ,variant))
  670. '())
  671. ,@(if model
  672. `(("GUIX_XKB_MODEL" ,model))
  673. '())
  674. ,@(if (null? options)
  675. '()
  676. `(("GUIX_XKB_OPTIONS"
  677. ,(string-join options ","))))))))
  678. '()))
  679. (define localed-service-type
  680. (let ((package (lambda (config)
  681. ;; Don't bother if the user didn't specify any keyboard
  682. ;; layout.
  683. (if (localed-configuration-keyboard-layout config)
  684. (list (localed-configuration-localed config))
  685. '()))))
  686. (service-type (name 'localed)
  687. (extensions
  688. (list (service-extension dbus-root-service-type
  689. localed-dbus-service)
  690. (service-extension udev-service-type package)
  691. (service-extension polkit-service-type package)
  692. ;; Add 'localectl' to the profile.
  693. (service-extension profile-service-type package)))
  694. ;; This service can be extended, typically by the X login
  695. ;; manager, to communicate the chosen Xorg keyboard layout.
  696. (compose (lambda (extensions)
  697. (find keyboard-layout? extensions)))
  698. (extend (lambda (config keyboard-layout)
  699. (localed-configuration
  700. (inherit config)
  701. (keyboard-layout keyboard-layout))))
  702. (description
  703. "Run the locale daemon, @command{localed}, which can be used
  704. to control the system locale and keyboard mapping from user programs such as
  705. the GNOME desktop environment.")
  706. (default-value (localed-configuration)))))
  707. ;;;
  708. ;;; GNOME Desktop Manager.
  709. ;;;
  710. (define %gdm-accounts
  711. (list (user-group (name "gdm") (system? #t))
  712. (user-account
  713. (name "gdm")
  714. (group "gdm")
  715. (supplementary-groups '("video"))
  716. (system? #t)
  717. (comment "GNOME Display Manager user")
  718. (home-directory "/var/lib/gdm")
  719. (shell (file-append shadow "/sbin/nologin")))))
  720. (define %gdm-activation
  721. ;; Ensure /var/lib/gdm is owned by the "gdm" user. This is normally the
  722. ;; case but could be wrong if the "gdm" user was created, then removed, and
  723. ;; then recreated under a different UID/GID: <https://bugs.gnu.org/37423>.
  724. (with-imported-modules '((guix build utils))
  725. #~(begin
  726. (use-modules (guix build utils))
  727. (let* ((gdm (getpwnam "gdm"))
  728. (uid (passwd:uid gdm))
  729. (gid (passwd:gid gdm))
  730. (st (stat "/var/lib/gdm" #f)))
  731. ;; Recurse into /var/lib/gdm only if it has wrong ownership.
  732. (when (and st
  733. (or (not (= uid (stat:uid st)))
  734. (not (= gid (stat:gid st)))))
  735. (for-each (lambda (file)
  736. (chown file uid gid))
  737. (find-files "/var/lib/gdm"
  738. #:directories? #t)))))))
  739. (define dbus-daemon-wrapper
  740. (program-file
  741. "gdm-dbus-wrapper"
  742. #~(begin
  743. (use-modules (srfi srfi-26))
  744. (define system-profile
  745. "/run/current-system/profile")
  746. (define user-profile
  747. (and=> (getpw (getuid))
  748. (lambda (pw)
  749. (string-append (passwd:dir pw) "/.guix-profile"))))
  750. ;; If we are able to find the user's profile, we can add it to
  751. ;; the search paths set below. We need to do this so that D-Bus
  752. ;; can start services installed by the user. This allows
  753. ;; applications that require session D-Bus services (e.g,
  754. ;; 'evolution') to work even if those services are only available
  755. ;; in the user's profile. See <https://bugs.gnu.org/35267>.
  756. (define profiles
  757. (if user-profile
  758. (list user-profile system-profile)
  759. (list system-profile)))
  760. (setenv "XDG_CONFIG_DIRS"
  761. (string-join (map (cut string-append <> "/etc/xdg") profiles)
  762. ":"))
  763. (setenv "XDG_DATA_DIRS"
  764. (string-join (map (cut string-append <> "/share") profiles)
  765. ":"))
  766. (apply execl (string-append #$dbus "/bin/dbus-daemon")
  767. (program-arguments)))))
  768. (define-record-type* <gdm-configuration>
  769. gdm-configuration make-gdm-configuration
  770. gdm-configuration?
  771. (gdm gdm-configuration-gdm (default gdm))
  772. (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
  773. (auto-login? gdm-configuration-auto-login? (default #f))
  774. (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
  775. (debug? gdm-configuration-debug? (default #f))
  776. (default-user gdm-configuration-default-user (default #f))
  777. (gnome-shell-assets gdm-configuration-gnome-shell-assets
  778. (default (list adwaita-icon-theme font-cantarell)))
  779. (xorg-configuration gdm-configuration-xorg
  780. (default (xorg-configuration)))
  781. (x-session gdm-configuration-x-session
  782. (default (xinitrc))))
  783. (define (gdm-configuration-file config)
  784. (mixed-text-file "gdm-custom.conf"
  785. "[daemon]\n"
  786. "#User=gdm\n"
  787. "#Group=gdm\n"
  788. (if (gdm-configuration-auto-login? config)
  789. (string-append
  790. "AutomaticLoginEnable=true\n"
  791. "AutomaticLogin="
  792. (or (gdm-configuration-default-user config)
  793. (error "missing default user for auto-login"))
  794. "\n")
  795. (string-append
  796. "AutomaticLoginEnable=false\n"
  797. "#AutomaticLogin=\n"))
  798. "#TimedLoginEnable=false\n"
  799. "#TimedLogin=\n"
  800. "#TimedLoginDelay=0\n"
  801. ;; Disable initial system setup inside GDM.
  802. ;; Whatever settings are set there should already be
  803. ;; taken care of through `guix system'.
  804. ;; See also
  805. ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=39281>.
  806. "InitialSetupEnable=false\n"
  807. ;; Enable me once X is working.
  808. "WaylandEnable=false\n"
  809. "\n"
  810. "[debug]\n"
  811. "Enable=" (if (gdm-configuration-debug? config)
  812. "true"
  813. "false") "\n"
  814. "\n"
  815. "[security]\n"
  816. "#DisallowTCP=true\n"
  817. "#AllowRemoteAutoLogin=false\n"))
  818. (define (gdm-pam-service config)
  819. "Return a PAM service for @command{gdm}."
  820. (list
  821. (pam-service
  822. (inherit (unix-pam-service "gdm-autologin"
  823. #:login-uid? #t))
  824. (auth (list (pam-entry
  825. (control "optional")
  826. (module (file-append (gdm-configuration-gdm config)
  827. "/lib/security/pam_gdm.so")))
  828. (pam-entry
  829. (control "sufficient")
  830. (module "pam_permit.so")))))
  831. (pam-service
  832. (inherit (unix-pam-service "gdm-launch-environment"))
  833. (auth (list (pam-entry
  834. (control "required")
  835. (module "pam_permit.so")))))
  836. (unix-pam-service "gdm-password"
  837. #:login-uid? #t
  838. #:allow-empty-passwords?
  839. (gdm-configuration-allow-empty-passwords? config))))
  840. (define (gdm-shepherd-service config)
  841. (list (shepherd-service
  842. (documentation "Xorg display server (GDM)")
  843. (provision '(xorg-server))
  844. (requirement '(dbus-system user-processes host-name udev))
  845. (start #~(lambda ()
  846. (fork+exec-command
  847. (list #$(file-append (gdm-configuration-gdm config)
  848. "/bin/gdm"))
  849. #:environment-variables
  850. (list (string-append
  851. "GDM_CUSTOM_CONF="
  852. #$(gdm-configuration-file config))
  853. (string-append
  854. "GDM_DBUS_DAEMON="
  855. #$(gdm-configuration-dbus-daemon config))
  856. (string-append
  857. "GDM_X_SERVER="
  858. #$(xorg-wrapper
  859. (gdm-configuration-xorg config)))
  860. (string-append
  861. "GDM_X_SESSION="
  862. #$(gdm-configuration-x-session config))
  863. (string-append
  864. "XDG_DATA_DIRS="
  865. ((lambda (ls) (string-join ls ":"))
  866. (map (lambda (path)
  867. (string-append path "/share"))
  868. ;; XXX: Remove gnome-shell below when GDM
  869. ;; can depend on GNOME Shell directly.
  870. (cons #$gnome-shell
  871. '#$(gdm-configuration-gnome-shell-assets
  872. config)))))))))
  873. (stop #~(make-kill-destructor))
  874. (respawn? #t))))
  875. (define gdm-service-type
  876. (handle-xorg-configuration gdm-configuration
  877. (service-type (name 'gdm)
  878. (extensions
  879. (list (service-extension shepherd-root-service-type
  880. gdm-shepherd-service)
  881. (service-extension activation-service-type
  882. (const %gdm-activation))
  883. (service-extension account-service-type
  884. (const %gdm-accounts))
  885. (service-extension pam-root-service-type
  886. gdm-pam-service)
  887. (service-extension profile-service-type
  888. gdm-configuration-gnome-shell-assets)
  889. (service-extension dbus-root-service-type
  890. (compose list
  891. gdm-configuration-gdm))
  892. (service-extension localed-service-type
  893. (compose
  894. xorg-configuration-keyboard-layout
  895. gdm-configuration-xorg))))
  896. (default-value (gdm-configuration))
  897. (description
  898. "Run the GNOME Desktop Manager (GDM), a program that allows
  899. you to log in in a graphical session, whether or not you use GNOME."))))
  900. (define-deprecated (gdm-service #:key (gdm gdm)
  901. (allow-empty-passwords? #t)
  902. (x-server (xorg-wrapper)))
  903. gdm-service-type
  904. "Return a service that spawns the GDM graphical login manager, which in turn
  905. starts the X display server with @var{X}, a command as returned by
  906. @code{xorg-wrapper}.
  907. @cindex X session
  908. GDM automatically looks for session types described by the @file{.desktop}
  909. files in @file{/run/current-system/profile/share/xsessions} and allows users
  910. to choose a session from the log-in screen using @kbd{F1}. Packages such as
  911. @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
  912. adding them to the system-wide set of packages automatically makes them
  913. available at the log-in screen.
  914. In addition, @file{~/.xsession} files are honored. When available,
  915. @file{~/.xsession} must be an executable that starts a window manager
  916. and/or other X clients.
  917. When @var{allow-empty-passwords?} is true, allow logins with an empty
  918. password."
  919. (service gdm-service-type
  920. (gdm-configuration
  921. (gdm gdm)
  922. (allow-empty-passwords? allow-empty-passwords?))))
  923. (define* (set-xorg-configuration config
  924. #:optional
  925. (login-manager-service-type
  926. gdm-service-type))
  927. "Tell the log-in manager (of type @var{login-manager-service-type}) to use
  928. @var{config}, an <xorg-configuration> record."
  929. (simple-service 'set-xorg-configuration
  930. login-manager-service-type
  931. config))
  932. ;;; xorg.scm ends here