[PATCH 0/2] Respect XDG Base Directory Specification 0.8.

  • Done
  • quality assurance status badge
Details
5 participants
  • Andrew Tropin
  • Ludovic Courtès
  • Bruno Victal
  • (
  • Philip McGrath
Owner
unassigned
Submitted by
Bruno Victal
Severity
normal
B
B
Bruno Victal wrote on 5 Mar 2023 16:16
(address . guix-patches@gnu.org)(name . Bruno Victal)(address . mirai@makinata.eu)
cover.1678029159.git.mirai@makinata.eu
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
B
B
Bruno Victal wrote on 5 Mar 2023 16:19
[PATCH 1/2] home: services: xdg-base-directories: Set correct value for XDG_STATE_HOME.
(address . 61982@debbugs.gnu.org)
3005f8a58ec5afc447f2baf40958956bd0d16099.1678029530.git.mirai@makinata.eu
XDG Base Directory Specification 0.8 officially introduces the
XDG_STATE_HOME environment variable.


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

Toggle diff (44 lines)
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
B
B
Bruno Victal wrote on 5 Mar 2023 16:19
[PATCH 2/2] home: services: xdg-base-directories: Deprecate XDG_LOG_HOME.
(address . 61982@debbugs.gnu.org)
0a0764da3fa04f9a02f37a7960a0c9608782854d.1678029530.git.mirai@makinata.eu
XDG_LOG_HOME is non-standard and log files should go to XDG_STATE_HOME
according to the XDG Base Directory Specification.


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

Toggle diff (164 lines)
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@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2023 Bruno Victal <mirai@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
A
A
Andrew Tropin wrote on 7 Apr 2023 08:43
Re: [bug#61982] [PATCH 1/2] home: services: xdg-base-directories: Set correct value for XDG_STATE_HOME.
87lej4w5sp.fsf@trop.in
On 2023-03-05 15:19, Bruno Victal wrote:

Toggle quote (28 lines)
> 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 :)

Toggle quote (29 lines)
> + "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
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmQvu6YACgkQIgjSCVjB
3rBkxg//bw2Snxad+y2klyFnHcvEBTknll1fF0v4jpT2Ex4IBZsnRhgAnbWDfIBV
xG7DwYC+uAr443rsj4joFpapMJK2d8OJBBff45I4u3KYFZ9Z/bLfurTS7cX8aPIC
Kcx5Wwvuf1R7ZWk+bRhHcQ75DmqAmBlLhupcBAluXgQ2kA+JhfyHnbv2zBAO9P8d
TFYzu4LunHIY8ZTrsvwJsUg7J/dIDN0dI8YQMLzalHivXtFlLkUBbiJfgnDnu+dv
YGUFGBqQmBpHq+5zcOqR1wnJhvqPzDuK15r160fpnrxp2JGe6m4qQSCeW/VxsJF2
PvXX+fyTwHT1dLv+0DCOzUJofgTMZ/7C/yDr3xKd+a1GHXlRHQowzfnsF33+xiuq
fJHdQ29FH0F3P5WfUQdylwqsbuzaZpTVmAcY7xV3YVzyXqkNmSwia6rdR2z5w87+
R6Jq4P01YXiG6i+hi5pZE0bZMSGHtk04sQYm7arI70WZmMuhtLHqZa2Z3F56u3/Q
fS2u6KrO0IgsD6d5lebO0LN1Dg91xSJ7Dao5gnAt24vUVbSfYY6vBgiNy4fKUlpg
NTpb0IPitGmQ3x7aKfUHqTJby/bIqqCRSkwTBVh1cPnhim5cXbSsGZNS//9Krxfb
LODE2N/dfvK6b95CL9Q/4HTxrEyY8iDDnjk51ovklilVzzyMNo8=
=LYE/
-----END PGP SIGNATURE-----

A
A
Andrew Tropin wrote on 7 Apr 2023 10:45
Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories: Deprecate XDG_LOG_HOME.
87cz4gw06c.fsf@trop.in
On 2023-03-05 15:19, Bruno Victal wrote:

Toggle quote (35 lines)
> 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?

Toggle quote (151 lines)
> (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@trop.in>
> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
> +;;; Copyright © 2023 Bruno Victal <mirai@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
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmQv2BsACgkQIgjSCVjB
3rDrhw//cWndPui+Kl5k5KEkufH933IXT/qy8Y4yefqd9MJLAIbhfqTwsjz4v52P
YBeYAJb0vx0Vh9Cq22clzvFq3w9wbVsaKeDkC2sL1Xk3vATRxSuvMI6gcAw8M4Hh
3jc1Lbxv4rv3181d3Qjq+hV665gCSpEDb/gp2dBieGpMRhFPloDdjPkIoebtk9B+
rhngsrvlV67mZl5HDJai91+7BSsBKY2mMxnQ6WOgvFoRUP14YEQ0YM2iikOpnvp+
2Gjw6WIMRJC4CILglqf2mfLcBbxS6ivrgukOcvlpb0WR9wa7OlFpTZsARC39JPrd
DoB54HvmiJzs7cN/gbxfST35rZA/O6P6VnbFjjlIyFrtVr6s2+ORTDfz4k20tSia
hd83o6Z0jMrSr0x1PH9xjPCZ/2bKLiqGzpgvcP0cxl6yttiItojpSrXtBANTsT1Q
AzKYk43QO09hlJvIWYj7NXZvwB4Tlq+5/Uu8XQr6/K472OvUgc1+0BGcjxWtEWnY
F0/3i9d2OUdUJBqUi87j/2pN+C4bBZnJ7KPA/gCdJS2agPMN+88gybj0JBDKbePC
EMcKI91iWPV0vv2VsRMpTeTQZ8WZTZo7KCq49IwsdqBdK2Cj4RgGbb+8sbDPK4/6
C7DRl6O0sh7+ilcuEg8QeUGqz+FhR68uzP6LG+o/8lDOlvhKhwE=
=ijCt
-----END PGP SIGNATURE-----

B
B
Bruno Victal wrote on 7 Apr 2023 13:47
(name . Andrew Tropin)(address . andrew@trop.in)
10e30d4c-07f2-8bf9-24ed-7bbf820d12e8@makinata.eu
Hi Andrew,

On 2023-04-07 09:45, Andrew Tropin wrote:
Toggle quote (18 lines)
> 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
A
A
Andrew Tropin wrote on 7 Apr 2023 14:46
(name . Bruno Victal)(address . mirai@makinata.eu)
875ya7x3kl.fsf@trop.in
On 2023-04-07 12:47, Bruno Victal wrote:

Toggle quote (31 lines)
> 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
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmQwEKoACgkQIgjSCVjB
3rD0Tw/+Kn9fjK0gunUgwz0wWZ9T/+uvK8PFedGXRpDMH/ZV/iwHXC3AiS5R0I++
eHMTF0slJ6H06buDmaMwSZYy750R5GBJ7Ec4XQjLa+TSLSLaOIjP3BhviMFqxWJP
zmGVqzT4ajsUgLHAbTAF7XymZMuHnggN8UZJzg1ZVEiF7amGIygP9CtE3GQbehao
Erylha2O1ZZFMvwepmYBF9auhN1pyD5Um5Tn/IijAllc4VpCIsTIQBmozlNUIR0G
GktkYIwo6C9H/R5v+O8C/ROFVjjMl/k4GMm/I8pLHUCQiy0FSfoKQmcSzbprY4TT
nYVJvnvSnEtZ+CeamdB2l2O3Yqu/v4QdaPOvbq+j2+b818g378ffp5Je4BQ0n32U
WmIEfq3W+vWHuffhWyozcb3RTbO14UxIECjVyPSSQezeolNWhJtJnvI8gphsBb+8
MOlm4suVDSpBJPjDkX5vVOn2tayMDyuI4AgqhUKWjDKZ4IaG1Cl+ML3msMqbdyjR
9hkYxnkBK+EeBDizPhuzDjRlFirXxmHUo3FmN6U/r0U127xlUWc52Bpn1tc8Yj0c
XSFMn/GHOotJVLTIozd/Q8LFFbAvt6RNmeXg7oWpo3exDdQ730F9Kci0dZsdc+DL
Ek0Pkb5yOPPuazbgR3oz85yEEmuyr31USpuaq3o3CKZqVBAtinU=
=szw0
-----END PGP SIGNATURE-----

P
P
Philip McGrath wrote on 9 Apr 2023 21:09
(address . 61982@debbugs.gnu.org)
92d07a8a-aac9-42c7-809d-66373358c77b@app.fastmail.com
Hi,

On Fri, Apr 7, 2023, at 8:46 AM, Andrew Tropin wrote:
Toggle quote (39 lines)
> 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/".

Toggle quote (6 lines)
>
> 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
(
(address . 61982@debbugs.gnu.org)
CRSHOENTZGT6.2A5WD1YC8VIRO@guix-framework
On Sun Apr 9, 2023 at 8:09 PM BST, Philip McGrath wrote:
Toggle quote (8 lines)
> > 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

-- (
-----BEGIN PGP SIGNATURE-----

iQGzBAABCgAdFiEE6Vh10NblKE5doNlW7ImHg/nqI20FAmQzGMMACgkQ7ImHg/nq
I23uLwv/VOu1QciGvXiSykavq7Lo3K7lZ5o+dxhzPLpPeOqlhA9ybQkLRVJ26TQe
JS4wQLUv7Fc+b1XUKDnQ0VR1MtQ51T4Tkl4RHlbINJof89nOtrtrTvkFtEUeF3Jk
A+aiFbH0L7hAsQ+KPkiE0C77Tv79WQ5Ig/I/xexi96DD+my5rnyNfwk9M2hRjqti
jnwmWhrV1PtHI+9thdlDtrByrrvg80kNzW14eSWIhKRBWcE4dtOTsxNI8UYWKK4v
X82rAz2Qp/rARVH3IiRZKe+mh9IJ+vRhkKVtYoquEoMprWy+dGTof8J2lWihEmiS
7QPx08y3oZHlYllq99y61SFfg1nka+V/NZ3qCqL5+HITv9lgUZM+tO7E2EtJvnVE
2v/e/5k/DJE5eI0lHQO3Qu+VUGVBm7b0ND1nrEiW/l+maB1P/eDSH8qfLhRM2dCy
WfFapUkkBtlZSvxcWarkgoqXVK9iwf92rkf2pGyCheFlyeMCtC2R8qglSLrLi32m
Rzvg3Az6
=OMIV
-----END PGP SIGNATURE-----


(
(address . 61982@debbugs.gnu.org)
CRSHRE5JL5CQ.Q3NXT9GFJAPM@guix-framework
On Sun Apr 9, 2023 at 8:57 PM BST, ( via Guix-patches via wrote:
Toggle quote (2 lines)
> 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.

-- (
-----BEGIN PGP SIGNATURE-----

iQGzBAABCgAdFiEE6Vh10NblKE5doNlW7ImHg/nqI20FAmQzGa0ACgkQ7ImHg/nq
I23ZOgv/Q4ZsSBdNMntoOF/rrzfQoq9qtlbLLvsAAdCIqMw14PNr+omSuvr2mmtK
kcMXe9UCYCLEjgdLbRDaGr44w72lOeakYFyoonVwT9z7+SqAiGknh0o/ajrsk91R
LrZBCJf+BUc+NMRqZSqSZ3J6X+IDJH4opcklnK9RbFg10cvvbqgqXo08jFdllgvD
80utEH31j6LeEnsC0Xbw0u6k2vTR4fORfLeeKiUMscl8fxhmXlkPqWfct5Xf3AF2
6VkPtAPt+9oShYggZslTmSIf/DXbgi4H2KAGiShfBG7lZrY+KFNG4/GUZuI+PE9G
eKCO1P1POJ7NtiKoRsWywnlvsdv19gDMGCbScDefXMDUNJFQ8NxJ9tGXM15d10Lr
qsDcd2SGext9vi8rT3cnc5aDyiI1nDdtK/wOS4iRjMBu8uxhd11w4Sldzej5jhhC
W1mngixGlor9cJYBUcIA08Kpxh9QeT6Hn6+r4sZ3thcoW7xIP7kcKolS5aB7KrRa
0A4vIEkB
=yf4j
-----END PGP SIGNATURE-----


(
(name . ()(address . paren@disroot.org)
878rexgsli.fsf@disroot.org
"( via Guix-patches" via <guix-patches@gnu.org> writes:
Toggle quote (2 lines)
> 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...
A
A
Andrew Tropin wrote on 12 Apr 2023 19:17
87o7ntkojm.fsf@trop.in
On 2023-04-11 21:01, paren@disroot.org wrote:

Toggle quote (6 lines)
> "( via Guix-patches" via <guix-patches@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 :)

Toggle quote (3 lines)
> 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
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmQ2570ACgkQIgjSCVjB
3rBFYA//ZZDIzzV2/xiEZFD2zRwxx6EFC3ha8DD+7c21RGcZXJNXsOQ2l1S4ruPS
cZ4hHa3hw8aC+N3T3zdCdF+48tfVsjmZKzTECEpl208hnh12JGhLdAxhIMJCF0hP
mtyLrt1b5AnjFPbfXj44R3JrUzstdkLszUhYnucMVcV7m/IJp8Cm/i4PKKpvquWe
sl4bZW+DuZdkq7mT3Te4aPrXlupXXyYXnBI5Q2MN6jl/YABDI1J48VlcKlVPZsQt
d7MW20tLq8OI36wMeETuxHnB0qo1baPCWREuuISwRKDvnHtNYX1laFNc3qzNNavI
Agm9qU8fsquPLObpQuUepvY2RaCgb1L9BO/W2cqWJJoQ9NXN3U8a6ozjM4+P8GWq
xS0WZdkhw6jAHgSxotsMX+byg0BybZqrXKIVgPKXi569yuX7KDtRAqoEBwg1TuA8
AdFCCzX/EMe8EwCPhSTHYkuZbSfp3A78dBpqquClJ0kMhCAosvYuyN3E1kjD5J1D
JVq0J5CSaOiGAoxWJreeJ65Iaz+53KbrXMYjgctTAHLvD2D1nkLmq7i7L3DOxW5O
1/2eEW2s7HCtM5BUgUuaeqR94vGJ6PLOsbiTy5864tw68MsDzrHkrbkknwRZ1IIz
CMWE4GtxUqthYrWnNX1yCjonTs5OlXeBL7PGcO1deSfTbciGEC8=
=WQn+
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 9 Jun 2023 23:01
Re: bug#61982: [PATCH 0/2] Respect XDG Base Directory Specification 0.8.
(name . Andrew Tropin)(address . andrew@trop.in)
87y1kstknk.fsf_-_@gnu.org
Hi Andrew,

Andrew Tropin <andrew@trop.in> skribis:

Toggle quote (5 lines)
> 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’.
A
A
Andrew Tropin wrote on 14 Jun 2023 11:27
(name . Ludovic Courtès)(address . ludo@gnu.org)
87r0qegzre.fsf@trop.in
On 2023-06-09 23:01, Ludovic Courtès wrote:

Toggle quote (11 lines)
> Hi Andrew,
>
> Andrew Tropin <andrew@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
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmSJh/UACgkQIgjSCVjB
3rAVeA/+I4PTw519Du0wUgFMVD/MlEcB2GRUuk/Zd+Ob/6WF6KeGhIvsIaBAh4UU
81C4r0HtIFh927MhNmmVDutoVxEQtYaP9QEXma1lyVtzyUTb/Va+MgDx9VwNXQs1
Aie+OHMe+fv+fkiV6aKVnRk80PVB/do07iBMM7LyJHL12sX1UEVeb/HTI835pZjU
lm4IqzVLSFT8kKRsPWoHxYwvwoWcb6U1lULoCssYwZiYOlDdQevRlIgbXFv5ncBn
hDGw7nToRHC8pdurClg7GlWZRmnTNiYID6dIvbwMwBobD97qxrFzxdNnB3klaSo1
Xr7i4+ZthQbgUwafkgGu8pPNdWuoHpWUkhX8V6scD++pK2TIQrI+FuciXVHDwwEy
rLNTIZNga32iE/QJarZUIF+l6gjghgwJDBRc+poKu7XLOQMhUhK6tF1QHPpoRV+4
62Aj8FBWWi/Y32LmonRpT9PHrMb3Dvg3XTOxcW854T3cbuEgnXGLI5XfvpqhC9oa
qgcqxPWHEzQrv8Z3sUhqlNXuBBKhZ853gvc21pHB0qwa66STFO6EBZUmP1A7K14i
+1/p6wNYT8IpqI7vcE6qZPz7kfdj2VSS6m6aEy0FSgf3S2OCD33IGMSK/kPcZgau
6PIvnQp4eCaWIq8Wv0lEMSHnxm3RC9TribxDFfbKGhcq6oLeMuk=
=cJsf
-----END PGP SIGNATURE-----

A
A
Andrew Tropin wrote on 15 Jun 2023 11:35
Re: [bug#61982] [PATCH 2/2] home: services: xdg-base-directories: Deprecate XDG_LOG_HOME.
87a5x1rrtv.fsf@trop.in
On 2023-03-05 15:19, Bruno Victal wrote:

Toggle quote (185 lines)
> 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@trop.in>
> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
> +;;; Copyright © 2023 Bruno Victal <mirai@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:
Toggle snippet (9 lines)
(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"))

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmSK21wACgkQIgjSCVjB
3rB5nQ/+J6ifXaoQOhVxAsGTboPD1vr0SYfc+HXrgfQ0U1DXPXv4nETTuKlzhoU+
YocTjfCPX4Sq4Cqoi88jg5InBBN1jI0XokVOSMj9J64jecIYBNsPBcLmU2T+sn5M
rfAgTJ63DJLT2EL+Ahc8HXATkL9fcgSQiGeAdWFO8/6Q15X6ifZpdvUTBE7HNDge
AkjzrHOOcYQgpg88RQiGmZ6it3lXg8KLs2z/Y0gGJ7RsdS/yjKYO5ZDJGlkRg8bv
8zmNOxiGFUd17UtOZUI5HvdKdjoEEb9Lz+0sKQncblDrmagChZbn7HvznwCIWOpD
Vli4y+7Wdqb3B0QVvoeJWYUTDY96sX9yOKlar+TFguKpsYJ8yRQOYzmIHiwCZ+uw
bbAkPFblEkUx6ot30kJSpzKN/anngng5u9MMtgByHUym8FjzUMruGaTK4aRSIx+D
wS3OYccSOuLZD93kkeu/pIu7ZYIJ7dSJy/6kX8GelzqUmJwDxGHRzdcjqdd5Xepq
4TCH34xs3Sg5OlxpTBPeHTVmd4t/NwxYR97dztWD5jblGHA9Zn2tNqJpCnc5Dqf2
ab4FtWWv4X21r/Y9MG9wn5mnJ2xgXeHsmX3/WP1I9OnAqFeumsXvLZoGS82APLGD
mZNW7cHhetEm2Nsq7Ef6DyGlOifkBCf5gYXNOUzKXIcOckFRr3s=
=d6+V
-----END PGP SIGNATURE-----

Closed
P
P
Philip McGrath wrote on 15 Jun 2023 20:09
a88fc559-d8bd-4d70-9599-ee42a7a9565b@app.fastmail.com
Hi,

On Thu, Jun 15, 2023, at 5:35 AM, Andrew Tropin wrote:
Toggle quote (16 lines)
>
> 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
A
A
Andrew Tropin wrote on 16 Jun 2023 05:28
877cs4rspr.fsf@trop.in
On 2023-06-15 14:09, Philip McGrath wrote:

Toggle quote (23 lines)
> 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.

Toggle quote (13 lines)
>
> 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
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmSL1uAACgkQIgjSCVjB
3rBUwg//bJXnPFi5qqcYfmK3CicM/6SD3qLZKHzoLk3lTEjBX2sUJPNsBzfNI50r
walBdw/DXdMtHv5S019GQKmFfmt8hs8H6v1qv9pV7spDAw8kxZzx1doG94wxKmuL
ZStm2ehjQSnlk1aUoRy6/0TC1VvUtKok6gJMmPFfwPovIGU72L3B+XcG5kT3WYfm
9/2hmTdCycw66oCGbdr0Tb3yh6AqcVqFolchVRC3pBxyFyYjgFIHGTri+rTKQQRF
LzDI5UpDrF4hqTiHVSc+GXIFd8DYwphSQSe8O8MHOQUA7mlKkVxyQ7PUyU3O5/VS
XNNtfKGlMYietNx011iG0jwesJ0rFrwaWPSCOQjoV9747dveKYpuEJZHfFJQ0dk7
qIRXKZIPXRpXm/P8y897MxKNYagfpQf8aY2FSc9F5M6KhybHJEKT9+sxxkj08JIb
0UQ7kq1WP+D/CoI5XwuUq3WGHtLEZoF0PW8/2JTW/UMeSWRAJTLk8ZEZPFkczOnz
9c2lJhCNTY7OFkKAxxByMJcLGh1K1c267l1SMJbWVeRSR1LGZQfnG4lL3hS6KsX5
ni//1uGPDX4iYKKoocBrdEevjkZP3B/45sSM5b02qut+GufhemMSgu7JnSzP+hDA
c/Ye6x5NEECt71O7dL936cVxzG6vgDhWaG2+CEIamH58U6mXs+I=
=NXhi
-----END PGP SIGNATURE-----

P
P
Philip McGrath wrote on 17 Jun 2023 20:22
4f059a7c-8ab8-4957-be1d-afc882a80739@app.fastmail.com
Hi,

On Thu, Jun 15, 2023, at 11:28 PM, Andrew Tropin wrote:
Toggle quote (32 lines)
> 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:

Toggle quote (18 lines)
>
> 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.


Toggle quote (17 lines)
>>
>> 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
?
Your comment

This issue is archived.

To comment on this conversation send an email to 61982@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 61982
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch