Subject: bug#63082: [PATCH v2 11/16] services: mpd: Warn when the MPD user is not in the "audio" group.

From: Maxim Cournoyer <[email-masked]>
Date: Sat, 29 Apr 2023 13:21:48 -0400

Relates to <https://issues.guix.gnu.org>.

* gnu/services/audio.scm (%mpd-user) [group]: Add comment.
(mpd-user-sanitizer): Warn if the MPD user is not in the audio group.
---
 gnu/services/audio.scm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm
index f470ca20e0..7040a63ecd 100644
--- a/gnu/services/audio.scm
+++ b/gnu/services/audio.scm
@@ -31,6 +31,7 @@ (define-module (gnu services audio)
   #:use-module (gnu services configuration)
   #:use-module (gnu services shepherd)
   #:use-module (gnu services admin)
+  #:use-module (gnu system accounts)
   #:use-module (gnu system shadow)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages mpd)
@@ -173,6 +174,8 @@ (define-maybe boolean (prefix mpd-))
 (define %mpd-user
   (user-account
    (name "mpd")
+   ;; Being in the audio group ensures that PulseAudio can access sound
+   ;; devices.
    (group "audio")
    (system? #t)
    (comment "Music Player Daemon (MPD) user")
@@ -209,10 +212,17 @@ (define (mpd-serialize-port field-name value)
 
 (define-maybe port (prefix mpd-))
 
-;;; Procedures for unsupported value types, to be removed.
-
+;;; Sanitizer procedures.
 (define (mpd-user-sanitizer value)
-  (cond ((user-account? value) value)
+  (cond ((user-account? value)
+         (match-record value <user-account>
+           (group supplementary-groups)
+           (unless (or (string=? "audio" group)
+                       (member "audio" supplementary-groups))
+             ;; Being in the "audio" group is necessary for access to the
+             ;; sound devices.
+             (warning (G_ "mpd user not member of \"audio\" group~%"))))
+         value)
         ((string? value)
          (warning (G_ "string value for 'user' is deprecated, use \
 user-account instead~%"))
-- 
2.39.2