Subject: [bug#77266] [PATCH v5 2/2] gnu: set-xorg-configuration: Be smarter finding the display-manager.

From: Ian Eure <[email-masked]>
Date: Sun, 18 May 2025 17:07:11 -0700

* gnu/services/desktop.scm (desktop-services-for-system): Export.
* gnu/services/desktop.scm (set-xorg-configuration): Look for a
display-manager service in (desktop-services-for-system).
* gnu/services/desktop.scm (set-xorg-configuration): Remove TODO comment.

Change-Id: Iceda2d13d16435517cd92bcb49e6937ed096f392
---
 gnu/services/desktop.scm |  1 +
 gnu/services/xorg.scm    | 25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm
index 12560a6249d..fd4a452aa56 100644
--- a/gnu/services/desktop.scm
+++ b/gnu/services/desktop.scm
@@ -205,6 +205,7 @@ (define-module (gnu services desktop)
             seatd-configuration
             seatd-service-type
 
+            desktop-services-for-system
             %desktop-services))
 
 ;;; Commentary:
diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index c2ee68b1ab2..9b82882116e 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -16,6 +16,7 @@
 ;;; Copyright © 2023 muradm <[email-masked]>
 ;;; Copyright © 2024 Zheng Junjie <[email-masked]>
 ;;; Copyright © 2024 Tomas Volf <[email-masked]>
+;;; Copyright © 2025 Ian Eure <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -43,6 +44,7 @@ (define-module (gnu services xorg)
   #:use-module (gnu system privilege)
   #:use-module (gnu services base)
   #:use-module (gnu services dbus)
+  #:use-module (gnu services desktop)
   #:use-module (gnu packages base)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages xorg)
@@ -139,6 +141,7 @@ (define-module (gnu services xorg)
             gdm-configuration
             gdm-service-type
 
+            xorg-configuration-service-type
             handle-xorg-configuration
             set-xorg-configuration))
 
@@ -1392,16 +1395,24 @@ (define gdm-service-type
                    "Run the GNOME Desktop Manager (GDM), a program that allows
 you to log in in a graphical session, whether or not you use GNOME."))))
 
-;; Since GDM depends on Rust and Rust is not available on all platforms,
-;; use SDDM as the fall-back display manager.
-;; TODO: Switch the condition to take into account if Rust is supported and
-;; match the configuration in desktop-services-for-system.
+(define (xorg-configuration-service? s)
+  "Returns #t if @var{s} is a service carrying xorg configuration."
+  (let ((val (service-value s)))
+    (and (record? val)
+         (memq 'xorg-configuration
+                 (record-type-fields (record-type-descriptor val))))))
+
+(define (xorg-configuration-service-type services)
+  "Return the service type of the first service in @var{services}
+which carries xorg configuration. "
+  (let ((lmst (find xorg-configuration-service? services)))
+    (when lmst (service-kind lmst))))
+
 (define* (set-xorg-configuration config
                                  #:optional
                                  (login-manager-service-type
-                                  (if (target-x86-64?)
-                                      gdm-service-type
-                                      sddm-service-type)))
+                                  (xorg-configuration-service-type
+                                   (desktop-services-for-system))))
   "Tell the log-in manager (of type @var{login-manager-service-type}) to use
 @var{config}, an <xorg-configuration> record."
   (simple-service 'set-xorg-configuration
-- 
2.49.0