GNU bug report logs - #61982
[PATCH 0/2] Respect XDG Base Directory Specification 0.8.

Previous Next

Package: guix-patches;

Reported by: Bruno Victal <mirai <at> makinata.eu>

Date: Sun, 5 Mar 2023 15:18:02 UTC

Severity: normal

Tags: patch

Done: Andrew Tropin <andrew <at> trop.in>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61982 in the body.
You can then email your comments to 61982 AT debbugs.gnu.org in the normal way.

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

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


Report forwarded to philip <at> philipmcgrath.com, guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sun, 05 Mar 2023 15:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bruno Victal <mirai <at> makinata.eu>:
New bug report received and forwarded. Copy sent to philip <at> philipmcgrath.com, guix-patches <at> gnu.org. (Sun, 05 Mar 2023 15:18:03 GMT) Full text and rfc822 format available.

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

From: Bruno Victal <mirai <at> makinata.eu>
To: guix-patches <at> gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>
Subject: [PATCH 0/2] Respect XDG Base Directory Specification 0.8.
Date: Sun,  5 Mar 2023 15:16:48 +0000
Note: Needs to be tested.

Bruno Victal (2):
  home: services: xdg-base-directories: Set correct value for
    XDG_STATE_HOME.
  home: services: xdg-base-directories: Deprecate XDG_LOG_HOME.

 gnu/home/services/desktop.scm  |  4 +--
 gnu/home/services/mcron.scm    |  4 +--
 gnu/home/services/pm.scm       |  6 ++--
 gnu/home/services/shepherd.scm |  4 +--
 gnu/home/services/xdg.scm      | 52 +++++++++++++++++++++++-----------
 5 files changed, 44 insertions(+), 26 deletions(-)


base-commit: d92ec2f2812c76b23aab778e26708cf353542ae9
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sun, 05 Mar 2023 15:20:03 GMT) Full text and rfc822 format available.

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

From: Bruno Victal <mirai <at> makinata.eu>
To: 61982 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, philip <at> philipmcgrath.com
Subject: [PATCH 1/2] home: services: xdg-base-directories: Set correct value
 for XDG_STATE_HOME.
Date: Sun,  5 Mar 2023 15:19:13 +0000
XDG Base Directory Specification 0.8 officially introduces the
XDG_STATE_HOME environment variable.

Fixes <https://issues.guix.gnu.org/issue/61809>.

* gnu/home/services/xdg.scm
(home-xdg-base-directories-configuration)[state-home]: Set default value according to spec.
Update field documentation.
(home-xdg-base-directories-service-type): Update service description.
---
 gnu/home/services/xdg.scm | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
index 3007493f85..ac557b4c3d 100644
--- a/gnu/home/services/xdg.scm
+++ b/gnu/home/services/xdg.scm
@@ -104,11 +104,11 @@ (define-configuration home-xdg-base-directories-configuration
 Specification, but helps to make implementation of home services more
 consistent.")
   (state-home
-   (path "$HOME/.local/var/lib")
-   "Base directory for programs to store state files, like databases,
-analogus to @file{/var/lib}, but for user.  It is not a part of XDG
-Base Directory Specification, but helps to make implementation of home
-services more consistent."))
+   (path "$HOME/.local/state")
+   "Base directory for programs to store state data that should persist
+between (application) restarts, such as logs, but are not important or
+portable enough to the user to warrant storing them in
+@env{XDG_DATA_HOME}."))
 
 (define (home-xdg-base-directories-environment-variables-service config)
   (map
@@ -158,12 +158,12 @@ (define home-xdg-base-directories-service-type
                 (compose identity)
                 (extend last-extension-or-cfg)
                 (description "Configure XDG base directories.  This
-service introduces two additional variables @env{XDG_STATE_HOME},
-@env{XDG_LOG_HOME}.  They are not a part of XDG specification, at
-least yet, but are convenient to have, it improves the consistency
-between different home services.  The services of this service-type is
-instantiated by default, to provide non-default value, extend the
-service-type (using @code{simple-service} for example).")))
+service introduces an additional @env{XDG_LOG_HOME} variable.  It's not
+a part of XDG specification, at least yet, but are convenient to have,
+it improves the consistency between different home services.  The
+services of this service-type is instantiated by default, to provide
+non-default value, extend the service-type (using @code{simple-service}
+for example).")))
 
 (define (generate-home-xdg-base-directories-documentation)
   (generate-documentation

base-commit: d92ec2f2812c76b23aab778e26708cf353542ae9
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sun, 05 Mar 2023 15:20:03 GMT) Full text and rfc822 format available.

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

From: Bruno Victal <mirai <at> makinata.eu>
To: 61982 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, philip <at> philipmcgrath.com
Subject: [PATCH 2/2] home: services: xdg-base-directories: Deprecate
 XDG_LOG_HOME.
Date: Sun,  5 Mar 2023 15:19:14 +0000
XDG_LOG_HOME is non-standard and log files should go to XDG_STATE_HOME
according to the XDG Base Directory Specification.

Fixes <https://issues.guix.gnu.org/61809>.

* gnu/home/services/desktop.scm (home-dbus-shepherd-services): Log to XDG_STATE_HOME.
* gnu/home/services/mcron.scm (home-mcron-shepherd-services): Ditto.
* gnu/home/services/pm.scm (home-batsignal-shepherd-services): Ditto.
* gnu/home/services/shepherd.scm (launch-shepherd-gexp): Ditto.
* gnu/home/services/xdg.scm
(home-xdg-base-directories-configuration)[log-home]: Deprecate and unset default value.
(home-xdg-base-directories-environment-variables-service)
(ensure-xdg-base-dirs-on-activation): Handle field deprecation.
(home-xdg-base-directories-service-type): Update description.
---
 gnu/home/services/desktop.scm  |  4 ++--
 gnu/home/services/mcron.scm    |  4 ++--
 gnu/home/services/pm.scm       |  6 +++---
 gnu/home/services/shepherd.scm |  4 ++--
 gnu/home/services/xdg.scm      | 36 +++++++++++++++++++++++++---------
 5 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index cb25b03b64..76df7b30a2 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -206,8 +206,8 @@ (define (home-dbus-shepherd-services config)
                          (default-environment-variables))
                    #:log-file
                    (format #f "~a/dbus.log"
-                           (or (getenv "XDG_LOG_HOME")
-                               (format #f "~a/.local/var/log"
+                           (or (getenv "XDG_STATE_HOME")
+                               (format #f "~a/.local/state"
                                        (getenv "HOME"))))))
          (stop #~(make-kill-destructor)))))
 
diff --git a/gnu/home/services/mcron.scm b/gnu/home/services/mcron.scm
index 5f35bfe054..69c7f9faa6 100644
--- a/gnu/home/services/mcron.scm
+++ b/gnu/home/services/mcron.scm
@@ -99,8 +99,8 @@ (define (home-mcron-shepherd-services config)
                                         #~())
                                  #$@files)
                            #:log-file (string-append
-                                       (or (getenv "XDG_LOG_HOME")
-                                           (format #f "~a/.local/var/log"
+                                       (or (getenv "XDG_STATE_HOME")
+                                           (format #f "~a/.local/state"
                                                    (getenv "HOME")))
                                        "/mcron.log")))
                  (stop #~(make-kill-destructor))
diff --git a/gnu/home/services/pm.scm b/gnu/home/services/pm.scm
index 5f09941827..274ab2303c 100644
--- a/gnu/home/services/pm.scm
+++ b/gnu/home/services/pm.scm
@@ -128,9 +128,9 @@ (define (home-batsignal-shepherd-services config)
                                  (list "-i")
                                  (list)))
                      #:log-file (string-append
-                                 (or (getenv "XDG_LOG_HOME")
-                                     (format #f "~a/.local/var/log"
-                                               (getenv "HOME")))
+                                 (or (getenv "XDG_STATE_HOME")
+                                     (format #f "~a/.local/state"
+                                             (getenv "HOME")))
                                  "/batsignal.log")))
            (stop #~(make-kill-destructor))))))
 
diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
index 1a70a220f0..825cf66f05 100644
--- a/gnu/home/services/shepherd.scm
+++ b/gnu/home/services/shepherd.scm
@@ -108,8 +108,8 @@ (define (launch-shepherd-gexp config)
                       (or (getenv "XDG_RUNTIME_DIR")
                           (format #f "/run/user/~a" (getuid)))
                       "/shepherd/socket"))
-              (let ((log-dir (or (getenv "XDG_LOG_HOME")
-                                 (format #f "~a/.local/var/log"
+              (let ((log-dir (or (getenv "XDG_STATE_HOME")
+                                 (format #f "~a/.local/state"
                                          (getenv "HOME")))))
                 ;; TODO: Remove it, 0.9.2 creates it automatically?
                 ((@ (guix build utils) mkdir-p) log-dir)
diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
index ac557b4c3d..958772696b 100644
--- a/gnu/home/services/xdg.scm
+++ b/gnu/home/services/xdg.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021, 2022 Andrew Tropin <andrew <at> trop.in>
 ;;; Copyright © 2021 Xinglu Chen <public <at> yoctocell.xyz>
+;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,6 +23,7 @@ (define-module (gnu home services xdg)
   #:use-module (gnu home services)
   #:use-module (gnu packages freedesktop)
   #:use-module (gnu home services utils)
+  #:use-module (guix deprecation)
   #:use-module (guix gexp)
   #:use-module (guix modules)
   #:use-module (guix records)
@@ -39,7 +41,7 @@ (define-module (gnu home services xdg)
             home-xdg-base-directories-configuration-config-home
             home-xdg-base-directories-configuration-data-home
             home-xdg-base-directories-configuration-state-home
-            home-xdg-base-directories-configuration-log-home
+            home-xdg-base-directories-configuration-log-home  ; deprecated
             home-xdg-base-directories-configuration-runtime-dir
 
             home-xdg-user-directories-service-type
@@ -77,6 +79,7 @@ (define-module (gnu home services xdg)
 
 (define (serialize-path field-name val) "")
 (define path? string?)
+(define-maybe path)
 
 (define-configuration home-xdg-base-directories-configuration
   (cache-home
@@ -97,12 +100,17 @@ (define-configuration home-xdg-base-directories-configuration
    (path "${XDG_RUNTIME_DIR:-/run/user/$UID}")
    "Base directory for programs to store user-specific runtime files,
 like sockets.")
+  ;; TODO: deprecated field, use $XDG_STATE_HOME(/log) instead.
   (log-home
-   (path "$HOME/.local/var/log")
+   maybe-path
    "Base directory for programs to store log files, analogus to
 @file{/var/log}, but for user.  It is not a part of XDG Base Directory
 Specification, but helps to make implementation of home services more
-consistent.")
+consistent."
+   (lambda (field-name val)
+     (when (maybe-value-set? val)
+       (warn-about-deprecation field-name #f #:replacement 'state-home))
+     (serialize-path field-name val)))
   (state-home
    (path "$HOME/.local/state")
    "Base directory for programs to store state data that should persist
@@ -117,7 +125,13 @@ (define (home-xdg-base-directories-environment-variables-service config)
             #f "XDG_~a"
             (object->snake-case-string (configuration-field-name field) 'upper))
            ((configuration-field-getter field) config)))
-   home-xdg-base-directories-configuration-fields))
+   ;; XXX: deprecated field, remove later
+   (if (maybe-value-set?
+        (home-xdg-base-directories-configuration-log-home config))
+       home-xdg-base-directories-configuration-fields
+       (filter-configuration-fields
+        home-xdg-base-directories-configuration-fields
+        '(log-home) #t))))
 
 (define (ensure-xdg-base-dirs-on-activation config)
   (with-imported-modules '((guix build utils))
@@ -138,7 +152,14 @@ (define (ensure-xdg-base-dirs-on-activation config)
                      ;; and will be provided by elogind or other service.
                      (and (not (string=? "XDG_RUNTIME_DIR" variable))
                           variable)))
-                 home-xdg-base-directories-configuration-fields)))))
+                 ;; XXX: deprecated field, remove later
+                 (if (maybe-value-set?
+                      (home-xdg-base-directories-configuration-log-home
+                       config))
+                     home-xdg-base-directories-configuration-fields
+                     (filter-configuration-fields
+                      home-xdg-base-directories-configuration-fields
+                      '(log-home) #t)))))))
 
 (define (last-extension-or-cfg config extensions)
   "Picks configuration value from last provided extension.  If there
@@ -157,10 +178,7 @@ (define home-xdg-base-directories-service-type
                 (default-value (home-xdg-base-directories-configuration))
                 (compose identity)
                 (extend last-extension-or-cfg)
-                (description "Configure XDG base directories.  This
-service introduces an additional @env{XDG_LOG_HOME} variable.  It's not
-a part of XDG specification, at least yet, but are convenient to have,
-it improves the consistency between different home services.  The
+                (description "Configure XDG base directories.  The
 services of this service-type is instantiated by default, to provide
 non-default value, extend the service-type (using @code{simple-service}
 for example).")))
-- 
2.39.1





Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Fri, 07 Apr 2023 06:45:01 GMT) Full text and rfc822 format available.

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

From: Andrew Tropin <andrew <at> trop.in>
To: Bruno Victal <mirai <at> makinata.eu>, 61982 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, philip <at> philipmcgrath.com
Subject: Re: [bug#61982] [PATCH 1/2] home: services: xdg-base-directories:
 Set correct value for XDG_STATE_HOME.
Date: Fri, 07 Apr 2023 10:43:50 +0400
[Message part 1 (text/plain, inline)]
On 2023-03-05 15:19, Bruno Victal wrote:

> XDG Base Directory Specification 0.8 officially introduces the
> XDG_STATE_HOME environment variable.
>
> Fixes <https://issues.guix.gnu.org/issue/61809>.
>
> * gnu/home/services/xdg.scm
> (home-xdg-base-directories-configuration)[state-home]: Set default value according to spec.
> Update field documentation.
> (home-xdg-base-directories-service-type): Update service description.
> ---
>  gnu/home/services/xdg.scm | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
> index 3007493f85..ac557b4c3d 100644
> --- a/gnu/home/services/xdg.scm
> +++ b/gnu/home/services/xdg.scm
> @@ -104,11 +104,11 @@ (define-configuration home-xdg-base-directories-configuration
>  Specification, but helps to make implementation of home services more
>  consistent.")
>    (state-home
> -   (path "$HOME/.local/var/lib")
> -   "Base directory for programs to store state files, like databases,
> -analogus to @file{/var/lib}, but for user.  It is not a part of XDG
> -Base Directory Specification, but helps to make implementation of home
> -services more consistent."))
> +   (path "$HOME/.local/state")

Ironically enough, it was my first idea for default value :)

> +   "Base directory for programs to store state data that should persist
> +between (application) restarts, such as logs, but are not important or
> +portable enough to the user to warrant storing them in
> +@env{XDG_DATA_HOME}."))
>  
>  (define (home-xdg-base-directories-environment-variables-service config)
>    (map
> @@ -158,12 +158,12 @@ (define home-xdg-base-directories-service-type
>                  (compose identity)
>                  (extend last-extension-or-cfg)
>                  (description "Configure XDG base directories.  This
> -service introduces two additional variables @env{XDG_STATE_HOME},
> -@env{XDG_LOG_HOME}.  They are not a part of XDG specification, at
> -least yet, but are convenient to have, it improves the consistency
> -between different home services.  The services of this service-type is
> -instantiated by default, to provide non-default value, extend the
> -service-type (using @code{simple-service} for example).")))
> +service introduces an additional @env{XDG_LOG_HOME} variable.  It's not
> +a part of XDG specification, at least yet, but are convenient to have,
> +it improves the consistency between different home services.  The
> +services of this service-type is instantiated by default, to provide
> +non-default value, extend the service-type (using @code{simple-service}
> +for example).")))
>  
>  (define (generate-home-xdg-base-directories-documentation)
>    (generate-documentation
>
> base-commit: d92ec2f2812c76b23aab778e26708cf353542ae9

Applied and pushed the first patch as 
5c893787be78a79433fe1343f5b70cd647e8f667

Will think about the second one a little more and reply on that later.

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Fri, 07 Apr 2023 08:46:01 GMT) Full text and rfc822 format available.

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

From: Andrew Tropin <andrew <at> trop.in>
To: Bruno Victal <mirai <at> makinata.eu>, 61982 <at> debbugs.gnu.org
Cc: Bruno Victal <mirai <at> makinata.eu>, philip <at> philipmcgrath.com
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Fri, 07 Apr 2023 12:45:15 +0400
[Message part 1 (text/plain, inline)]
On 2023-03-05 15:19, Bruno Victal wrote:

> XDG_LOG_HOME is non-standard and log files should go to XDG_STATE_HOME
> according to the XDG Base Directory Specification.
>
> Fixes <https://issues.guix.gnu.org/61809>.
>
> * gnu/home/services/desktop.scm (home-dbus-shepherd-services): Log to XDG_STATE_HOME.
> * gnu/home/services/mcron.scm (home-mcron-shepherd-services): Ditto.
> * gnu/home/services/pm.scm (home-batsignal-shepherd-services): Ditto.
> * gnu/home/services/shepherd.scm (launch-shepherd-gexp): Ditto.
> * gnu/home/services/xdg.scm
> (home-xdg-base-directories-configuration)[log-home]: Deprecate and unset default value.
> (home-xdg-base-directories-environment-variables-service)
> (ensure-xdg-base-dirs-on-activation): Handle field deprecation.
> (home-xdg-base-directories-service-type): Update description.
> ---
>  gnu/home/services/desktop.scm  |  4 ++--
>  gnu/home/services/mcron.scm    |  4 ++--
>  gnu/home/services/pm.scm       |  6 +++---
>  gnu/home/services/shepherd.scm |  4 ++--
>  gnu/home/services/xdg.scm      | 36 +++++++++++++++++++++++++---------
>  5 files changed, 36 insertions(+), 18 deletions(-)
>
> diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
> index cb25b03b64..76df7b30a2 100644
> --- a/gnu/home/services/desktop.scm
> +++ b/gnu/home/services/desktop.scm
> @@ -206,8 +206,8 @@ (define (home-dbus-shepherd-services config)
>                           (default-environment-variables))
>                     #:log-file
>                     (format #f "~a/dbus.log"
> -                           (or (getenv "XDG_LOG_HOME")
> -                               (format #f "~a/.local/var/log"
> +                           (or (getenv "XDG_STATE_HOME")
> +                               (format #f "~a/.local/state"

If we deprecate XDG_LOG_HOME, maybe it's a good idea to make a helper
function, which can be reused across different services?  

Also, how about appending /log subdirectory by default?

WDYT?

>                                         (getenv "HOME"))))))
>           (stop #~(make-kill-destructor)))))
>  
> diff --git a/gnu/home/services/mcron.scm b/gnu/home/services/mcron.scm
> index 5f35bfe054..69c7f9faa6 100644
> --- a/gnu/home/services/mcron.scm
> +++ b/gnu/home/services/mcron.scm
> @@ -99,8 +99,8 @@ (define (home-mcron-shepherd-services config)
>                                          #~())
>                                   #$@files)
>                             #:log-file (string-append
> -                                       (or (getenv "XDG_LOG_HOME")
> -                                           (format #f "~a/.local/var/log"
> +                                       (or (getenv "XDG_STATE_HOME")
> +                                           (format #f "~a/.local/state"
>                                                     (getenv "HOME")))
>                                         "/mcron.log")))
>                   (stop #~(make-kill-destructor))
> diff --git a/gnu/home/services/pm.scm b/gnu/home/services/pm.scm
> index 5f09941827..274ab2303c 100644
> --- a/gnu/home/services/pm.scm
> +++ b/gnu/home/services/pm.scm
> @@ -128,9 +128,9 @@ (define (home-batsignal-shepherd-services config)
>                                   (list "-i")
>                                   (list)))
>                       #:log-file (string-append
> -                                 (or (getenv "XDG_LOG_HOME")
> -                                     (format #f "~a/.local/var/log"
> -                                               (getenv "HOME")))
> +                                 (or (getenv "XDG_STATE_HOME")
> +                                     (format #f "~a/.local/state"
> +                                             (getenv "HOME")))
>                                   "/batsignal.log")))
>             (stop #~(make-kill-destructor))))))
>  
> diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
> index 1a70a220f0..825cf66f05 100644
> --- a/gnu/home/services/shepherd.scm
> +++ b/gnu/home/services/shepherd.scm
> @@ -108,8 +108,8 @@ (define (launch-shepherd-gexp config)
>                        (or (getenv "XDG_RUNTIME_DIR")
>                            (format #f "/run/user/~a" (getuid)))
>                        "/shepherd/socket"))
> -              (let ((log-dir (or (getenv "XDG_LOG_HOME")
> -                                 (format #f "~a/.local/var/log"
> +              (let ((log-dir (or (getenv "XDG_STATE_HOME")
> +                                 (format #f "~a/.local/state"
>                                           (getenv "HOME")))))
>                  ;; TODO: Remove it, 0.9.2 creates it automatically?
>                  ((@ (guix build utils) mkdir-p) log-dir)
> diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
> index ac557b4c3d..958772696b 100644
> --- a/gnu/home/services/xdg.scm
> +++ b/gnu/home/services/xdg.scm
> @@ -1,6 +1,7 @@
>  ;;; GNU Guix --- Functional package management for GNU
>  ;;; Copyright © 2021, 2022 Andrew Tropin <andrew <at> trop.in>
>  ;;; Copyright © 2021 Xinglu Chen <public <at> yoctocell.xyz>
> +;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -22,6 +23,7 @@ (define-module (gnu home services xdg)
>    #:use-module (gnu home services)
>    #:use-module (gnu packages freedesktop)
>    #:use-module (gnu home services utils)
> +  #:use-module (guix deprecation)
>    #:use-module (guix gexp)
>    #:use-module (guix modules)
>    #:use-module (guix records)
> @@ -39,7 +41,7 @@ (define-module (gnu home services xdg)
>              home-xdg-base-directories-configuration-config-home
>              home-xdg-base-directories-configuration-data-home
>              home-xdg-base-directories-configuration-state-home
> -            home-xdg-base-directories-configuration-log-home
> +            home-xdg-base-directories-configuration-log-home  ; deprecated
>              home-xdg-base-directories-configuration-runtime-dir
>  
>              home-xdg-user-directories-service-type
> @@ -77,6 +79,7 @@ (define-module (gnu home services xdg)
>  
>  (define (serialize-path field-name val) "")
>  (define path? string?)
> +(define-maybe path)
>  
>  (define-configuration home-xdg-base-directories-configuration
>    (cache-home
> @@ -97,12 +100,17 @@ (define-configuration home-xdg-base-directories-configuration
>     (path "${XDG_RUNTIME_DIR:-/run/user/$UID}")
>     "Base directory for programs to store user-specific runtime files,
>  like sockets.")
> +  ;; TODO: deprecated field, use $XDG_STATE_HOME(/log) instead.
>    (log-home
> -   (path "$HOME/.local/var/log")
> +   maybe-path
>     "Base directory for programs to store log files, analogus to
>  @file{/var/log}, but for user.  It is not a part of XDG Base Directory
>  Specification, but helps to make implementation of home services more
> -consistent.")
> +consistent."
> +   (lambda (field-name val)
> +     (when (maybe-value-set? val)
> +       (warn-about-deprecation field-name #f #:replacement 'state-home))
> +     (serialize-path field-name val)))
>    (state-home
>     (path "$HOME/.local/state")
>     "Base directory for programs to store state data that should persist
> @@ -117,7 +125,13 @@ (define (home-xdg-base-directories-environment-variables-service config)
>              #f "XDG_~a"
>              (object->snake-case-string (configuration-field-name field) 'upper))
>             ((configuration-field-getter field) config)))
> -   home-xdg-base-directories-configuration-fields))
> +   ;; XXX: deprecated field, remove later
> +   (if (maybe-value-set?
> +        (home-xdg-base-directories-configuration-log-home config))
> +       home-xdg-base-directories-configuration-fields
> +       (filter-configuration-fields
> +        home-xdg-base-directories-configuration-fields
> +        '(log-home) #t))))
>  
>  (define (ensure-xdg-base-dirs-on-activation config)
>    (with-imported-modules '((guix build utils))
> @@ -138,7 +152,14 @@ (define (ensure-xdg-base-dirs-on-activation config)
>                       ;; and will be provided by elogind or other service.
>                       (and (not (string=? "XDG_RUNTIME_DIR" variable))
>                            variable)))
> -                 home-xdg-base-directories-configuration-fields)))))
> +                 ;; XXX: deprecated field, remove later
> +                 (if (maybe-value-set?
> +                      (home-xdg-base-directories-configuration-log-home
> +                       config))
> +                     home-xdg-base-directories-configuration-fields
> +                     (filter-configuration-fields
> +                      home-xdg-base-directories-configuration-fields
> +                      '(log-home) #t)))))))
>  
>  (define (last-extension-or-cfg config extensions)
>    "Picks configuration value from last provided extension.  If there
> @@ -157,10 +178,7 @@ (define home-xdg-base-directories-service-type
>                  (default-value (home-xdg-base-directories-configuration))
>                  (compose identity)
>                  (extend last-extension-or-cfg)
> -                (description "Configure XDG base directories.  This
> -service introduces an additional @env{XDG_LOG_HOME} variable.  It's not
> -a part of XDG specification, at least yet, but are convenient to have,
> -it improves the consistency between different home services.  The
> +                (description "Configure XDG base directories.  The
>  services of this service-type is instantiated by default, to provide
>  non-default value, extend the service-type (using @code{simple-service}
>  for example).")))

Overall LGTM, let me know what you think on a few comments above.

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Fri, 07 Apr 2023 11:48:01 GMT) Full text and rfc822 format available.

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

From: Bruno Victal <mirai <at> makinata.eu>
To: Andrew Tropin <andrew <at> trop.in>
Cc: philip <at> philipmcgrath.com, 61982 <at> debbugs.gnu.org
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Fri, 7 Apr 2023 12:47:44 +0100
Hi Andrew,

On 2023-04-07 09:45, Andrew Tropin wrote:
> On 2023-03-05 15:19, Bruno Victal wrote:
>> --- a/gnu/home/services/desktop.scm
>> +++ b/gnu/home/services/desktop.scm
>> @@ -206,8 +206,8 @@ (define (home-dbus-shepherd-services config)
>>                           (default-environment-variables))
>>                     #:log-file
>>                     (format #f "~a/dbus.log"
>> -                           (or (getenv "XDG_LOG_HOME")
>> -                               (format #f "~a/.local/var/log"
>> +                           (or (getenv "XDG_STATE_HOME")
>> +                               (format #f "~a/.local/state"
> 
> If we deprecate XDG_LOG_HOME, maybe it's a good idea to make a helper
> function, which can be reused across different services?  
> 
> Also, how about appending /log subdirectory by default?
>> WDYT?

I'm wondering if this continued usage of XDG_LOG_HOME was a good idea,
maybe the service should just start using XDG_STATE_HOME as soon as possible?
(in which case, this patch will have to be reworked to reflect that)
This way we avoid introducing yet more code to handle deprecated code.

It shouldn't result in any kind of problems, XDG_LOG_HOME will still be set in the meantime
for scripts and code that happen to use it and are not part of (upstream) guix.

WDYT?


Cheers,
Bruno




Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Fri, 07 Apr 2023 12:47:02 GMT) Full text and rfc822 format available.

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

From: Andrew Tropin <andrew <at> trop.in>
To: Bruno Victal <mirai <at> makinata.eu>
Cc: philip <at> philipmcgrath.com, 61982 <at> debbugs.gnu.org
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Fri, 07 Apr 2023 16:46:34 +0400
[Message part 1 (text/plain, inline)]
On 2023-04-07 12:47, Bruno Victal wrote:

> Hi Andrew,
>
> On 2023-04-07 09:45, Andrew Tropin wrote:
>> On 2023-03-05 15:19, Bruno Victal wrote:
>>> --- a/gnu/home/services/desktop.scm
>>> +++ b/gnu/home/services/desktop.scm
>>> @@ -206,8 +206,8 @@ (define (home-dbus-shepherd-services config)
>>>                           (default-environment-variables))
>>>                     #:log-file
>>>                     (format #f "~a/dbus.log"
>>> -                           (or (getenv "XDG_LOG_HOME")
>>> -                               (format #f "~a/.local/var/log"
>>> +                           (or (getenv "XDG_STATE_HOME")
>>> +                               (format #f "~a/.local/state"
>> 
>> If we deprecate XDG_LOG_HOME, maybe it's a good idea to make a helper
>> function, which can be reused across different services?  
>> 
>> Also, how about appending /log subdirectory by default?
>>> WDYT?
>
> I'm wondering if this continued usage of XDG_LOG_HOME was a good idea,
> maybe the service should just start using XDG_STATE_HOME as soon as possible?
> (in which case, this patch will have to be reworked to reflect that)
> This way we avoid introducing yet more code to handle deprecated code.
>
> It shouldn't result in any kind of problems, XDG_LOG_HOME will still be set in the meantime
> for scripts and code that happen to use it and are not part of (upstream) guix.
>
> WDYT?

I meant introducing something like this
(define (get-log-dir)
 (string-append
  (getenv "XDG_STATE_HOME") "/log"))

and use it instead of
(or (getenv "XDG_STATE_HOME")
 (format #f "~a/.local/state" (getenv "HOME")))

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sun, 09 Apr 2023 19:10:02 GMT) Full text and rfc822 format available.

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

From: "Philip McGrath" <philip <at> philipmcgrath.com>
To: "Andrew Tropin" <andrew <at> trop.in>, "Bruno Victal" <mirai <at> makinata.eu>
Cc: 61982 <at> debbugs.gnu.org
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Sun, 09 Apr 2023 15:09:14 -0400
Hi,

On Fri, Apr 7, 2023, at 8:46 AM, Andrew Tropin wrote:
> On 2023-04-07 12:47, Bruno Victal wrote:
>
>> Hi Andrew,
>>
>> On 2023-04-07 09:45, Andrew Tropin wrote:
>>> On 2023-03-05 15:19, Bruno Victal wrote:
>>>> --- a/gnu/home/services/desktop.scm
>>>> +++ b/gnu/home/services/desktop.scm
>>>> @@ -206,8 +206,8 @@ (define (home-dbus-shepherd-services config)
>>>>                           (default-environment-variables))
>>>>                     #:log-file
>>>>                     (format #f "~a/dbus.log"
>>>> -                           (or (getenv "XDG_LOG_HOME")
>>>> -                               (format #f "~a/.local/var/log"
>>>> +                           (or (getenv "XDG_STATE_HOME")
>>>> +                               (format #f "~a/.local/state"
>>> 
>>> If we deprecate XDG_LOG_HOME, maybe it's a good idea to make a helper
>>> function, which can be reused across different services?  
>>> 
>>> Also, how about appending /log subdirectory by default?
>>>> WDYT?
>>
>> I'm wondering if this continued usage of XDG_LOG_HOME was a good idea,
>> maybe the service should just start using XDG_STATE_HOME as soon as possible?
>> (in which case, this patch will have to be reworked to reflect that)
>> This way we avoid introducing yet more code to handle deprecated code.
>>
>> It shouldn't result in any kind of problems, XDG_LOG_HOME will still be set in the meantime
>> for scripts and code that happen to use it and are not part of (upstream) guix.
>>
>> WDYT?
>
> I meant introducing something like this
> (define (get-log-dir)
>  (string-append
>   (getenv "XDG_STATE_HOME") "/log"))
>

Within the XDG directories, I think (unless perhaps you only use a single file) you are supposed to keep everything in a subdirectory named for your application (or with a well-known name for things shared among multiple applications). For example, on my system, I can find log files in "$XDG_DATA_HOME/akonadi/Akonadi.error", "$XDG_DATA_HOME/akonadi/Akonadi.error.old", "$XDG_DATA_HOME/sddm/wayland-session.log", and "$XDG_DATA_HOME/sddm/xorg-session.log". (Apparently SDDM and Akonadi haven't been updated to use $XDG_STATE_HOME.) I think Guix Home services should follow that convention, rather than putting all logs together in "$XDG_STATE_HOME/log/".

>
> and use it instead of
> (or (getenv "XDG_STATE_HOME")
>  (format #f "~a/.local/state" (getenv "HOME")))
>

Perhaps my least-favorite part of the XDG Base Directory specification is having to repeat the default values so many times. But I understood the conclusion from <https://issues.guix.gnu.org/56050#3> to be that Guix should be able to assume that the XDG variables are all explicitly set, either by Guix System or by the installation process for Guix on a foreign distro.

-Philip 




Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sun, 09 Apr 2023 19:58:02 GMT) Full text and rfc822 format available.

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

From: "(" <paren <at> disroot.org>
To: "Philip McGrath" <philip <at> philipmcgrath.com>, "Andrew Tropin"
 <andrew <at> trop.in>, "Bruno Victal" <mirai <at> makinata.eu>
Cc: 61982 <at> debbugs.gnu.org
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Sun, 09 Apr 2023 20:57:54 +0100
[Message part 1 (text/plain, inline)]
On Sun Apr 9, 2023 at 8:09 PM BST, Philip McGrath wrote:
> > I meant introducing something like this
> > (define (get-log-dir)
> >  (string-append
> >   (getenv "XDG_STATE_HOME") "/log"))
> >
>
> Within the XDG directories, I think (unless perhaps you only use a single file) you are supposed to keep everything in a subdirectory named for your application (or with a well-known name for things shared among multiple applications). For example, on my system, I can find log files in "$XDG_DATA_HOME/akonadi/Akonadi.error", "$XDG_DATA_HOME/akonadi/Akonadi.error.old", "$XDG_DATA_HOME/sddm/wayland-session.log", and "$XDG_DATA_HOME/sddm/xorg-session.log". (Apparently SDDM and Akonadi haven't been updated to use $XDG_STATE_HOME.) I think Guix Home services should follow that convention, rather than putting all logs together in "$XDG_STATE_HOME/log/".

So it turns out Shepherd provides these gems squirreled away inside its
(shepherd support) module:

```
(define %user-config-dir
  ;; Default config directory if shepherd is run as a normal user.
  (string-append (or (getenv "XDG_CONFIG_HOME")
                     (string-append user-homedir "/.config"))
                 "/shepherd"))

(define %user-log-dir
  ;; Default log directory if shepherd is run as a normal user.
  (string-append (or (getenv "XDG_STATE_HOME")
                     (string-append user-homedir "/.local/state"))
                 "/shepherd"))

(define %user-runtime-dir
  ;; Default runtime directory if shepherd is run as a normal user.
  (string-append (or (getenv "XDG_RUNTIME_DIR")
                     (format #f "/run/user/~s" (getuid)))))
```

Shepherd already provides us with a %USER-LOG-DIR variable :D

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

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sun, 09 Apr 2023 20:02:01 GMT) Full text and rfc822 format available.

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

From: "(" <paren <at> disroot.org>
To: "(" <paren <at> disroot.org>, "Philip McGrath" <philip <at> philipmcgrath.com>,
 "Andrew Tropin" <andrew <at> trop.in>, "Bruno Victal" <mirai <at> makinata.eu>
Cc: 61982 <at> debbugs.gnu.org
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Sun, 09 Apr 2023 21:01:48 +0100
[Message part 1 (text/plain, inline)]
On Sun Apr 9, 2023 at 8:57 PM BST, ( via Guix-patches via wrote:
> Shepherd already provides us with a %USER-LOG-DIR variable :D

One thing I will note is that it might be good if (shepherd support) was one
of the modules imported into shepherd service gexps by default.

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

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Wed, 12 Apr 2023 13:04:01 GMT) Full text and rfc822 format available.

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

From: "(" <paren <at> disroot.org>
To: "(" <paren <at> disroot.org>
Cc: 61982 <at> debbugs.gnu.org, Bruno Victal <mirai <at> makinata.eu>,
 Philip McGrath <philip <at> philipmcgrath.com>, guix-patches <at> gnu.org,
 Andrew Tropin <andrew <at> trop.in>
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Tue, 11 Apr 2023 21:01:31 +0100
"( via Guix-patches" via <guix-patches <at> gnu.org> writes:
> Shepherd already provides us with a %USER-LOG-DIR variable :D

Apparently I can't read.  This is *Shepherd*'s log dir, not a general
log dir variable.  Oops :)  I suppose that would be a good thing to add
to (gnu build utils), then...




Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Wed, 12 Apr 2023 13:05:02 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Wed, 12 Apr 2023 17:19:02 GMT) Full text and rfc822 format available.

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

From: Andrew Tropin <andrew <at> trop.in>
To: "(" <paren <at> disroot.org>, "(" <paren <at> disroot.org>
Cc: Bruno Victal <mirai <at> makinata.eu>, Philip McGrath <philip <at> philipmcgrath.com>,
 guix-patches <at> gnu.org, 61982 <at> debbugs.gnu.org
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Wed, 12 Apr 2023 21:17:49 +0400
[Message part 1 (text/plain, inline)]
On 2023-04-11 21:01, paren <at> disroot.org wrote:

> "( via Guix-patches" via <guix-patches <at> gnu.org> writes:
>> Shepherd already provides us with a %USER-LOG-DIR variable :D
>
> Apparently I can't read.  This is *Shepherd*'s log dir, not a general
> log dir variable.  Oops :)

That's right :)

> I suppose that would be a good thing to add to (gnu build utils),
> then...

Yep, I have the same idea.

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Wed, 12 Apr 2023 17:19:02 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Fri, 09 Jun 2023 21:02:02 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Andrew Tropin <andrew <at> trop.in>
Cc: Bruno Victal <mirai <at> makinata.eu>, 61982 <at> debbugs.gnu.org,
 philip <at> philipmcgrath.com
Subject: Re: bug#61982: [PATCH 0/2] Respect XDG Base Directory Specification
 0.8.
Date: Fri, 09 Jun 2023 23:01:35 +0200
Hi Andrew,

Andrew Tropin <andrew <at> trop.in> skribis:

> Applied and pushed the first patch as 
> 5c893787be78a79433fe1343f5b70cd647e8f667
>
> Will think about the second one a little more and reply on that later.

Could you take a look and apply it or close the issue?

Thanks in advance,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Wed, 14 Jun 2023 09:28:02 GMT) Full text and rfc822 format available.

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

From: Andrew Tropin <andrew <at> trop.in>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: Bruno Victal <mirai <at> makinata.eu>, 61982 <at> debbugs.gnu.org,
 philip <at> philipmcgrath.com
Subject: Re: bug#61982: [PATCH 0/2] Respect XDG Base Directory Specification
 0.8.
Date: Wed, 14 Jun 2023 13:27:17 +0400
[Message part 1 (text/plain, inline)]
On 2023-06-09 23:01, Ludovic Courtès wrote:

> Hi Andrew,
>
> Andrew Tropin <andrew <at> trop.in> skribis:
>
>> Applied and pushed the first patch as 
>> 5c893787be78a79433fe1343f5b70cd647e8f667
>>
>> Will think about the second one a little more and reply on that later.
>
> Could you take a look and apply it or close the issue?

Sure, added this thread to my agenda for this week.

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Reply sent to Andrew Tropin <andrew <at> trop.in>:
You have taken responsibility. (Thu, 15 Jun 2023 09:36:01 GMT) Full text and rfc822 format available.

Notification sent to Bruno Victal <mirai <at> makinata.eu>:
bug acknowledged by developer. (Thu, 15 Jun 2023 09:36:01 GMT) Full text and rfc822 format available.

Message #55 received at 61982-done <at> debbugs.gnu.org (full text, mbox):

From: Andrew Tropin <andrew <at> trop.in>
To: Bruno Victal <mirai <at> makinata.eu>, 61982-done <at> debbugs.gnu.org, Ludovic
 Courtès <ludo <at> gnu.org>
Cc: Bruno Victal <mirai <at> makinata.eu>, philip <at> philipmcgrath.com
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Thu, 15 Jun 2023 13:35:24 +0400
[Message part 1 (text/plain, inline)]
On 2023-03-05 15:19, Bruno Victal wrote:

> XDG_LOG_HOME is non-standard and log files should go to XDG_STATE_HOME
> according to the XDG Base Directory Specification.
>
> Fixes <https://issues.guix.gnu.org/61809>.
>
> * gnu/home/services/desktop.scm (home-dbus-shepherd-services): Log to XDG_STATE_HOME.
> * gnu/home/services/mcron.scm (home-mcron-shepherd-services): Ditto.
> * gnu/home/services/pm.scm (home-batsignal-shepherd-services): Ditto.
> * gnu/home/services/shepherd.scm (launch-shepherd-gexp): Ditto.
> * gnu/home/services/xdg.scm
> (home-xdg-base-directories-configuration)[log-home]: Deprecate and unset default value.
> (home-xdg-base-directories-environment-variables-service)
> (ensure-xdg-base-dirs-on-activation): Handle field deprecation.
> (home-xdg-base-directories-service-type): Update description.
> ---
>  gnu/home/services/desktop.scm  |  4 ++--
>  gnu/home/services/mcron.scm    |  4 ++--
>  gnu/home/services/pm.scm       |  6 +++---
>  gnu/home/services/shepherd.scm |  4 ++--
>  gnu/home/services/xdg.scm      | 36 +++++++++++++++++++++++++---------
>  5 files changed, 36 insertions(+), 18 deletions(-)
>
> diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
> index cb25b03b64..76df7b30a2 100644
> --- a/gnu/home/services/desktop.scm
> +++ b/gnu/home/services/desktop.scm
> @@ -206,8 +206,8 @@ (define (home-dbus-shepherd-services config)
>                           (default-environment-variables))
>                     #:log-file
>                     (format #f "~a/dbus.log"
> -                           (or (getenv "XDG_LOG_HOME")
> -                               (format #f "~a/.local/var/log"
> +                           (or (getenv "XDG_STATE_HOME")
> +                               (format #f "~a/.local/state"
>                                         (getenv "HOME"))))))
>           (stop #~(make-kill-destructor)))))
>  
> diff --git a/gnu/home/services/mcron.scm b/gnu/home/services/mcron.scm
> index 5f35bfe054..69c7f9faa6 100644
> --- a/gnu/home/services/mcron.scm
> +++ b/gnu/home/services/mcron.scm
> @@ -99,8 +99,8 @@ (define (home-mcron-shepherd-services config)
>                                          #~())
>                                   #$@files)
>                             #:log-file (string-append
> -                                       (or (getenv "XDG_LOG_HOME")
> -                                           (format #f "~a/.local/var/log"
> +                                       (or (getenv "XDG_STATE_HOME")
> +                                           (format #f "~a/.local/state"
>                                                     (getenv "HOME")))
>                                         "/mcron.log")))
>                   (stop #~(make-kill-destructor))
> diff --git a/gnu/home/services/pm.scm b/gnu/home/services/pm.scm
> index 5f09941827..274ab2303c 100644
> --- a/gnu/home/services/pm.scm
> +++ b/gnu/home/services/pm.scm
> @@ -128,9 +128,9 @@ (define (home-batsignal-shepherd-services config)
>                                   (list "-i")
>                                   (list)))
>                       #:log-file (string-append
> -                                 (or (getenv "XDG_LOG_HOME")
> -                                     (format #f "~a/.local/var/log"
> -                                               (getenv "HOME")))
> +                                 (or (getenv "XDG_STATE_HOME")
> +                                     (format #f "~a/.local/state"
> +                                             (getenv "HOME")))
>                                   "/batsignal.log")))
>             (stop #~(make-kill-destructor))))))
>  
> diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
> index 1a70a220f0..825cf66f05 100644
> --- a/gnu/home/services/shepherd.scm
> +++ b/gnu/home/services/shepherd.scm
> @@ -108,8 +108,8 @@ (define (launch-shepherd-gexp config)
>                        (or (getenv "XDG_RUNTIME_DIR")
>                            (format #f "/run/user/~a" (getuid)))
>                        "/shepherd/socket"))
> -              (let ((log-dir (or (getenv "XDG_LOG_HOME")
> -                                 (format #f "~a/.local/var/log"
> +              (let ((log-dir (or (getenv "XDG_STATE_HOME")
> +                                 (format #f "~a/.local/state"
>                                           (getenv "HOME")))))
>                  ;; TODO: Remove it, 0.9.2 creates it automatically?
>                  ((@ (guix build utils) mkdir-p) log-dir)
> diff --git a/gnu/home/services/xdg.scm b/gnu/home/services/xdg.scm
> index ac557b4c3d..958772696b 100644
> --- a/gnu/home/services/xdg.scm
> +++ b/gnu/home/services/xdg.scm
> @@ -1,6 +1,7 @@
>  ;;; GNU Guix --- Functional package management for GNU
>  ;;; Copyright © 2021, 2022 Andrew Tropin <andrew <at> trop.in>
>  ;;; Copyright © 2021 Xinglu Chen <public <at> yoctocell.xyz>
> +;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -22,6 +23,7 @@ (define-module (gnu home services xdg)
>    #:use-module (gnu home services)
>    #:use-module (gnu packages freedesktop)
>    #:use-module (gnu home services utils)
> +  #:use-module (guix deprecation)
>    #:use-module (guix gexp)
>    #:use-module (guix modules)
>    #:use-module (guix records)
> @@ -39,7 +41,7 @@ (define-module (gnu home services xdg)
>              home-xdg-base-directories-configuration-config-home
>              home-xdg-base-directories-configuration-data-home
>              home-xdg-base-directories-configuration-state-home
> -            home-xdg-base-directories-configuration-log-home
> +            home-xdg-base-directories-configuration-log-home  ; deprecated
>              home-xdg-base-directories-configuration-runtime-dir
>  
>              home-xdg-user-directories-service-type
> @@ -77,6 +79,7 @@ (define-module (gnu home services xdg)
>  
>  (define (serialize-path field-name val) "")
>  (define path? string?)
> +(define-maybe path)
>  
>  (define-configuration home-xdg-base-directories-configuration
>    (cache-home
> @@ -97,12 +100,17 @@ (define-configuration home-xdg-base-directories-configuration
>     (path "${XDG_RUNTIME_DIR:-/run/user/$UID}")
>     "Base directory for programs to store user-specific runtime files,
>  like sockets.")
> +  ;; TODO: deprecated field, use $XDG_STATE_HOME(/log) instead.
>    (log-home
> -   (path "$HOME/.local/var/log")
> +   maybe-path
>     "Base directory for programs to store log files, analogus to
>  @file{/var/log}, but for user.  It is not a part of XDG Base Directory
>  Specification, but helps to make implementation of home services more
> -consistent.")
> +consistent."
> +   (lambda (field-name val)
> +     (when (maybe-value-set? val)
> +       (warn-about-deprecation field-name #f #:replacement 'state-home))
> +     (serialize-path field-name val)))
>    (state-home
>     (path "$HOME/.local/state")
>     "Base directory for programs to store state data that should persist
> @@ -117,7 +125,13 @@ (define (home-xdg-base-directories-environment-variables-service config)
>              #f "XDG_~a"
>              (object->snake-case-string (configuration-field-name field) 'upper))
>             ((configuration-field-getter field) config)))
> -   home-xdg-base-directories-configuration-fields))
> +   ;; XXX: deprecated field, remove later
> +   (if (maybe-value-set?
> +        (home-xdg-base-directories-configuration-log-home config))
> +       home-xdg-base-directories-configuration-fields
> +       (filter-configuration-fields
> +        home-xdg-base-directories-configuration-fields
> +        '(log-home) #t))))
>  
>  (define (ensure-xdg-base-dirs-on-activation config)
>    (with-imported-modules '((guix build utils))
> @@ -138,7 +152,14 @@ (define (ensure-xdg-base-dirs-on-activation config)
>                       ;; and will be provided by elogind or other service.
>                       (and (not (string=? "XDG_RUNTIME_DIR" variable))
>                            variable)))
> -                 home-xdg-base-directories-configuration-fields)))))
> +                 ;; XXX: deprecated field, remove later
> +                 (if (maybe-value-set?
> +                      (home-xdg-base-directories-configuration-log-home
> +                       config))
> +                     home-xdg-base-directories-configuration-fields
> +                     (filter-configuration-fields
> +                      home-xdg-base-directories-configuration-fields
> +                      '(log-home) #t)))))))
>  
>  (define (last-extension-or-cfg config extensions)
>    "Picks configuration value from last provided extension.  If there
> @@ -157,10 +178,7 @@ (define home-xdg-base-directories-service-type
>                  (default-value (home-xdg-base-directories-configuration))
>                  (compose identity)
>                  (extend last-extension-or-cfg)
> -                (description "Configure XDG base directories.  This
> -service introduces an additional @env{XDG_LOG_HOME} variable.  It's not
> -a part of XDG specification, at least yet, but are convenient to have,
> -it improves the consistency between different home services.  The
> +                (description "Configure XDG base directories.  The
>  services of this service-type is instantiated by default, to provide
>  non-default value, extend the service-type (using @code{simple-service}
>  for example).")))

Hi Bruno,

Applied, added log subdirectory, pushed, thank you for working on it.


Hi Ludo,

WDYT about adding (home-log-dir) function to (guix build utils)?
So we can prevent copypasting the same code all over home modules.

Something like:
--8<---------------cut here---------------start------------->8---
(define (home-log-dir)
  "Returns a directory for user applications logs."
  (string-append
   (or (getenv "XDG_STATE_HOME")
       (format #f "~a/.local/state"
               (getenv "HOME")))
   "/log"))
--8<---------------cut here---------------end--------------->8---

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Thu, 15 Jun 2023 18:10:01 GMT) Full text and rfc822 format available.

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

From: "Philip McGrath" <philip <at> philipmcgrath.com>
To: "Andrew Tropin" <andrew <at> trop.in>, "Bruno Victal" <mirai <at> makinata.eu>,
 61982 <at> debbugs.gnu.org, Ludovic Courtès <ludo <at> gnu.org>
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Thu, 15 Jun 2023 14:09:22 -0400
Hi,

On Thu, Jun 15, 2023, at 5:35 AM, Andrew Tropin wrote:
>
> WDYT about adding (home-log-dir) function to (guix build utils)?
> So we can prevent copypasting the same code all over home modules.
>
> Something like:
> --8<---------------cut here---------------start------------->8---
> (define (home-log-dir)
>   "Returns a directory for user applications logs."
>   (string-append
>    (or (getenv "XDG_STATE_HOME")
>        (format #f "~a/.local/state"
>                (getenv "HOME")))
>    "/log"))
> --8<---------------cut here---------------end--------------->8---
>

I still think idiomatic XDG structure is NOT to have a "/log" subdirectory like this, as I explained in <https://issues.guix.gnu.org/61982#7>.

Aside from that, though, I thought the conclusion from <https://issues.guix.gnu.org/56050#3> was that it is the responsibility of Guix System or the installation mechanism for Guix on a foreign distribution (e.g. "/etc/profile.d/zzz-guix.sh") to initialize all of the XDG variables, so code like this can use `(getenv "XDG_STATE_HOME")` unconditionally (or indeed with a checked assertion). Maybe there's some context I'm forgetting, though. I've been looking into these things again as I attempt to solve <https://lists.gnu.org/archive/html/help-guix/2023-06/msg00031.html>: I noticed in the attached environment variables that entries under /home/philip/.guix-home/profile/ are duplicated in many search paths.

-Philip




Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Fri, 16 Jun 2023 03:29:02 GMT) Full text and rfc822 format available.

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

From: Andrew Tropin <andrew <at> trop.in>
To: Philip McGrath <philip <at> philipmcgrath.com>, Bruno Victal
 <mirai <at> makinata.eu>, 61982 <at> debbugs.gnu.org, Ludovic Courtès <ludo <at> gnu.org>
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Fri, 16 Jun 2023 07:28:32 +0400
[Message part 1 (text/plain, inline)]
On 2023-06-15 14:09, Philip McGrath wrote:

> Hi,
>
> On Thu, Jun 15, 2023, at 5:35 AM, Andrew Tropin wrote:
>>
>> WDYT about adding (home-log-dir) function to (guix build utils)?
>> So we can prevent copypasting the same code all over home modules.
>>
>> Something like:
>> --8<---------------cut here---------------start------------->8---
>> (define (home-log-dir)
>>   "Returns a directory for user applications logs."
>>   (string-append
>>    (or (getenv "XDG_STATE_HOME")
>>        (format #f "~a/.local/state"
>>                (getenv "HOME")))
>>    "/log"))
>> --8<---------------cut here---------------end--------------->8---
>>
>
> I still think idiomatic XDG structure is NOT to have a "/log"
> subdirectory like this, as I explained in
> <https://issues.guix.gnu.org/61982#7>.

With a brief look I didn't find information about this idiom in
specification, but you can highlight it with quote or link.

Anyway, I'm ok with storing logs in app subdirectory or "/log", not so
ok with storing them in the root of state home.

>
> Aside from that, though, I thought the conclusion from
> <https://issues.guix.gnu.org/56050#3> was that it is the
> responsibility of Guix System or the installation mechanism for Guix
> on a foreign distribution (e.g. "/etc/profile.d/zzz-guix.sh") to
> initialize all of the XDG variables, so code like this can use
> `(getenv "XDG_STATE_HOME")` unconditionally (or indeed with a checked
> assertion). Maybe there's some context I'm forgetting, though. I've
> been looking into these things again as I attempt to solve
> <https://lists.gnu.org/archive/html/help-guix/2023-06/msg00031.html>:
> I noticed in the attached environment variables that entries under
> /home/philip/.guix-home/profile/ are duplicated in many search paths.

home-state-dir function can also be useful, which can later become just
(getenv ("XDG_STATE_HOME")).

-- 
Best regards,
Andrew Tropin
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#61982; Package guix-patches. (Sat, 17 Jun 2023 18:23:02 GMT) Full text and rfc822 format available.

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

From: "Philip McGrath" <philip <at> philipmcgrath.com>
To: "Andrew Tropin" <andrew <at> trop.in>, "Bruno Victal" <mirai <at> makinata.eu>,
 61982 <at> debbugs.gnu.org, Ludovic Courtès <ludo <at> gnu.org>
Subject: Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories:
 Deprecate XDG_LOG_HOME.
Date: Sat, 17 Jun 2023 14:22:27 -0400
Hi,

On Thu, Jun 15, 2023, at 11:28 PM, Andrew Tropin wrote:
> On 2023-06-15 14:09, Philip McGrath wrote:
>
>> Hi,
>>
>> On Thu, Jun 15, 2023, at 5:35 AM, Andrew Tropin wrote:
>>>
>>> WDYT about adding (home-log-dir) function to (guix build utils)?
>>> So we can prevent copypasting the same code all over home modules.
>>>
>>> Something like:
>>> --8<---------------cut here---------------start------------->8---
>>> (define (home-log-dir)
>>>   "Returns a directory for user applications logs."
>>>   (string-append
>>>    (or (getenv "XDG_STATE_HOME")
>>>        (format #f "~a/.local/state"
>>>                (getenv "HOME")))
>>>    "/log"))
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>
>> I still think idiomatic XDG structure is NOT to have a "/log"
>> subdirectory like this, as I explained in
>> <https://issues.guix.gnu.org/61982#7>.
>
> With a brief look I didn't find information about this idiom in
> specification, but you can highlight it with quote or link.
>
> Anyway, I'm ok with storing logs in app subdirectory or "/log", not so
> ok with storing them in the root of state home.
>

You are right that the idiomatic usage isn't made very explicit in the specification. In the specification itself, the idiom is implicit in the "Referencing this specification" section, which always uses a subdirectory:

>
> Other specifications may reference this specification by specifying the location of a data file as $XDG_DATA_DIRS/subdir/filename. This implies that:
>
> - Such file should be installed to $datadir/subdir/filename with $datadir defaulting to /usr/share.
>
> - A user-specific version of the data file may be created in $XDG_DATA_HOME/subdir/filename, taking into account the default value for $XDG_DATA_HOME if $XDG_DATA_HOME is not set.
>
> - Lookups of the data file should search for ./subdir/filename relative to all base directories specified by $XDG_DATA_HOME and $XDG_DATA_DIRS . If an environment variable is either not set or empty, its default value as defined by this specification should be used instead. 
>
> Specifications may reference this specification by specifying the location of a configuration file as $XDG_CONFIG_DIRS/subdir/filename. This implies that:
>
> - Default configuration files should be installed to $sysconfdir/xdg/subdir/filename with $sysconfdir defaulting to /etc.
>
> - A user-specific version of the configuration file may be created in $XDG_CONFIG_HOME/subdir/filename, taking into account the default value for $XDG_CONFIG_HOME if $XDG_CONFIG_HOME is not set.
>
> - Lookups of the configuration file should search for ./subdir/filename relative to all base directories indicated by $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS . If an environment variable is either not set or empty, its default value as defined by this specification should be used instead. 
>

(Obviously $HOME/.local/bin is a special case, since using subdirectories there would defeat the point.)

More than the text of the specification, I'd look at actual observed usage and documented best practices. The relevant Gnome Goal [1] (despite outbound linkrot) is consistent with every other developer guide I've seen in showing the use of subdirectories, e.g. in the Glib example code:

```
const char *cache_dir = g_get_user_cache_dir ();
char *mydir = g_build_filename (cache_dir, "myapp", NULL);
/* use it */
g_free (mydir);
```

(Glib now provides g_get_user_state_dir, too. [2])

The Arch wiki has a survey of XDG support status [3] that consistently shows applications using appropriate subdirectories.

[1]: https://wiki.gnome.org/Initiatives/GnomeGoals/XDGConfigFolders
[2]: https://docs.gtk.org/glib/func.get_user_state_dir.html
[3]: https://wiki.archlinux.org/title/XDG_Base_Directory

>>
>> Aside from that, though, I thought the conclusion from
>> <https://issues.guix.gnu.org/56050#3> was that it is the
>> responsibility of Guix System or the installation mechanism for Guix
>> on a foreign distribution (e.g. "/etc/profile.d/zzz-guix.sh") to
>> initialize all of the XDG variables, so code like this can use
>> `(getenv "XDG_STATE_HOME")` unconditionally (or indeed with a checked
>> assertion). Maybe there's some context I'm forgetting, though. I've
>> been looking into these things again as I attempt to solve
>> <https://lists.gnu.org/archive/html/help-guix/2023-06/msg00031.html>:
>> I noticed in the attached environment variables that entries under
>> /home/philip/.guix-home/profile/ are duplicated in many search paths.
>
> home-state-dir function can also be useful, which can later become just
> (getenv ("XDG_STATE_HOME")).
>

I'm not at all opposed to providing functions rather that using getenv everywhere: they could guard against typos, check invariants, and all the other usual helpful things. But---though maybe I'm missing some context---how often is it actually needed to pass these default values? As long as the upstream software supports XDG directories properly, I would think it should just do the right thing without having to pass a bunch of explicit configuration options.

-Philip




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 16 Jul 2023 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 256 days ago.

Previous Next


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