home: services: xdg-base-directories: Deprecate XDG_LOG_HOME.

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/desktop.scm (home-unclutter-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.

Co-authored-by: Andrew Tropin <andrew@trop.in>
Signed-off-by: Andrew Tropin <andrew@trop.in>
This commit is contained in:
Bruno Victal 2023-03-05 15:19:14 +00:00 committed by Andrew Tropin
parent 48cdc47d8c
commit f74df2ab87
No known key found for this signature in database
GPG key ID: 2208D20958C1DEB0
5 changed files with 46 additions and 27 deletions

View file

@ -214,9 +214,9 @@ according to time of day.")))
(cons "DBUS_VERBOSE=1" (cons "DBUS_VERBOSE=1"
(default-environment-variables)) (default-environment-variables))
#:log-file #:log-file
(format #f "~a/dbus.log" (format #f "~a/log/dbus.log"
(or (getenv "XDG_LOG_HOME") (or (getenv "XDG_STATE_HOME")
(format #f "~a/.local/var/log" (format #f "~a/.local/state"
(getenv "HOME")))))) (getenv "HOME"))))))
(stop #~(make-kill-destructor))))) (stop #~(make-kill-destructor)))))
@ -264,10 +264,10 @@ according to time of day.")))
(number->string (number->string
#$(home-unclutter-configuration-idle-timeout config))) #$(home-unclutter-configuration-idle-timeout config)))
#:log-file (string-append #:log-file (string-append
(or (getenv "XDG_LOG_HOME") (or (getenv "XDG_STATE_HOME")
(format #f "~a/.local/var/log" (format #f "~a/.local/state"
(getenv "HOME"))) (getenv "HOME")))
"/unclutter.log")))))) "/log/unclutter.log"))))))
(define home-unclutter-service-type (define home-unclutter-service-type
(service-type (service-type

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Andrew Tropin <andrew@trop.in> ;;; Copyright © 2021, 2023 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; ;;;
@ -99,10 +99,10 @@ Each message is also prefixed by a timestamp by GNU Shepherd."))
#~()) #~())
#$@files) #$@files)
#:log-file (string-append #:log-file (string-append
(or (getenv "XDG_LOG_HOME") (or (getenv "XDG_STATE_HOME")
(format #f "~a/.local/var/log" (format #f "~a/.local/state"
(getenv "HOME"))) (getenv "HOME")))
"/mcron.log"))) "/log/mcron.log")))
(stop #~(make-kill-destructor)) (stop #~(make-kill-destructor))
(actions (actions
(list (shepherd-schedule-action mcron files))))))))) (list (shepherd-schedule-action mcron files)))))))))

View file

@ -128,10 +128,10 @@
(list "-i") (list "-i")
(list))) (list)))
#:log-file (string-append #:log-file (string-append
(or (getenv "XDG_LOG_HOME") (or (getenv "XDG_STATE_HOME")
(format #f "~a/.local/var/log" (format #f "~a/.local/state"
(getenv "HOME"))) (getenv "HOME")))
"/batsignal.log"))) "/log/batsignal.log")))
(stop #~(make-kill-destructor)))))) (stop #~(make-kill-destructor))))))
(define home-batsignal-service-type (define home-batsignal-service-type

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Andrew Tropin <andrew@trop.in> ;;; Copyright © 2021, 2023 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
@ -108,9 +108,10 @@ as shepherd package."
(or (getenv "XDG_RUNTIME_DIR") (or (getenv "XDG_RUNTIME_DIR")
(format #f "/run/user/~a" (getuid))) (format #f "/run/user/~a" (getuid)))
"/shepherd/socket")) "/shepherd/socket"))
(let ((log-dir (or (getenv "XDG_LOG_HOME") (let* ((state-dir (or (getenv "XDG_STATE_HOME")
(format #f "~a/.local/var/log" (format #f "~a/.local/state"
(getenv "HOME"))))) (getenv "HOME"))))
(log-dir (string-append state-dir "/log")))
;; TODO: Remove it, 0.9.2 creates it automatically? ;; TODO: Remove it, 0.9.2 creates it automatically?
((@ (guix build utils) mkdir-p) log-dir) ((@ (guix build utils) mkdir-p) log-dir)
(system* (system*

View file

@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021, 2022 Andrew Tropin <andrew@trop.in> ;;; Copyright © 2021, 2022 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -22,6 +23,7 @@
#:use-module (gnu home services) #:use-module (gnu home services)
#:use-module (gnu packages freedesktop) #:use-module (gnu packages freedesktop)
#:use-module (gnu home services utils) #:use-module (gnu home services utils)
#:use-module (guix deprecation)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix modules) #:use-module (guix modules)
#:use-module (guix records) #:use-module (guix records)
@ -39,7 +41,7 @@
home-xdg-base-directories-configuration-config-home home-xdg-base-directories-configuration-config-home
home-xdg-base-directories-configuration-data-home home-xdg-base-directories-configuration-data-home
home-xdg-base-directories-configuration-state-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-base-directories-configuration-runtime-dir
home-xdg-user-directories-service-type home-xdg-user-directories-service-type
@ -77,6 +79,7 @@
(define (serialize-path field-name val) "") (define (serialize-path field-name val) "")
(define path? string?) (define path? string?)
(define-maybe path)
(define-configuration home-xdg-base-directories-configuration (define-configuration home-xdg-base-directories-configuration
(cache-home (cache-home
@ -97,12 +100,17 @@ read-only shared data, analogus to @file{/usr/share}, but for user.")
(path "${XDG_RUNTIME_DIR:-/run/user/$UID}") (path "${XDG_RUNTIME_DIR:-/run/user/$UID}")
"Base directory for programs to store user-specific runtime files, "Base directory for programs to store user-specific runtime files,
like sockets.") like sockets.")
;; TODO: deprecated field, use $XDG_STATE_HOME(/log) instead.
(log-home (log-home
(path "$HOME/.local/var/log") maybe-path
"Base directory for programs to store log files, analogus to "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 @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 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 (state-home
(path "$HOME/.local/state") (path "$HOME/.local/state")
"Base directory for programs to store state data that should persist "Base directory for programs to store state data that should persist
@ -117,7 +125,13 @@ portable enough to the user to warrant storing them in
#f "XDG_~a" #f "XDG_~a"
(object->snake-case-string (configuration-field-name field) 'upper)) (object->snake-case-string (configuration-field-name field) 'upper))
((configuration-field-getter field) config))) ((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) (define (ensure-xdg-base-dirs-on-activation config)
(with-imported-modules '((guix build utils)) (with-imported-modules '((guix build utils))
@ -138,7 +152,14 @@ portable enough to the user to warrant storing them in
;; and will be provided by elogind or other service. ;; and will be provided by elogind or other service.
(and (not (string=? "XDG_RUNTIME_DIR" variable)) (and (not (string=? "XDG_RUNTIME_DIR" variable))
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) (define (last-extension-or-cfg config extensions)
"Picks configuration value from last provided extension. If there "Picks configuration value from last provided extension. If there
@ -157,10 +178,7 @@ are no extensions use configuration instead."
(default-value (home-xdg-base-directories-configuration)) (default-value (home-xdg-base-directories-configuration))
(compose identity) (compose identity)
(extend last-extension-or-cfg) (extend last-extension-or-cfg)
(description "Configure XDG base directories. This (description "Configure XDG base directories. The
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 services of this service-type is instantiated by default, to provide
non-default value, extend the service-type (using @code{simple-service} non-default value, extend the service-type (using @code{simple-service}
for example)."))) for example).")))