xorg.scm 42 KB

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