Subject: [PATCH] services: xorg: Make startx respect XDG_VTR.

From: Sergey Trofimov <[email-masked]>
Date: Mon, 5 May 2025 12:04:28 +0200

To allow X server to be started by shepherd, without resorting to login
managers, the determine-vty procedure has to be adjusted. Shepherd would
as set /proc/self/fd/0 to /dev/null when starting the service, so the
TTY has to be extracted by other means.

* gnu/services/xorg.scm (xorg-start-command-xinit): Use XDG_VTR
environment variable to determine VTY.

Change-Id: I390217e292f6534b31d18083c9a49c009a836aad
---
 gnu/services/xorg.scm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index bef05b9bb9..d5d7ffbc4c 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -451,13 +451,17 @@ (define* (xorg-start-command-xinit #:optional (config (xorg-configuration)))
                        (eq? 'socket (stat:type (stat sock-file)))))
                   (determine-unused-display (+ n 1))
                   (format #f ":~a" n))))
-          (define (determine-vty)
+
+          (define (vty-from-fd0)
             (let ((fd0 (readlink "/proc/self/fd/0"))
                   (pref "/dev/tty"))
               (if (string-prefix? pref fd0)
-                  (string-append "vt" (substring fd0 (string-length pref)))
+                  (substring fd0 (string-length pref))
                   (error (format #f "Cannot determine VT from: ~a" fd0)))))
 
+          (define (determine-vty)
+            (string-append "vt" (or (getenv "XDG_VTNR") (vty-from-fd0))))
+
           (define (enable-xauth server-auth-file display)
             ;; Configure and enable X authority
             (or (getenv "XAUTHORITY")

base-commit: 17119f1a35b7bff683f2f8f2b5db09b4634283e6
prerequisite-patch-id: f9cc903b8048c8c6fde576fbf38ab110263020e3
prerequisite-patch-id: b6d30068ce4971d4d8e67517229916df4e76c529
prerequisite-patch-id: a7d0b89bff79773111c364edcd67265df55a0234
prerequisite-patch-id: c99e71b3eaa726b8ecf2d9b782d5a6a51476e702
prerequisite-patch-id: a3f8e48f417d7a17d9db12e950354a0220dc52f3
prerequisite-patch-id: 8456c216a2d8dd3d6c403243c0d9452fbb138ecf
prerequisite-patch-id: 95bb686bc7dc0961b89a2900a368f270de065d94
prerequisite-patch-id: f56033bf148a2fdfb5d9321315bdff877ebdb7ba
-- 
2.49.0