GNU bug report logs - #78603
[PATCH] services: readymedia: Respect SUDO_HOME if configuring for home.

Previous Next

Package: guix-patches;

Reported by: Sughosha <sughosha <at> disroot.org>

Date: Tue, 27 May 2025 09:28:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 78603 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#78603; Package guix-patches. (Tue, 27 May 2025 09:28:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sughosha <sughosha <at> disroot.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Tue, 27 May 2025 09:28:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sughosha <sughosha <at> disroot.org>
To: guix-patches <at> gnu.org
Cc: Sughosha <sughosha <at> disroot.org>
Subject: [PATCH] services: readymedia: Respect SUDO_HOME if configuring for
 home.
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





Information forwarded to guix-patches <at> gnu.org:
bug#78603; Package guix-patches. (Tue, 27 May 2025 11:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 78603 <at> debbugs.gnu.org (full text, mbox):

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: Sughosha <sughosha <at> disroot.org>
Cc: 78603 <at> debbugs.gnu.org
Subject: Re: [bug#78603] [PATCH] services: readymedia: Respect SUDO_HOME if
 configuring for home.
Date: Tue, 27 May 2025 13:45:10 +0200
Hi Sughosha,

Sughosha <sughosha <at> disroot.org> writes:

> 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)))

That's a brittle solution: this code runs when the file is loaded,
setting the defaults to the values of host environment. This is not what
you generally want, because the target environment might be different,
i.e. I might be building home profile for another user and the resulting
config should contain their username.

Check how `syncthing-configuration` works. I think that the simplest
solution would be to use relative paths for installations to user homes.
The shepherd service is run from the $HOME, so just
`db_dir=.cache/readymedia` should work. If the user wants to use XDG
dirs, they should pass the correct values explicitly.




Information forwarded to guix-patches <at> gnu.org:
bug#78603; Package guix-patches. (Tue, 27 May 2025 13:29:02 GMT) Full text and rfc822 format available.

Message #11 received at 78603 <at> debbugs.gnu.org (full text, mbox):

From: Sughosha <sughosha <at> disroot.org>
To: Sergey Trofimov <sarg <at> sarg.org.ru>
Cc: 78603 <at> debbugs.gnu.org
Subject: Re: [bug#78603] [PATCH] services: readymedia: Respect SUDO_HOME if
 configuring for home.
Date: Tue, 27 May 2025 18:57:31 +0530
[Message part 1 (text/plain, inline)]
On Tuesday, May 27, 2025 5:15:10 PM GMT+5:30 Sergey Trofimov wrote:
> Hi Sughosha,
> 
> Sughosha <sughosha <at> disroot.org> writes:
> > 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)))
> That's a brittle solution: this code runs when the file is loaded,
> setting the defaults to the values of host environment. This is not what
> you generally want, because the target environment might be different,
> i.e. I might be building home profile for another user and the resulting
> config should contain their username.
> 
> Check how `syncthing-configuration` works. I think that the simplest
> solution would be to use relative paths for installations to user homes.
> The shepherd service is run from the $HOME, so just
> `db_dir=.cache/readymedia` should work. If the user wants to use XDG
> dirs, they should pass the correct values explicitly.
Using relative paths without any variable is working. I will send v2 patch.

-- 
Sughosha
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#78603; Package guix-patches. (Tue, 27 May 2025 13:29:02 GMT) Full text and rfc822 format available.

Message #14 received at 78603 <at> debbugs.gnu.org (full text, mbox):

From: Sughosha <sughosha <at> disroot.org>
To: 78603 <at> debbugs.gnu.org
Cc: Sughosha <sughosha <at> disroot.org>
Subject: [PATCH v2] services: readymedia: Use relative paths to cache and log
 directories for home.
Date: Tue, 27 May 2025 18:58:15 +0530
This fixes readymedia configured by a different user.

* gnu/services/upnp.scm (readymedia-configuration)[cache-directory]: Update
path.
[log-directory]: Ditto.

Change-Id: I629c937973ca46bcd6e60382aa7576b9859515be
---
 gnu/services/upnp.scm | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/gnu/services/upnp.scm b/gnu/services/upnp.scm
index 8267b1e53af..a5954c83f40 100644
--- a/gnu/services/upnp.scm
+++ b/gnu/services/upnp.scm
@@ -74,19 +74,12 @@ (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)))
+                                ".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)))
+                              ".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





Information forwarded to guix-patches <at> gnu.org:
bug#78603; Package guix-patches. (Tue, 27 May 2025 13:53:01 GMT) Full text and rfc822 format available.

Message #17 received at 78603 <at> debbugs.gnu.org (full text, mbox):

From: Sughosha <sughosha <at> disroot.org>
To: 78603 <at> debbugs.gnu.org
Subject: Re: [PATCH v2] services: readymedia: Use relative paths to cache and
 log directories for home.
Date: Tue, 27 May 2025 19:22:09 +0530
[Message part 1 (text/plain, inline)]
On Tuesday, May 27, 2025 6:58:15 PM GMT+5:30 Sughosha wrote:
> This fixes readymedia configured by a different user.
> 
> * gnu/services/upnp.scm (readymedia-configuration)[cache-directory]: Update
> path.
> [log-directory]: Ditto.
> 
> Change-Id: I629c937973ca46bcd6e60382aa7576b9859515be
> ---
>  gnu/services/upnp.scm | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/gnu/services/upnp.scm b/gnu/services/upnp.scm
> index 8267b1e53af..a5954c83f40 100644
> --- a/gnu/services/upnp.scm
> +++ b/gnu/services/upnp.scm
> @@ -74,19 +74,12 @@ (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)))
> +                                ".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)))
> +                              ".local/state/readymedia"
> +                              %readymedia-default-log-directory)))
>    (friendly-name readymedia-configuration-friendly-name
>                   (default #f))
>    (media-directories readymedia-configuration-media-directories)
> 
> base-commit: c15f786f8936502249b639220997094fdbf7f1e8
Sorry, when I checked the log this is giving the following error:

--8<---------------cut here---------------start------------->8---
2025-05-27 19:04:38 gnu/build/linux-container.scm:476:16: In procedure statfs: 
.cache/readymedia: No such file or directory
2025-05-27 19:04:38 Backtrace:
2025-05-27 19:04:38            3 (primitive-load "/gnu/store/
0b4l0f7yypzqww1h3hchqkqvam9…")
2025-05-27 19:04:38 In ice-9/eval.scm:
2025-05-27 19:04:38    191:35  2 (_ #f)
2025-05-27 19:04:38 In gnu/build/linux-container.scm:
2025-05-27 19:04:38     368:8  1 (call-with-temporary-directory #<procedure 
7f07dc3c82a0…>)
2025-05-27 19:04:38    476:16  0 (_ "/tmp/guix-directory.puYgco")
--8<---------------cut here---------------end--------------->8---

-- 
Sughosha
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#78603; Package guix-patches. (Tue, 27 May 2025 13:57:01 GMT) Full text and rfc822 format available.

Message #20 received at 78603 <at> debbugs.gnu.org (full text, mbox):

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: Sughosha <sughosha <at> disroot.org>
Cc: 78603 <at> debbugs.gnu.org
Subject: Re: [bug#78603] [PATCH] services: readymedia: Respect SUDO_HOME if
 configuring for home.
Date: Tue, 27 May 2025 15:56:42 +0200
Hi Sughosha,

Sughosha <sughosha <at> disroot.org> writes:
[...]
> Using relative paths without any variable is working. I will send v2 patch.
>

I've also noticed a couple other issues:
- `(getuid)` used in `readymedia-configuration->config-file`. It could
be removed altogether, no need to specify `user=` for home installations
- log_dir seem to be ineffective when starting the app with -s. It logs
to stdout when running in foreground. You can just remove this parameter
- #:log-file for a shepherd service should be located either in
%user-log-dir or "/var/log". Please check e.g. mcron service
- not sure if least-authority-wrapper would work for symlinked media
directories (see wide_links config option)






This bug report was last modified 1 day ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.