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