xorg.scm 40 KB

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