From: Tomas Volf <~@wolfsden.cz>
To: 68289@debbugs.gnu.org
Cc: Tomas Volf <~@wolfsden.cz>
Subject: [bug#68289] [PATCH] services: xorg: Add xorg-start-command-xinit procedure.
Date: Sat, 6 Jan 2024 16:07:09 +0100 [thread overview]
Message-ID: <4fdf0d9993bb3375797ca807d894f66920bd81d2.1704553618.git.~@wolfsden.cz> (raw)
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
next reply other threads:[~2024-01-06 15:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-06 15:07 Tomas Volf [this message]
2024-04-16 18:29 ` [bug#68289] [PATCH] services: xorg: Add xorg-start-command-xinit procedure Fabio Natali via Guix-patches via
2024-04-17 9:30 ` Fabio Natali via Guix-patches via
2024-04-18 18:43 ` Fabio Natali via Guix-patches via
2024-04-18 21:17 ` Tomas Volf
2024-04-18 21:09 ` Tomas Volf
2024-04-19 12:25 ` Fabio Natali via Guix-patches via
2024-04-24 11:59 ` Fabio Natali via Guix-patches via
2024-04-24 17:43 ` Tomas Volf
2024-05-02 9:55 ` Ludovic Courtès
2024-05-02 14:58 ` Tomas Volf
2024-05-03 9:57 ` Ludovic Courtès
2024-05-11 13:29 ` Tomas Volf
2024-05-11 13:26 ` [bug#68289] [PATCH v2 1/3] " Tomas Volf
2024-05-11 13:26 ` [bug#68289] [PATCH v2 2/3] services: xorg: Add startx-command-service-type Tomas Volf
2024-05-11 13:26 ` [bug#68289] [PATCH v2 3/3] home: services: Add home-startx-command-service-type Tomas Volf
2024-05-30 17:33 ` [bug#68289] [PATCH] services: xorg: Add xorg-start-command-xinit procedure Arun Isaac
2024-05-30 18:27 ` Tomas Volf
2024-05-30 18:18 ` [bug#68289] [PATCH v3 1/2] services: xorg: Add startx-command-service-type Tomas Volf
2024-05-30 18:18 ` [bug#68289] [PATCH v3 2/2] home: services: Add home-startx-command-service-type Tomas Volf
2024-05-30 18:29 ` [bug#68289] [PATCH v4 1/2] services: xorg: Add startx-command-service-type Tomas Volf
2024-05-30 18:29 ` [bug#68289] [PATCH v4 2/2] home: services: Add home-startx-command-service-type Tomas Volf
2024-05-30 21:43 ` bug#68289: [PATCH] services: xorg: Add xorg-start-command-xinit procedure Arun Isaac
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='4fdf0d9993bb3375797ca807d894f66920bd81d2.1704553618.git.~@wolfsden.cz' \
--to=~@wolfsden.cz \
--cc=68289@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.