From patchwork Mon May 19 00:07:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ian Eure X-Patchwork-Id: 42733 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 D28F827BC4A; Mon, 19 May 2025 01:08:28 +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=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable 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 4A5CA27BC49 for ; Mon, 19 May 2025 01:08:26 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uGo35-0008Cb-RS; Sun, 18 May 2025 20:08:08 -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 1uGo31-0008Bs-16 for guix-patches@gnu.org; Sun, 18 May 2025 20:08:04 -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 1uGo30-0005zb-Ia for guix-patches@gnu.org; Sun, 18 May 2025 20:08:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=PE7TZ5wdYjrsFhfeG+nw5O7qk5GQ7Y8SyUZ5bD1SXdg=; b=VbnqgEHe/VmcJDJdHffDAEYECScD0WLm0dqO9gKt2kv/h01gUT1hD2f7YBHorMKWJSQKKwaYSi0GNLrLTMmkyYNsaM/htJ5fpm1DRBpg9uqpundA1RKmbXk9CpslzBeVuSKM7+vAPL+UcARlXyJU8xnub/O4nBh1tKZMMruGtlx1jvWHv5tADXOzXebzYAfuQopGpWb5ueRqwRrcnJP280cOQm7G3YuH7PQU9LQlalTx/pvVy+L6SIs4rPpTKfKXMUzA1vpzSsgN9LczzO+BjFPZmYDgSb6AwVJpi1fjSXgzkiWwu91BMhZ1Qxqzm9Teqgc6g0MdKKFePOqf7cQ28A==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uGo30-00054c-3V for guix-patches@gnu.org; Sun, 18 May 2025 20:08:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77266] [PATCH v5 1/2] gnu: Merge xorg configurations when extending. Resent-From: Ian Eure Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 19 May 2025 00:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77266 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77266@debbugs.gnu.org Cc: Ian Eure Received: via spool by 77266-submit@debbugs.gnu.org id=B77266.174761325519335 (code B ref 77266); Mon, 19 May 2025 00:08:02 +0000 Received: (at 77266) by debbugs.gnu.org; 19 May 2025 00:07:35 +0000 Received: from localhost ([127.0.0.1]:33786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uGo2Y-00051l-IM for submit@debbugs.gnu.org; Sun, 18 May 2025 20:07:35 -0400 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]:51411) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uGo2T-000518-Su for 77266@debbugs.gnu.org; Sun, 18 May 2025 20:07:30 -0400 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.stl.internal (Postfix) with ESMTP id 1C30C2540080; Sun, 18 May 2025 20:07:24 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Sun, 18 May 2025 20:07:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=retrospec.tv; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1747613243; x=1747699643; bh=PE7TZ5wdYjrsFhfeG+nw5O7qk5GQ7Y8SyUZ5bD1SXdg=; b= QvYYm+t07ctlz8W4pBj2Ttl5LiEDWFdEcvy5p4sISyt1THYPv62onN7HAFP+lLGR f3iYWozCuCeRnlS1bfZHLyFcAMIFVYPDDnoLtrWz4uApAfAQ8ziXMGCcUT2S7u48 wZK0q1QfHIldhzSYX5H3QSqXzhyY8s29F6OyUw/o2BjsFc4Kdu4Y37XCFZyJ/pho yKYtLttZ6ej71/U8SWMrqXcV1i7obtspmknLXWuC0j+tis3BSuv/HxSKTgYrMcxT u6015RVZ17BbjDk1eywKY7Vddq9JobjV3kGOFcnQLpMyCSLrsxvg1YFgH8cz83qg Dfxx9+Y8yVggaItuJeGELQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1747613243; x= 1747699643; bh=PE7TZ5wdYjrsFhfeG+nw5O7qk5GQ7Y8SyUZ5bD1SXdg=; b=M lLpEpq3JkxaE0g+CZAbv57r/xqQE9eVhZ3HzAAmrabx+O04JiLc0jQoXzyWF/nFg lNltgBr8sLMeZ5DdmyzPODYY5XXczUdDOMDTTxzDARG7aaKFeUrzfLKws8RwiYU4 rqbqdVBnN9HGX97/mQyxkF6jBZVjgdnxslMwEOSvW6V2uoHzQ8lHmsf7Oap5qB8p 8Y5jruokpsRzlFjU5nNzvbqSyY23OX3DG7jgYc1C9cI2TB0GxPLO9wFjtdkxZZfh ErCN4g/YN+dUfOloHvAgk09v0P9rkug7uMhsMYgcIL3lW7FkqFWNEssrG/Jtt5Yd ObEgLc7FpH5uD4Lh4ukYg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdefudelleduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvf evufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepkfgrnhcugfhurhgvuceo ihgrnhesrhgvthhrohhsphgvtgdrthhvqeenucggtffrrghtthgvrhhnpefggeehudelle eggfevueehffefgeevieejiedtteduleeluefhjeeiudfhudffteenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehirghnsehrvghtrhhoshhpvg gtrdhtvhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthht ohepjeejvdeiieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopehirghnse hrvghtrhhoshhpvggtrdhtvh X-ME-Proxy: Feedback-ID: id9014242:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 18 May 2025 20:07:23 -0400 (EDT) From: Ian Eure Date: Sun, 18 May 2025 17:07:10 -0700 Message-ID: <20250519000718.2147-2-ian@retrospec.tv> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250519000718.2147-1-ian@retrospec.tv> References: <20250519000718.2147-1-ian@retrospec.tv> 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 Configuration for xorg is embedded in the various display-manager configuration records, and extension support is factored out into the `handle-xorg-configuration' macro. However, the extension mechanism replaces the existing xorg-configuration with the supplied one, making it impossible to compose configuration from multiple sources. This patch adds a procedure to merge two xorg-configuration records, and calls it within handle-xorg-configuration, allowing the config to be built piecemeal. * gnu/services/xorg.scm (merge-xorg-configurations): New variable. (handle-xorg-configuration): Merge xorg configs. * doc/guix.texi (X Window): Document xorg-configuration composition. Change-Id: I20e9db911eef5d4efe98fdf382f3084e4defc1ba --- doc/guix.texi | 48 +++++++++++++++++++++++++++++++++++-- gnu/services/xorg.scm | 55 +++++++++++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 4f9cd56aa5b..dd184b27e78 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -140,6 +140,7 @@ Copyright @copyright{} 2025 Rostislav Svoboda@* Copyright @copyright{} 2025 Zacchaeus@* Copyright @copyright{} 2025 Sergio Pastor Pérez@* Copyright @copyright{} 2024 Evgeny Pisemsky@* +Copyright @copyright{} 2025 Ian Eure@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -25039,8 +25040,51 @@ Tell the log-in manager (of type @var{login-manager-service-type}) to use @var{config}, an @code{} record. Since the Xorg configuration is embedded in the log-in manager's -configuration---e.g., @code{gdm-configuration}---this procedure provides a -shorthand to set the Xorg configuration. +configuration---e.g., @code{gdm-configuration}---this procedure provides +a shorthand to set the Xorg configuration. + +In addition to @code{set-xorg-configuration}, you may extend your log-in +manager’s service-type to provide reusable, partial configurations, +which are concatenated to create the final Xorg configuration: + +@lisp +;; A service which configures Intel video drivers. +(define %xorg-intel-service + (simple-service + 'xorg-intel + gdm-service-type + (xorg-configuration + (modules (list xf86-video-intel)) + (drivers '("intel")) + (extra-config " + Section \"Device\" + Identifier \"Intel GPU\" + Driver \"intel\" + Option \"TearFree\" \"true\" + EndSection")))) + +;; A service which configures the keyboard. +(define %xorg-keyboard-service + (simple-service + 'xorg-keyboard + gdm-service-type + (xorg-configuration + (keyboard-layout + (keyboard-layout "us" #:options '("ctrl:nocaps")))))) + +(operating-system + (services + (append + (list (service gdm-service-type) + %xorg-intel-service + %xorg-keyboard-service) + %base-services)) + @dots{}) +@end lisp + +Service extension and @code{set-xorg-configuration} can each be used +seperately, or in conjunction. + @end deffn @deffn {Procedure} xorg-start-command [config] diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm index bef05b9bb9b..c2ee68b1ab2 100644 --- a/gnu/services/xorg.scm +++ b/gnu/services/xorg.scm @@ -209,14 +209,43 @@ (define-record-type* (server-arguments xorg-configuration-server-arguments ;list of strings (default %default-xorg-server-arguments))) +(define (merge-xorg-configurations a b) + (let ((configs (list b a))) ; Prefer later configurations. + (xorg-configuration + (modules + (append-map xorg-configuration-modules configs)) + (fonts + (append-map xorg-configuration-fonts configs)) + (drivers + (append-map xorg-configuration-drivers configs)) + (resolutions + (append-map xorg-configuration-resolutions configs)) + (extra-config (append-map xorg-configuration-extra-config configs)) + ;; Prefer the more recently set layout. + (keyboard-layout (or (xorg-configuration-keyboard-layout b) + (xorg-configuration-keyboard-layout a) + #f)) + (server + ;; Prefer the non-default server. + (if (eq? xorg-server (xorg-configuration-server a)) + (xorg-configuration-server b) + (xorg-configuration-server a))) + (server-arguments + ;; Prefer the non-default arguments. + (if (eq? %default-xorg-server-arguments + (xorg-configuration-server-arguments a)) + (xorg-configuration-server-arguments b) + (xorg-configuration-server-arguments a)))))) + (define (xorg-configuration->file config) "Compute an Xorg configuration file corresponding to CONFIG, an record." (let ((xorg-server (xorg-configuration-server config))) (define all-modules ;; 'xorg-server' provides 'fbdevhw.so' etc. - (append (xorg-configuration-modules config) - (list xorg-server))) + (delete-duplicates + (append (xorg-configuration-modules config) + (list xorg-server)))) (define build #~(begin @@ -227,7 +256,7 @@ (define build (call-with-output-file #$output (lambda (port) (define drivers - '#$(xorg-configuration-drivers config)) + (delete-duplicates '#$(xorg-configuration-drivers config))) (define (device-section driver) (string-append " @@ -247,7 +276,7 @@ (define (screen-section driver resolutions) ((x y) (string-append "\"" (number->string x) "x" (number->string y) "\""))) - resolutions)) " + (delete-duplicates resolutions))) " EndSubSection EndSection")) @@ -294,7 +323,7 @@ (define (expand modules) (display "Section \"Files\"\n" port) (for-each (lambda (font) (format port " FontPath \"~a\"~%" font)) - '#$(xorg-configuration-fonts config)) + (delete-duplicates '#$(xorg-configuration-fonts config))) (for-each (lambda (module) (format port " ModulePath \"~a\"~%" @@ -315,7 +344,7 @@ (define (expand modules) (newline port) (display (string-join (map (cut screen-section <> - '#$(xorg-configuration-resolutions config)) + (delete-duplicates '#$(xorg-configuration-resolutions config))) drivers) "\n") port) @@ -334,9 +363,12 @@ (define (expand modules) port) (newline port))) - (for-each (lambda (config) - (display config port)) - '#$(xorg-configuration-extra-config config)))))) + (for-each + (lambda (config) + (display config port) + (newline port)) + (delete-duplicates + '#$(xorg-configuration-extra-config config))))))) (computed-file "xserver.conf" build))) @@ -628,10 +660,7 @@ (define-syntax handle-xorg-configuration ((_ configuration-record service-type-definition) (service-type (inherit service-type-definition) - (compose (lambda (extensions) - (match extensions - (() #f) - ((config . _) config)))) + (compose (cut reduce merge-xorg-configurations #f <>)) (extend (lambda (config xorg-configuration) (if xorg-configuration (configuration-record