xorg.scm 43 KB

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