[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#63082: [PATCH v2 14/16] services: mpd: Provision a default cache dir
From: |
Maxim Cournoyer |
Subject: |
bug#63082: [PATCH v2 14/16] services: mpd: Provision a default cache directory and set HOME. |
Date: |
Sat, 29 Apr 2023 13:21:51 -0400 |
Relates to <https://issues.guix.gnu.org/63082>.
* gnu/services/audio.scm (mpd-shepherd-service): Create a default .cache
directory. Use mkdir-p/perms and refactor loop. Set the HOME environment
variables.
---
doc/guix.texi | 3 +-
gnu/services/audio.scm | 68 ++++++++++++++++++++++++------------------
2 files changed, 41 insertions(+), 30 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 148ca88633..abfbbdb2fc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -33604,7 +33604,8 @@ Audio Services
The directory to store playlists.
@item @code{db-file} (type: maybe-string)
-The location of the music database.
+The location of the music database. When left unspecified,
+@file{~/.cache/db} is used.
@item @code{state-file} (type: maybe-string)
The location of the file that stores current MPD's state.
diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm
index dca2e8e5f6..0e90d72462 100644
--- a/gnu/services/audio.scm
+++ b/gnu/services/audio.scm
@@ -465,7 +465,8 @@ (define-configuration mpd-configuration
(db-file
maybe-string
- "The location of the music database.")
+ "The location of the music database. When left unspecified,
+@file{~/.cache/db} is used.")
(state-file
maybe-string
@@ -609,35 +610,44 @@ (define (mpd-shepherd-service config)
#~(begin
(use-modules (gnu build activation))
- (let ((user (getpw #$username)))
-
- (define (init-directory directory)
- (unless (file-exists? directory)
- (mkdir-p/perms directory user #o755)))
+ (let ((home #$(user-account-home-directory user)))
+ (let ((user (getpw #$username))
+ (default-cache-dir (string-append home "/.cache")))
+
+ (define (init-directory directory)
+ (unless (file-exists? directory)
+ (mkdir-p/perms directory user #o755)))
+
+ ;; Define a cache location that can be automatically used
+ ;; for the database file, in case it hasn't been explicitly
+ ;; specified.
+ (for-each
+ init-directory
+ (cons default-cache-dir
+ '#$(map dirname
+ ;; XXX: Delete the potential "syslog"
+ ;; log-file value, which is not a directory.
+ (delete "syslog"
+ (filter-map maybe-value
+ (list db-file
+ log-file
+ state-file
+ sticker-file)))))))
- (for-each
- init-directory
- '#$(map dirname
- ;; XXX: Delete the potential "syslog"
- ;; log-file value, which is not a directory.
- (delete "syslog"
- (filter-map maybe-value
- (list db-file
- log-file
- state-file
- sticker-file))))))
-
- (make-forkexec-constructor
- (list #$(file-append package "/bin/mpd") "--no-daemon"
- #$config-file)
- #:environment-variables
- ;; Use the system-configured pulse configuration.
- (list "PULSE_CLIENTCONFIG=/etc/pulse/client.conf"
- "PULSE_CONFIG=/etc/pulse/daemon.conf")
- #:user #$username
- #:group #$(user-account-group user)
- #:supplementary-groups
- '#$(user-account-supplementary-groups user)))))
+ (make-forkexec-constructor
+ (list #$(file-append package "/bin/mpd") "--no-daemon"
+ #$config-file)
+ #:environment-variables
+ ;; Use the system-configured pulse configuration. Set HOME
+ ;; so MPD can infer default paths, such as for the database
+ ;; file.
+ (list (string-append "HOME=" home)
+ "PULSE_CLIENTCONFIG=/etc/pulse/client.conf"
+ "PULSE_CONFIG=/etc/pulse/daemon.conf")
+ #:user #$username
+ #:group #$(user-account-group user)
+ #:supplementary-groups
+ '#$(user-account-supplementary-groups user))))))
(stop #~(make-kill-destructor))
(actions
(list (shepherd-configuration-action config-file)
--
2.39.2
- bug#63082: [PATCH v2 04/16] services: mpd: Obsolete the 'group' field., (continued)
- bug#63082: [PATCH v2 04/16] services: mpd: Obsolete the 'group' field., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 05/16] services: mpd: List log-level in decreasing verbosity order in doc., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 11/16] services: mpd: Warn when the MPD user is not in the "audio" group., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 08/16] services: mpd: Do not rotate logs when using syslog., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 07/16] services: mpd: Log to syslog by default., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 12/16] services: mpd: Auto-detect mpd-output mixer type by default., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 09/16] services: mpd: Let Shepherd effect the user/group change., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 10/16] system: accounts: Export <user-account>., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 13/16] services: mpd: Obsolete 'environment-variables' field., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 15/16] services: mpd: Update basic example., Maxim Cournoyer, 2023/04/29
- bug#63082: [PATCH v2 14/16] services: mpd: Provision a default cache directory and set HOME.,
Maxim Cournoyer <=
- bug#63082: [PATCH v2 16/16] services: Avoid 'delete' overrides warning in audio module., Maxim Cournoyer, 2023/04/29