Subject: [PATCH] services: readymedia: Respect SUDO_HOME if configuring for home.

From: Sughosha <[email-masked]>
Date: Tue, 27 May 2025 14:56:16 +0530

This fixes the service that is configured for a home environment,
defined with "guix-home-service-type" in a system configuration, using "sudo",
with "/root" as "$HOME" instead of the required home directory.

* gnu/services/upnp.scm (readymedia-configuration)[cache-directory]: Respect
SUDO_HOME if configuring for home.
[log-directory]: Ditto.

Change-Id: Ie6905c0b83608f91582671cde9d866079178f192
---
 gnu/services/upnp.scm | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/gnu/services/upnp.scm b/gnu/services/upnp.scm
index 8267b1e53af..edd55594e38 100644
--- a/gnu/services/upnp.scm
+++ b/gnu/services/upnp.scm
@@ -74,19 +74,22 @@ (define-record-type* <readymedia-configuration>
         (default #f))
   (cache-directory readymedia-configuration-cache-directory
                    (default (if for-home?
-                                (string-append (or (getenv "XDG_CACHE_HOME")
-                                                   (string-append
-                                                    (getenv "HOME") "/.cache"))
-                                               "/readymedia")
-                              %readymedia-default-cache-directory)))
+                                (if (getenv "XDG_CACHE_HOME")
+                                    (string-append (getenv "XDG_CACHE_HOME")
+                                                   "/readymedia")
+                                    (string-append (or (getenv "SUDO_HOME")
+                                                       (getenv "HOME"))
+                                                   "/.cache/readymedia"))
+                                %readymedia-default-cache-directory)))
   (log-directory readymedia-configuration-log-directory
                  (default (if for-home?
-                              (string-append (or (getenv "XDG_STATE_HOME")
-                                                 (string-append
-                                                  (getenv "HOME")
-                                                  "/.local/state"))
-                                             "/readymedia")
-                            %readymedia-default-log-directory)))
+                              (if (getenv "XDG_STATE_HOME")
+                                  (string-append (getenv "XDG_STATE_HOME")
+                                                 "/readymedia")
+                                  (string-append (or (getenv "SUDO_HOME")
+                                                     (getenv "HOME"))
+                                                 "/.local/state/readymedia"))
+                              %readymedia-default-log-directory)))
   (friendly-name readymedia-configuration-friendly-name
                  (default #f))
   (media-directories readymedia-configuration-media-directories)

base-commit: c15f786f8936502249b639220997094fdbf7f1e8
-- 
2.49.0