xorg.scm 43 KB

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