Subject: [PATCH] services: xorg-wrapper: Support xorg server input

From: Roman Scherer <[email-masked]>
Date: Sun, 12 Feb 2023 19:52:40 +0100

Hello Guix,

I would like to replace the Mesa package in my Xorg configuration. I
tried to do this with the following snippet:

```
(modify-services %desktop-services
  (slim-service-type config =>
                     (slim-configuration
                      (inherit config)
                      (xorg-configuration
                       (xorg-configuration
                        (server (replace-mesa xorg-server)))))))
```

But this unfortunately does not work, because the xorg-wrapper uses
static paths for the mesa, xkbcomp and xkeyboard-config packages in the
derivation.

The xserver starts now with the replaced mesa, but some paths still
point to the hard coded packages in Guix itself (and not the
replacement), which cause some things to not work.

This patch changes this to lookup the paths from the inputs of the
server field of the xorg-configuration instead. That way the correct
paths are setup in the xor-wrapper script. If those inputs are not found
for some reason it falls back to the current behavior, using the
packages from Guix.

Could you please review this?

Thanks, Roman.

From d035c99ed4703da0e3e9b62299c390560c074a17 Mon Sep 17 00:00:00 2001
From: r0man <[email-masked]>
Date: Sat, 11 Feb 2023 19:36:16 +0100
Subject: [PATCH] services: xorg-wrapper: Support xorg server input
 transformations.

* gnu/services/xorg.scm (xorg-wrapper): Support xorg server input transformations.
---
 gnu/services/xorg.scm | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index 5f073d05d3..92735e6004 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -355,6 +355,21 @@ (define files
                                  files)
                        #t))))
 
+(define (xorg-configuration-append-input config input default-input path)
+  (let ((server (xorg-configuration-server config)))
+    (file-append (or (lookup-package-direct-input server input) default-input)
+                 path)))
+
+(define (xorg-configuration-dri-driver-path config)
+  (xorg-configuration-append-input config "mesa" mesa "/lib/dri"))
+
+(define (xorg-configuration-xkb-bin-dir config)
+  (xorg-configuration-append-input config "xkbcomp" xkbcomp "/bin"))
+
+(define (xorg-configuration-xkb-dir config)
+  (xorg-configuration-append-input config "xkeyboard-config"
+                                   xkeyboard-config "/share/X11/xkb"))
+
 (define* (xorg-wrapper #:optional (config (xorg-configuration)))
   "Return a derivation that builds a script to start the X server with the
 given @var{config}.  The resulting script should be used in place of
@@ -362,12 +377,13 @@ (define* (xorg-wrapper #:optional (config (xorg-configuration)))
   (define exp
     ;; Write a small wrapper around the X server.
     #~(begin
-        (setenv "XORG_DRI_DRIVER_PATH" (string-append #$mesa "/lib/dri"))
-        (setenv "XKB_BINDIR" (string-append #$xkbcomp "/bin"))
+        (setenv "XORG_DRI_DRIVER_PATH"
+                #$(xorg-configuration-dri-driver-path config))
+        (setenv "XKB_BINDIR" #$(xorg-configuration-xkb-bin-dir config))
 
         (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
           (apply execl X X
-                 "-xkbdir" (string-append #$xkeyboard-config "/share/X11/xkb")
+                 "-xkbdir" #$(xorg-configuration-xkb-dir config)
                  "-config" #$(xorg-configuration->file config)
                  "-configdir" #$(xorg-configuration-directory
                                  (xorg-configuration-modules config))
-- 
2.38.1