Subject: bug#61570: [PATCH] services: mpd: Use proper records.

From: Liliana Marie Prikler <[email-masked]>
Date: Sat, 18 Feb 2023 18:42:45 +0100

* gnu/services/audio.scm (mpd-user, mpd-group): New variables.
(mpd-serialize-user-account, mpd-serialize-user-group): New variables.
(mpd-configuration)[user]: Change type to user-account.
Change default accordingly.
[group]: Change type to user-group.  Change default accordingly.
(mpd-shepherd-service, mpd-accounts): Adjust accordingly.
* doc/guix.texi ("Music Player Daemon") Adjust accordingly.
---
This patch fixes the issue of not being able to insert actual users and
groups into MPD service.  Sadly, as define-configuration lacks proper
support for sanitizers, it's a backwards-incompatible change.
Perhaps it makes sense to extend define-configuration to support this
case?

Cheers

 doc/guix.texi          |  4 ++--
 gnu/services/audio.scm | 41 +++++++++++++++++++++++++++--------------
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 44e2165a82..fa75eff62e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -33181,10 +33181,10 @@ Data type representing the configuration of @command{mpd}.
 @item @code{package} (default: @code{mpd}) (type: file-like)
 The MPD package.
 
-@item @code{user} (default: @code{"mpd"}) (type: string)
+@item @code{user} (default: @code{(mpd-user "mpd")}) (type: user-account)
 The user to run mpd as.
 
-@item @code{group} (default: @code{"mpd"}) (type: string)
+@item @code{group} (default: @code{(mpd-group "mpd")}) (type: user-group)
 The group to run mpd as.
 
 @item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbol)
diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm
index d55b804ba9..df9b0ac7f1 100644
--- a/gnu/services/audio.scm
+++ b/gnu/services/audio.scm
@@ -62,6 +62,9 @@ (define-module (gnu services audio)
             mpd-partition-name
             mpd-partition-extra-options
 
+            mpd-user
+            mpd-group
+
             mpd-configuration
             mpd-configuration?
             mpd-configuration-package
@@ -328,6 +331,26 @@ (define list-of-mpd-plugin-or-output?
   (list-of (lambda (x)
              (or (mpd-output? x) (mpd-plugin? x)))))
 
+(define* (mpd-user #:optional (name "mpd") (group "mpd"))
+  (user-account
+   (name name)
+   (group group)
+   (system? #t)
+   (comment "Music Player Daemon (MPD) user")
+   (home-directory "/var/lib/mpd")
+   (shell (file-append shadow "/sbin/nologin"))))
+
+(define* (mpd-group #:optional (name "mpd"))
+  (user-group
+   (name name)
+   (system? #t)))
+
+(define (mpd-serialize-user-account field value)
+  (mpd-serialize-string field (user-account-name value)))
+
+(define (mpd-serialize-user-group field value)
+  (mpd-serialize-string field (user-group-name value)))
+
 (define-configuration mpd-configuration
   (package
    (file-like mpd)
@@ -335,11 +358,11 @@ (define-configuration mpd-configuration
    empty-serializer)
 
   (user
-   (string "mpd")
+   (user-account (mpd-user "mpd"))
    "The user to run mpd as.")
 
   (group
-   (string "mpd")
+   (user-group (mpd-group "mpd"))
    "The group to run mpd as.")
 
   (shepherd-requirement
@@ -512,7 +535,7 @@ (define (mpd-shepherd-service config)
                   (and=> #$(maybe-value log-file)
                          (compose mkdir-p dirname))
 
-                  (let ((user (getpw #$user)))
+                  (let ((user (getpw #$(user-account-name user))))
                     (for-each
                      (lambda (x)
                        (when (and x (not (file-exists? x)))
@@ -546,17 +569,7 @@ (define (mpd-shepherd-service config)
 
 (define (mpd-accounts config)
   (match-record config <mpd-configuration> (user group)
-    (list (user-group
-           (name group)
-           (system? #t))
-          (user-account
-           (name user)
-           (group group)
-           (system? #t)
-           (comment "Music Player Daemon (MPD) user")
-           ;; MPD can use $HOME (or $XDG_CONFIG_HOME) to place its data
-           (home-directory "/var/lib/mpd")
-           (shell (file-append shadow "/sbin/nologin"))))))
+    (list user group)))
 
 (define mpd-service-type
   (service-type

base-commit: 312f1f41d3f3f3e5d2c36ff46920c6dce1c21a17
-- 
2.39.1