Subject: [PATCH 2/2] gnu: lightdm-service-type: Add lightdm.conf to /etc/lightdm.

From: Dariqq <[email-masked]>
Date: Sat, 2 Nov 2024 10:18:33 +0000

* gnu/services/lightdm.scm
(lightdm-configuration->greeters-config-dir): Rename to
lightdm-configuration-directory and add the lightdm-configuration-file.
(lightdm-shepherd-service): Don't pass the configuration file, don't set
XDG_CONFIG_DIRS
(lightdm-etc-service): New procedure.
(lightdm-service-type): Use lightdm-etc-service as the etc-extension.

Change-Id: I982ec1f7bdfd085621f45a8a1e4b175ab481202f
---
 gnu/services/lightdm.scm | 48 ++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/gnu/services/lightdm.scm b/gnu/services/lightdm.scm
index 798c106563..191cb5635b 100644
--- a/gnu/services/lightdm.scm
+++ b/gnu/services/lightdm.scm
@@ -397,15 +397,6 @@ (define-configuration/no-serialization lightdm-configuration
    (list-of-strings '())
    "Extra configuration values to append to the LightDM configuration file."))
 
-(define (lightdm-configuration->greeters-config-dir config)
-  "Return a directory containing all the serialized greeter configurations
-from CONFIG, a <lightdm-configuration> object."
-  (file-union "etc-lightdm"
-              (append-map (lambda (g)
-                            `((,(greeter-configuration->conf-name g)
-                               ,(greeter-configuration->file g))))
-                          (lightdm-configuration-greeters config))))
-
 (define (lightdm-configuration->packages config)
   "Return all the greeter packages and their assets defined in CONFIG, a
 <lightdm-configuration> object, as well as the lightdm package itself."
@@ -496,6 +487,16 @@ (define (lightdm-configuration-file config)
                                        lightdm-seat-configuration-fields)))
           seats))))
 
+(define (lightdm-configuration-directory config)
+  "Return a directory containing the serialized lightdm configuration
+and all the serialized greeter configurations from CONFIG."
+  (file-union "etc-lightdm"
+              (cons `("lightdm.conf" ,(lightdm-configuration-file config))
+                    (map (lambda (g)
+                           `(,(greeter-configuration->conf-name g)
+                             ,(greeter-configuration->file g)))
+                         (lightdm-configuration-greeters config)))))
+
 (define %lightdm-accounts
   (list (user-group (name "lightdm") (system? #t))
         (user-account
@@ -589,9 +590,7 @@ (define (lightdm-shepherd-service config)
                            "/sbin/lightdm")
             #$@(if (lightdm-configuration-debug? config)
                    #~("--debug")
-                   #~())
-            "--config"
-            #$(lightdm-configuration-file config)))
+                   #~())))
 
   (define lightdm-paths
     (let ((lightdm (lightdm-configuration-lightdm config)))
@@ -601,9 +600,6 @@ (define (lightdm-shepherd-service config)
                  '("/bin" "/sbin" "/libexec"))
          ":")))
 
-  (define greeters-config-dir
-    (lightdm-configuration->greeters-config-dir config))
-
   (define data-dirs
     ;; LightDM itself needs to be in XDG_DATA_DIRS for the accountsservice
     ;; interface it provides to be picked up.  The greeters must also be in
@@ -626,11 +622,7 @@ (define (lightdm-shepherd-service config)
                                   ;; Lightdm needs itself in its PATH.
                                   #:environment-variables
                                   (list
-                                   ;; It knows to look for greeter
-                                   ;; configurations in XDG_CONFIG_DIRS...
-                                   (string-append "XDG_CONFIG_DIRS="
-                                                  #$greeters-config-dir)
-                                   ;; ... and for greeter .desktop files as
+                                   ;; It looks for greeter .desktop files as
                                    ;; well as lightdm accountsservice
                                    ;; interface in XDG_DATA_DIRS.
                                    (string-append "XDG_DATA_DIRS="
@@ -638,6 +630,11 @@ (define (lightdm-shepherd-service config)
                                    (string-append "PATH=" #$lightdm-paths))))
     (stop #~(make-kill-destructor)))))
 
+(define (lightdm-etc-service config)
+  "Return a list of FILES for @var{etc-service-type} to build the
+/etc/lightdm directory using CONFIG"
+  (list `("lightdm" ,(lightdm-configuration-directory config))))
+
 (define lightdm-service-type
   (handle-xorg-configuration
    lightdm-configuration
@@ -666,13 +663,10 @@ (define lightdm-service-type
            ;; https://github.com/NixOS/nixpkgs/issues/45059.
            (service-extension profile-service-type
                               lightdm-configuration->packages)
-           ;; This is needed for the greeter itself to find its configuration,
-           ;; because XDG_CONF_DIRS gets overridden by /etc/profile.
-           (service-extension
-            etc-service-type
-            (lambda (config)
-              `(("lightdm"
-                 ,(lightdm-configuration->greeters-config-dir config)))))))
+           ;; This is needed for lightdm and greeter
+           ;; to find their configuration
+           (service-extension etc-service-type
+                              lightdm-etc-service)))
     (description "Run @code{lightdm}, the LightDM graphical login manager."))))
 
 
-- 
2.46.0