mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
services: mpd: Use proper records for user and group fields.
Deprecate using strings for these fields and prefer user-account (resp. user-group) instead to avoid duplication within account-service-type. Fixes #61570 <https://issues.guix.gnu.org/61570>. * gnu/services/audio.scm (%mpd-user, %mpd-group) (mpd-serialize-user-account, mpd-serialize-user-group) (mpd-user-sanitizer, mpd-group-sanitizer): New variables. (mpd-configuration)[user]: Use user-account as value type. Sanitize via mpd-user-sanitizer. [group]: Use user-group as value type. Sanitize via mpd-group-sanitizer. (mpd-shepherd-service): Adjust accordingly. (mpd-accounts): Likewise. * doc/guix.texi (Audio Services)[Music Player Daemon]: Likewise. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
This commit is contained in:
parent
2c4df1a41a
commit
7fdadeac11
2 changed files with 86 additions and 30 deletions
|
@ -33494,14 +33494,17 @@ Data type representing the configuration of @command{mpd}.
|
||||||
@item @code{package} (default: @code{mpd}) (type: file-like)
|
@item @code{package} (default: @code{mpd}) (type: file-like)
|
||||||
The MPD package.
|
The MPD package.
|
||||||
|
|
||||||
@item @code{user} (default: @code{"mpd"}) (type: string)
|
@item @code{user} (default: @code{%mpd-user}) (type: user-account)
|
||||||
The user to run mpd as.
|
The user to run mpd as.
|
||||||
|
|
||||||
@item @code{group} (default: @code{"mpd"}) (type: string)
|
The default @code{%mpd-user} is a system user with the name ``mpd'',
|
||||||
|
who is a part of the group @var{group} (see below).
|
||||||
|
@item @code{group} (default: @code{%mpd-group}) (type: user-group)
|
||||||
The group to run mpd as.
|
The group to run mpd as.
|
||||||
|
|
||||||
|
The default @code{%mpd-group} is a system group with name ``mpd''.
|
||||||
@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbol)
|
@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbol)
|
||||||
This is a list of symbols naming Shepherd services that this service
|
A list of symbols naming Shepherd services that this service
|
||||||
will depend on.
|
will depend on.
|
||||||
|
|
||||||
@item @code{environment-variables} (default: @code{("PULSE_CLIENTCONFIG=/etc/pulse/client.conf" "PULSE_CONFIG=/etc/pulse/daemon.conf")}) (type: list-of-strings)
|
@item @code{environment-variables} (default: @code{("PULSE_CLIENTCONFIG=/etc/pulse/client.conf" "PULSE_CONFIG=/etc/pulse/daemon.conf")}) (type: list-of-strings)
|
||||||
|
|
|
@ -140,6 +140,14 @@ (define (uglify-field-name field-name)
|
||||||
(define list-of-symbol?
|
(define list-of-symbol?
|
||||||
(list-of symbol?))
|
(list-of symbol?))
|
||||||
|
|
||||||
|
;; Helpers for deprecated field types, to be removed later.
|
||||||
|
(define %lazy-group (make-symbol "%lazy-group"))
|
||||||
|
|
||||||
|
(define (%set-user-group user group)
|
||||||
|
(user-account
|
||||||
|
(inherit user)
|
||||||
|
(group (user-group-name group))))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; MPD
|
;;; MPD
|
||||||
|
@ -164,10 +172,31 @@ (define mpd-serialize-boolean mpd-serialize-field)
|
||||||
(define (mpd-serialize-list-of-strings field-name value)
|
(define (mpd-serialize-list-of-strings field-name value)
|
||||||
#~(string-append #$@(map (cut mpd-serialize-string field-name <>) value)))
|
#~(string-append #$@(map (cut mpd-serialize-string field-name <>) value)))
|
||||||
|
|
||||||
|
(define (mpd-serialize-user-account field-name value)
|
||||||
|
(mpd-serialize-string field-name (user-account-name value)))
|
||||||
|
|
||||||
|
(define (mpd-serialize-user-group field-name value)
|
||||||
|
(mpd-serialize-string field-name (user-group-name value)))
|
||||||
|
|
||||||
(define-maybe string (prefix mpd-))
|
(define-maybe string (prefix mpd-))
|
||||||
(define-maybe list-of-strings (prefix mpd-))
|
(define-maybe list-of-strings (prefix mpd-))
|
||||||
(define-maybe boolean (prefix mpd-))
|
(define-maybe boolean (prefix mpd-))
|
||||||
|
|
||||||
|
(define %mpd-user
|
||||||
|
(user-account
|
||||||
|
(name "mpd")
|
||||||
|
(group %lazy-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"))))
|
||||||
|
|
||||||
|
(define %mpd-group
|
||||||
|
(user-group
|
||||||
|
(name "mpd")
|
||||||
|
(system? #t)))
|
||||||
|
|
||||||
;;; TODO: Procedures for deprecated fields, to be removed.
|
;;; TODO: Procedures for deprecated fields, to be removed.
|
||||||
|
|
||||||
(define mpd-deprecated-fields '((music-dir . music-directory)
|
(define mpd-deprecated-fields '((music-dir . music-directory)
|
||||||
|
@ -197,6 +226,33 @@ (define (mpd-serialize-port field-name value)
|
||||||
|
|
||||||
(define-maybe port (prefix mpd-))
|
(define-maybe port (prefix mpd-))
|
||||||
|
|
||||||
|
;;; Procedures for unsupported value types, to be removed.
|
||||||
|
|
||||||
|
(define (mpd-user-sanitizer value)
|
||||||
|
(cond ((user-account? value) value)
|
||||||
|
((string? value)
|
||||||
|
(warning (G_ "string value for 'user' is deprecated, use \
|
||||||
|
user-account instead~%"))
|
||||||
|
(user-account
|
||||||
|
(inherit %mpd-user)
|
||||||
|
(name value)
|
||||||
|
;; XXX: This is to be lazily substituted in (…-accounts)
|
||||||
|
;; with the value from 'group'.
|
||||||
|
(group %lazy-group)))
|
||||||
|
(else
|
||||||
|
(configuration-field-error #f 'user value))))
|
||||||
|
|
||||||
|
(define (mpd-group-sanitizer value)
|
||||||
|
(cond ((user-group? value) value)
|
||||||
|
((string? value)
|
||||||
|
(warning (G_ "string value for 'group' is deprecated, use \
|
||||||
|
user-group instead~%"))
|
||||||
|
(user-group
|
||||||
|
(inherit %mpd-group)
|
||||||
|
(name value)))
|
||||||
|
(else
|
||||||
|
(configuration-field-error #f 'group value))))
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
;; Generic MPD plugin record, lists only the most prevalent fields.
|
;; Generic MPD plugin record, lists only the most prevalent fields.
|
||||||
|
@ -347,12 +403,14 @@ (define-configuration mpd-configuration
|
||||||
empty-serializer)
|
empty-serializer)
|
||||||
|
|
||||||
(user
|
(user
|
||||||
(string "mpd")
|
(user-account %mpd-user)
|
||||||
"The user to run mpd as.")
|
"The user to run mpd as."
|
||||||
|
(sanitizer mpd-user-sanitizer))
|
||||||
|
|
||||||
(group
|
(group
|
||||||
(string "mpd")
|
(user-group %mpd-group)
|
||||||
"The group to run mpd as.")
|
"The group to run mpd as."
|
||||||
|
(sanitizer mpd-group-sanitizer))
|
||||||
|
|
||||||
(shepherd-requirement
|
(shepherd-requirement
|
||||||
(list-of-symbol '())
|
(list-of-symbol '())
|
||||||
|
@ -517,7 +575,8 @@ (define (mpd-shepherd-service config)
|
||||||
log-file playlist-directory
|
log-file playlist-directory
|
||||||
db-file state-file sticker-file
|
db-file state-file sticker-file
|
||||||
environment-variables)
|
environment-variables)
|
||||||
(let* ((config-file (mpd-serialize-configuration config)))
|
(let ((config-file (mpd-serialize-configuration config))
|
||||||
|
(username (user-account-name user)))
|
||||||
(shepherd-service
|
(shepherd-service
|
||||||
(documentation "Run the MPD (Music Player Daemon)")
|
(documentation "Run the MPD (Music Player Daemon)")
|
||||||
(requirement `(user-processes loopback ,@shepherd-requirement))
|
(requirement `(user-processes loopback ,@shepherd-requirement))
|
||||||
|
@ -526,7 +585,7 @@ (define (mpd-shepherd-service config)
|
||||||
(and=> #$(maybe-value log-file)
|
(and=> #$(maybe-value log-file)
|
||||||
(compose mkdir-p dirname))
|
(compose mkdir-p dirname))
|
||||||
|
|
||||||
(let ((user (getpw #$user)))
|
(let ((user (getpw #$username)))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(when (and x (not (file-exists? x)))
|
(when (and x (not (file-exists? x)))
|
||||||
|
@ -560,17 +619,11 @@ (define (mpd-shepherd-service config)
|
||||||
|
|
||||||
(define (mpd-accounts config)
|
(define (mpd-accounts config)
|
||||||
(match-record config <mpd-configuration> (user group)
|
(match-record config <mpd-configuration> (user group)
|
||||||
(list (user-group
|
;; TODO: Deprecation code, to be removed.
|
||||||
(name group)
|
(let ((user (if (eq? (user-account-group user) %lazy-group)
|
||||||
(system? #t))
|
(%set-user-group user group)
|
||||||
(user-account
|
user)))
|
||||||
(name user)
|
(list user group))))
|
||||||
(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"))))))
|
|
||||||
|
|
||||||
(define mpd-service-type
|
(define mpd-service-type
|
||||||
(service-type
|
(service-type
|
||||||
|
|
Loading…
Reference in a new issue