GNU bug report logs - #68289
[PATCH] services: xorg: Add xorg-start-command-xinit procedure.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Tomas Volf <~@wolfsden.cz>; Keywords: patch; dated Sat, 6 Jan 2024 15:08:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 6 Jan 2024 15:07:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 06 10:07:32 2024
Received: from localhost ([127.0.0.1]:60134 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rM8Gq-00045z-BT
	for submit <at> debbugs.gnu.org; Sat, 06 Jan 2024 10:07:32 -0500
Received: from lists.gnu.org ([2001:470:142::17]:32998)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <~@wolfsden.cz>) id 1rM8Go-00045l-1Q
 for submit <at> debbugs.gnu.org; Sat, 06 Jan 2024 10:07:30 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1rM8Gd-0003dn-Fn
 for guix-patches@HIDDEN; Sat, 06 Jan 2024 10:07:19 -0500
Received: from wolfsden.cz ([37.205.8.62])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <~@wolfsden.cz>) id 1rM8Ga-0005rP-G9
 for guix-patches@HIDDEN; Sat, 06 Jan 2024 10:07:19 -0500
Received: by wolfsden.cz (Postfix, from userid 104)
 id 413A2246305; Sat,  6 Jan 2024 15:07:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail;
 t=1704553633; bh=sG/9/+vKvhzXNypfAwUgTzXbjxvb59xBuzXBAJME6f4=;
 h=From:To:Cc:Subject:Date;
 b=oL0i83f5PDSX1zJhu6aCot3IVlCFw9m4qriiCM2mP12AwFFJqBNuvtmh0+Ozjidlz
 4n7Cep9BniLJylqhHNzfXglB7M8PFfyQDbS2ZSGBxPsWAx1qp8NtVBXpWiPNn1P/i9
 mr9OnrQ2Ltm5cMDNYlFgkRbt8VZnyAojJaCtax8VLQDqUKXqBU6Y4MFMLG8qFS5SHR
 cN24fgCK1F1W+iZNq8HdKqo2K6qu135wdNBAy9wlGTB0xLz9rTX8lQ6MmkbtDQY9yp
 U+xSC49QAPk+uK378UsWONExUukWSnCr9x+4rJBJlcTqVDmgUM+suo2x9zWb/8I2C6
 XEwr3KZd0zV0BcG9EeCRXOEsHKtacjL2+RQv7X8gofwDUAn4ri5indmUyPbZa2zpb0
 VdCR0rg5EfysnfQjCpXcKwYkOFxzH8RxTH/MaA3P/xU1Y6iNbY1M6q+XwtxTFNQTIL
 kGhBphqS0gYeDpdw2tWrwO1JoLz2OhK56tfe2pXHoREGAF3h1Oq/sl0GmvGjHxIpo/
 Fkno8R43a+TC2jyfz8NwmCSF01/22m6PhoR7owJqK6SOr3FsrZHuRouJ6I6jwW8gWn
 eQQyTJ1eHEG2yv4VU4QvHZj9mUSLc34nhz2p8vPkG8cRr6SNwKFKdH/cIxSkDp7tNB
 pZ6+31Y8BCKlZEuGCJSSA7QU=
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on wolfsden
X-Spam-Level: 
X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,T_SCC_BODY_TEXT_LINE,
 URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6
Received: from localhost (unknown [193.32.127.155])
 by wolfsden.cz (Postfix) with ESMTPSA id 538182448D7;
 Sat,  6 Jan 2024 15:07:12 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail;
 t=1704553632; bh=sG/9/+vKvhzXNypfAwUgTzXbjxvb59xBuzXBAJME6f4=;
 h=From:To:Cc:Subject:Date;
 b=f6wRG1YuNjiUPi9mF0RALvYdbrqYKztgb3Tjsw6Khdx7XM8u5oq6Q1VI9u/vrrg13
 ELHMF9mOCWnwyxjJmrQkPChzgq4Oeq/XnNX9IjoYre+eZk4q+vdHs9XZ5h4h69w8mA
 UxuxJNsjv/+jUPayw0Vd08T8KS6amyPRWe6JqpMTnRwMeuVpxsSUmcUe2U49HrocsP
 B5fEi9OnHocBTEiKGmXKpYI535ntQulvkYcWezQuIbnTFnCIDnCRDJVcshtkHLpSgI
 qC57U1SblzEQ2zYH7EDCUq3KGxg+K27A8R/RA26NPUlde10N8zTgbjLY2TmlDdwUBb
 yoBwTl06iqfZmnFEZXe0yH3Iu5hPj9l1F65UAmOaEJOaB8bz/0dmL5LodZSRKQht/b
 9NfpjMOOqNcAnIdNukeuGUBtNLPzA8w+BUUSi55qv0ljyArtioScXr3gkh/+stJMBF
 p7ZWtLEyGj+aBv1t+fWEf4ZO6HX31VUMgeTtAQRP5yiw46QHyL56v2AQ6vxUTesG+a
 DIK6i1CBTiFs22MkFKCGO/LfP8/EGzfvmQQPxBuDISJ17/hiIcsbFoeSArZwc4UJ+v
 Y0aGt4SvIrDZ3uHqK5+gTSyajWuSp5ApV4IcmG9rJua/TQFFqhLbUvVuO3krolv5UQ
 HwC6DJkv3bqmvYlktJOVEjWk=
From: Tomas Volf <~@wolfsden.cz>
To: guix-patches@HIDDEN
Subject: [PATCH] services: xorg: Add xorg-start-command-xinit procedure.
Date: Sat,  6 Jan 2024 16:07:09 +0100
Message-ID: <4fdf0d9993bb3375797ca807d894f66920bd81d2.1704553618.git.~@wolfsden.cz>
X-Mailer: git-send-email 2.41.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=37.205.8.62; envelope-from=~@wolfsden.cz;
 helo=wolfsden.cz
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
Cc: Tomas Volf <~@wolfsden.cz>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

When user does not use any desktop environment, the typical sequence is to log
in and then type `startx' into the tty to get a window manager running.  Most
distributions do provide startx by default, but Guix has only
xorg-start-command, that is not suitable for this type of task.

This commit adds second procedure, xorg-start-command-xinit, that correctly
picks virtual terminal to use, sets up XAUTHORITY and starts xinit with
correct arguments.  That should make running Guix without any desktop
environment more approachable.

* gnu/services/xorg.scm (xorg-start-command-xinit): New procedure.
(define-module): Export it.
* doc/guix.texi (X Window): Document it.

Change-Id: I17cb16093d16a5c6550b1766754700d4fe014ae9
---
 doc/guix.texi         | 18 ++++++++++
 gnu/services/xorg.scm | 82 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index a648a106b3..72c5527270 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -23177,6 +23177,24 @@ X Window
 Usually the X server is started by a login manager.
 @end deffn
 
+@deffn {Procedure} xorg-start-command-xinit [config]
+Return a @code{startx} script in which the modules, fonts,
+etc. specified in @var{config}, are available.  The result should be
+used in place of @code{startx}.  Compared to the
+@code{xorg-start-command} it calls xinit, therefore it works well when
+executed from tty.  If you are using a desktop environment, you are
+unlikely to have a need for this procedure.
+
+The resulting file should be invoked by user from the tty after login,
+common name for the program would be @code{startx}.  Convenience link
+can be created by (for example) this home service:
+
+@lisp
+(simple-service 'home-files home-files-service-type
+                `(("bin/startx" ,(xorg-start-command-xinit))))
+@end lisp
+@end deffn
+
 
 @defvar screen-locker-service-type
 Type for a service that adds a package for a screen locker or screen
diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index 1ee15ea90c..2f5aa3b4f3 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -53,6 +53,7 @@ (define-module (gnu services xorg)
   #:use-module (gnu packages gnome)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages bash)
+  #:use-module (gnu packages linux)
   #:use-module (gnu system shadow)
   #:use-module (guix build-system glib-or-gtk)
   #:use-module (guix build-system trivial)
@@ -84,6 +85,7 @@ (define-module (gnu services xorg)
 
             xorg-wrapper
             xorg-start-command
+            xorg-start-command-xinit
             xinitrc
             xorg-server-service-type
 
@@ -414,6 +416,86 @@ (define* (xorg-start-command #:optional (config (xorg-configuration)))
 
   (program-file "startx" exp))
 
+(define* (xorg-start-command-xinit #:optional (config (xorg-configuration)))
+  "Return a @code{startx} script in which the modules, fonts, etc. specified in
+@var{config}, are available.  The result should be used in place of
+@code{startx}.  Compared to the @code{xorg-start-command} it calls xinit,
+therefore it works well when executed from tty."
+  (define X
+    (xorg-wrapper config))
+
+  (define exp
+    ;; Small wrapper providing subset of functionality of typical startx script
+    ;; from distributions like alpine.
+    #~(begin
+        (use-modules (ice-9 popen)
+                     (ice-9 textual-ports))
+
+        (define (checked-system* . args)
+          (if (= 0 (status:exit-val (apply system* args)))
+              #t
+              (error "command failed")))
+
+        (define (capture-stdout . prog+args)
+          (let* ((port (apply open-pipe* OPEN_READ prog+args))
+                 (data (get-string-all port)))
+            (if (= 0 (status:exit-val (close-pipe port)))
+                (string-trim-right data #\newline)
+                (error "command failed"))))
+
+        (define (determine-unused-display n)
+          (let ((lock-file (format #f "/tmp/.X~a-lock" n))
+                (sock-file (format #f "/tmp/.X11-unix/X~a" n)))
+            (if (or (file-exists? lock-file)
+                    (false-if-exception
+                     (eq? 'socket (stat:type (stat sock-file)))))
+                (determine-unused-display (+ n 1))
+                (format #f ":~a" n))))
+        (define (determine-vty)
+          (let ((fd0 (readlink "/proc/self/fd/0"))
+                (pref "/dev/tty"))
+            (if (string-prefix? pref fd0)
+                (string-append "vt" (substring fd0 (string-length pref)))
+                (error (format #f "Cannot determine VT from: ~a" fd0)))))
+
+        (define (enable-xauth server-auth-file display)
+          ;; Configure and enable X authority
+          (or (getenv "XAUTHORITY")
+              (setenv "XAUTHORITY" (string-append (getenv "HOME") "/.Xauthority")))
+
+          (let* ((bin/xauth (string-append #$xauth "/bin/xauth"))
+                 (bin/mcookie (string-append #$util-linux "/bin/mcookie"))
+
+                 (mcookie (capture-stdout bin/mcookie)))
+            (checked-system* bin/xauth "-qf" server-auth-file
+                             "add" display "." mcookie)
+            (checked-system* bin/xauth "-q"
+                             "add" display "." mcookie)))
+
+        (let* ((xinit (string-append #$xinit "/bin/xinit"))
+               (display (determine-unused-display 0))
+               (vty (determine-vty))
+               (server-auth-port (mkstemp "/tmp/serverauth.XXXXXX"))
+               (server-auth-file (port-filename server-auth-port)))
+          (close-port server-auth-port)
+          (enable-xauth server-auth-file display)
+          (apply execl
+                 xinit
+                 xinit
+                 "--"
+                 #$X
+                 display
+                 vty
+                 "-keeptty"
+                 "-auth" server-auth-file
+                 ;; These are set by xorg-start-command, so do the same to keep
+                 ;; it consistent.
+                 "-logverbose" "-verbose" "-terminate"
+                 #$@(xorg-configuration-server-arguments config)
+                 (cdr (command-line))))))
+
+  (program-file "startx" exp))
+
 (define* (xinitrc #:key fallback-session)
   "Return a system-wide xinitrc script that starts the specified X session,
 which should be passed to this script as the first argument.  If not, the

base-commit: e994bc0abf39db228fa61f1aaf24840c19c47647
-- 
2.41.0





Acknowledgement sent to Tomas Volf <~@wolfsden.cz>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#68289; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 20 Jan 2024 12:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.