xorg.scm 40 KB

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