bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#63082: [PATCH v3 14/16] services: mpd: Provision a default cache dir


From: Maxim Cournoyer
Subject: bug#63082: [PATCH v3 14/16] services: mpd: Provision a default cache directory and set HOME.
Date: Fri, 5 May 2023 14:29:09 -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 | 63 +++++++++++++++++++++++++-----------------
 2 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 0981aa1568..04744498dd 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -33633,7 +33633,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 1e0a8b7f9e..e242f48ba0 100644
--- a/gnu/services/audio.scm
+++ b/gnu/services/audio.scm
@@ -461,7 +461,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
@@ -605,32 +606,42 @@ (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 '#$environment-variables
-               #: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
+                 ;; Set HOME so MPD can infer default paths, such as
+                 ;; for the database file.
+                 (cons (string-append "HOME=" home)
+                       '#$environment-variables)
+                 #: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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]