From patchwork Sat May 11 13:26:23 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: 27383 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 E148427BBEA; Sat, 11 May 2024 14:28:30 +0100 (BST) 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 440ED27BBE9 for ; Sat, 11 May 2024 14:28:26 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5mlj-00083T-LG; Sat, 11 May 2024 09:28:07 -0400 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 1s5mlh-00081U-BJ for guix-patches@gnu.org; Sat, 11 May 2024 09:28:05 -0400 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 1s5mlg-0001yW-6Y; Sat, 11 May 2024 09:28:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s5mle-000771-H0; Sat, 11 May 2024 09:28:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#68289] [PATCH v2 1/3] services: xorg: Add xorg-start-command-xinit procedure. References: <4fdf0d9993bb3375797ca807d894f66920bd81d2.1704553618.git.~@wolfsden.cz> In-Reply-To: <4fdf0d9993bb3375797ca807d894f66920bd81d2.1704553618.git.~@wolfsden.cz> Resent-From: Tomas Volf <~@wolfsden.cz> Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, guix-patches@gnu.org Resent-Date: Sat, 11 May 2024 13:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68289 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68289@debbugs.gnu.org Cc: Tomas Volf <~@wolfsden.cz>, Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 68289-submit@debbugs.gnu.org id=B68289.171543407927320 (code B ref 68289); Sat, 11 May 2024 13:28:02 +0000 Received: (at 68289) by debbugs.gnu.org; 11 May 2024 13:27:59 +0000 Received: from localhost ([127.0.0.1]:48364 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5mlb-00076Y-49 for submit@debbugs.gnu.org; Sat, 11 May 2024 09:27:59 -0400 Received: from wolfsden.cz ([37.205.8.62]:50972) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <~@wolfsden.cz>) id 1s5mlX-00076D-Ox for 68289@debbugs.gnu.org; Sat, 11 May 2024 09:27:57 -0400 Received: by wolfsden.cz (Postfix, from userid 104) id 2655D287B77; Sat, 11 May 2024 13:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1715434074; bh=kFJZSer9CFhYedqtwpROWs6QdH1hOKy/ROas61wnOO4=; h=From:To:Cc:Subject:Date; b=K6jSpn5HTSMYxLM2rf4/nc+2dh9DbcgyFnN4gsbjUir6VbCT6SpXnDAnXdYVBwNQL L+7qxPlRRFwYJ5Lt8iDQRBmf45llRyj6lU4ZRONpQtOT1usy2hPHYteQj0znPoq5NW oYez/fSb50C3VsKw3Wn4zAcFqueQcC7trcKWGOSOnyJLEVNq/otWcfaP0lVAMRz5pu eOBWbwALzORVmt4k3LO8f74z7Zg+FuNyPaNoD7WfKelYdIHkOL9bLtLx+SNlFmt4Pe 2cxziL7nL4tTCAPdnbXb55eBosjx98KWmbQFWiWn7AJJvoNQCQp2MXVhA3G2t9BFDc sSBl48PTR8B2lawJhrRIRKtn02jLNsAnxMH6qlXJM8Mpszzq7pMIJJCYhdQ3fWc+QV q1L49Al+6EQMzJ8yR3bXqYz3MaqTNGYv9i9AZAa8LVhTev7gWLco2UuYCRHBBLOX+y O9Zdr8mkPTlZ18gNMSOv5MsuecBSgItaqWVhArC0DAcROQuEw2nMQCEcEIDKpEN3ur 71NjgBS2NCZOy3zCwM2vmr3KtbaBddvfNbTCqnAjkHmMGF/VVF9Rwh4Tg0dn0hwKQQ fD45ysFjPsRskhtvxHAQwnpanSwU8TySagQFWN+dA87uiaeKzyfr1D3W7tr4u/rFrx GBHRHP9QjJ+u2cvA4zCfmz8M= Received: from localhost (unknown [193.32.127.155]) by wolfsden.cz (Postfix) with ESMTPSA id 41E802895BC; Sat, 11 May 2024 13:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wolfsden.cz; s=mail; t=1715434073; bh=kFJZSer9CFhYedqtwpROWs6QdH1hOKy/ROas61wnOO4=; h=From:To:Cc:Subject:Date; b=LcSYRHtiTE7+9tQkvu+KlFaiw9PP02hf/Vh/4Lp1STJVQbD8r6vjJ30DBYavrxLcU GSAd0hKzYVcktCT82EBLMgt6dIMSXfVGiQnC8jNXY3wmxPgVZGVM2n56qhDIV1mgZY NGZCwFtsdEIQYSLxeJf2gG9j6B72Yobt9Rpm8Er9Q3oY0g9RhtR6jXlr/wk9a0c15k nZHp38aigeOZLRGHkv+7640259sPaRLiHPnEEvDJNT2+7KBiUxS+SNi+H2VuUWqsgw PaEUyYXnu1fgGFtTW1+gU1tEFeBV/l1STTN/iLMVo5EkSHH92qpeM6xas3JWsQsSNt AqvO57XpHdbxsYGESpMtSCufmHgnVDOvhqt6WuD3O+QzLzSJ2UCczjAjk9a1CwvunW iUzl/M9LWPTkbyuHl5VBgyqJOt/fb0dZtREXJw6WnLufQt/e1TPztmT7KorJC7lIlb i8GyLxNjY7UbkAv5DWHLDSTzq0uqRfv+NooqVW5Ui3uLPOCStW8DN+HiWMrsbFkv+d ybt9dYuKK7Op0cJJRpIGqSI7kH7j9XELv9BxvwiZgRlHq8iHpQn+q/80Br71Cvk9yL GrNXxYDVerQ+3sAwJ4V7ajXuZTM8JAa9GAikpoyxTVt1N/NpyeToiQsiZinEVwYMt0 djD2PSjRhmHPGqrsuSzZBGBw= From: Tomas Volf <~@wolfsden.cz> Date: Sat, 11 May 2024 15:26:23 +0200 Message-ID: <5197b347747fd3fb3d51a2c05b5cb676d387de8d.1715433985.git.~@wolfsden.cz> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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 --- v2: * Use invoke instead of checked-system*. * Use file-append instead of string-append. doc/guix.texi | 18 ++++++++++ gnu/services/xorg.scm | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) -- 2.41.0 diff --git a/doc/guix.texi b/doc/guix.texi index f20208f94f..c47b6fdd9c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -23561,6 +23561,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 51d704439e..11b9c36995 100644 --- a/gnu/services/xorg.scm +++ b/gnu/services/xorg.scm @@ -54,11 +54,13 @@ (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) #:use-module (guix gexp) #:use-module (guix store) + #:use-module ((guix modules) #:select (source-module-closure)) #:use-module (guix packages) #:use-module (guix derivations) #:use-module (guix records) @@ -86,6 +88,7 @@ (define-module (gnu services xorg) xorg-wrapper xorg-start-command + xorg-start-command-xinit xinitrc xorg-server-service-type @@ -416,6 +419,83 @@ (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. + (with-imported-modules (source-module-closure '((guix build utils))) + #~(begin + (use-modules (guix build utils) + (ice-9 popen) + (ice-9 textual-ports)) + + (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 #$(file-append xauth "/bin/xauth")) + (bin/mcookie #$(file-append util-linux "/bin/mcookie")) + + (mcookie (capture-stdout bin/mcookie))) + (invoke bin/xauth "-qf" server-auth-file + "add" display "." mcookie) + (invoke bin/xauth "-q" + "add" display "." mcookie))) + + (let* ((xinit #$(file-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