services: slim: Allow SLiM to be started on multiple ttys.

This change makes it possible to add multiple SLiM services to an operating
system configuration by setting the new 'display' and 'vt' fields in their
configurations to different values.  Each SLiM service will get its own
authfile, logfile, lockfile, and shepherd service, which will start SLiM on a
different tty.

* gnu/services/xorg.scm: Export slim-configuration-display and
  slim-configuration-vt.
  (<slim-configuration>)[display, vt]: New fields.
  (slim-shepherd-service): Refactor let.
  [slim.cfg]: Use new fields for setting display_name, xserver_arguments,
  authfile, lockfile, and logfile.
  [shepherd-service][provision]: Name the shepherd service according to the
  value of 'vt'.
  [shepherd-service][start]: Delete the right lockfile.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Diego Nicola Barbato 2019-04-28 15:52:50 +02:00 committed by Ludovic Courtès
parent 6426a8fb6c
commit 61569171d0
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -83,6 +83,8 @@ (define-module (gnu services xorg)
slim-configuration-shepherd slim-configuration-shepherd
slim-configuration-auto-login-session slim-configuration-auto-login-session
slim-configuration-xorg slim-configuration-xorg
slim-configuration-display
slim-configuration-vt
slim-configuration-sessreg slim-configuration-sessreg
slim-service-type slim-service-type
@ -488,6 +490,10 @@ (define-record-type* <slim-configuration>
(default #f)) (default #f))
(xorg-configuration slim-configuration-xorg (xorg-configuration slim-configuration-xorg
(default (xorg-configuration))) (default (xorg-configuration)))
(display slim-configuration-display
(default ":0"))
(vt slim-configuration-vt
(default "vt7"))
(sessreg slim-configuration-sessreg (sessreg slim-configuration-sessreg
(default sessreg))) (default sessreg)))
@ -499,20 +505,26 @@ (define (slim-pam-service config)
(slim-configuration-allow-empty-passwords? config)))) (slim-configuration-allow-empty-passwords? config))))
(define (slim-shepherd-service config) (define (slim-shepherd-service config)
(define slim.cfg (let* ((xinitrc (xinitrc #:fallback-session
(let ((xinitrc (xinitrc #:fallback-session (slim-configuration-auto-login-session config)))
(slim-configuration-auto-login-session config))) (xauth (slim-configuration-xauth config))
(xauth (slim-configuration-xauth config)) (startx (xorg-start-command (slim-configuration-xorg config)))
(startx (xorg-start-command (slim-configuration-xorg config))) (display (slim-configuration-display config))
(shepherd (slim-configuration-shepherd config)) (vt (slim-configuration-vt config))
(theme-name (slim-configuration-theme-name config)) (shepherd (slim-configuration-shepherd config))
(sessreg (slim-configuration-sessreg config))) (theme-name (slim-configuration-theme-name config))
(sessreg (slim-configuration-sessreg config))
(lockfile (string-append "/var/run/slim-" vt ".lock")))
(define slim.cfg
(mixed-text-file "slim.cfg" " (mixed-text-file "slim.cfg" "
default_path /run/current-system/profile/bin default_path /run/current-system/profile/bin
default_xserver " startx " default_xserver " startx "
xserver_arguments :0 vt7 display_name " display "
xserver_arguments " vt "
xauth_path " xauth "/bin/xauth xauth_path " xauth "/bin/xauth
authfile /var/run/slim.auth authfile /var/run/slim-" vt ".auth
lockfile " lockfile "
logfile /var/log/slim-" vt ".log
# The login command. '%session' is replaced by the chosen session name, one # The login command. '%session' is replaced by the chosen session name, one
# of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc. # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
@ -530,32 +542,33 @@ (define slim.cfg
"") "")
(if theme-name (if theme-name
(string-append "current_theme " theme-name "\n") (string-append "current_theme " theme-name "\n")
"")))) "")))
(define theme (define theme
(slim-configuration-theme config)) (slim-configuration-theme config))
(list (shepherd-service (list (shepherd-service
(documentation "Xorg display server") (documentation "Xorg display server")
(provision '(xorg-server)) (provision (list (symbol-append 'xorg-server-
(requirement '(user-processes host-name udev)) (string->symbol vt))))
(start (requirement '(user-processes host-name udev))
#~(lambda () (start
;; A stale lock file can prevent SLiM from starting, so remove it to #~(lambda ()
;; be on the safe side. ;; A stale lock file can prevent SLiM from starting, so remove it to
(false-if-exception (delete-file "/var/run/slim.lock")) ;; be on the safe side.
(false-if-exception (delete-file lockfile))
(fork+exec-command (fork+exec-command
(list (string-append #$(slim-configuration-slim config) (list (string-append #$(slim-configuration-slim config)
"/bin/slim") "/bin/slim")
"-nodaemon") "-nodaemon")
#:environment-variables #:environment-variables
(list (string-append "SLIM_CFGFILE=" #$slim.cfg) (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
#$@(if theme #$@(if theme
(list #~(string-append "SLIM_THEMESDIR=" #$theme)) (list #~(string-append "SLIM_THEMESDIR=" #$theme))
#~()))))) #~())))))
(stop #~(make-kill-destructor)) (stop #~(make-kill-destructor))
(respawn? #t)))) (respawn? #t)))))
(define slim-service-type (define slim-service-type
(service-type (name 'slim) (service-type (name 'slim)