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