From patchwork Sat Jan 6 15:07:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Volf <~@wolfsden.cz> X-Patchwork-Id: 58430 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9F85527BBEA; Sat, 6 Jan 2024 15:08:26 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 74A1527BBE2 for ; Sat, 6 Jan 2024 15:08:24 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rM8HS-00040z-Pb; Sat, 06 Jan 2024 10:08:14 -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 ) id 1rM8HH-0003yW-4W for guix-patches@gnu.org; Sat, 06 Jan 2024 10:07:59 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM8HF-0005vV-Aj for guix-patches@gnu.org; Sat, 06 Jan 2024 10:07:57 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rM8HK-00046l-7r for guix-patches@gnu.org; Sat, 06 Jan 2024 10:08:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68289] [PATCH] services: xorg: Add xorg-start-command-xinit procedure. Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 06 Jan 2024 15:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68289 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68289@debbugs.gnu.org Cc: Tomas Volf <~@wolfsden.cz> X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.170455365315751 (code B ref -1); Sat, 06 Jan 2024 15:08:02 +0000 Received: (at submit) by debbugs.gnu.org; 6 Jan 2024 15:07:33 +0000 Received: from localhost ([127.0.0.1]:60134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM8Gq-00045z-BT for submit@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@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@gnu.org; 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@gnu.org; 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= 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> 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 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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(+) base-commit: e994bc0abf39db228fa61f1aaf24840c19c47647 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