me
/
guix
Archived
1
0
Fork 0

services: mympd: Use records for user and group fields.

* gnu/services/audio.scm (%mympd-user, %mympd-group)
(mympd-user-sanitizer, mympd-group-sanitizer): New variables.
(mympd-configuration)[user]: Use user-account as value type.
Sanitize via mympd-user-sanitizer.
[group]: Use user-group as value type.
Sanitize via mympd-group-sanitizer.
(mympd-serialize-configuration): Adjust accordingly.
(mympd-accounts): Likewise.
* doc/guix.texi (Audio Services)[myMPD]: Likewise.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
master
Bruno Victal 2023-03-26 19:41:33 +01:00 committed by Liliana Marie Prikler
parent 7fdadeac11
commit 380faf265b
No known key found for this signature in database
GPG Key ID: 442A84B8C70E2F87
2 changed files with 61 additions and 16 deletions

View File

@ -33738,12 +33738,15 @@ The package object of the myMPD server.
This is a list of symbols naming Shepherd services that this service This is a list of symbols naming Shepherd services that this service
will depend on. will depend on.
@item @code{user} (default: @code{"mympd"}) (type: string) @item @code{user} (default: @code{%mympd-user}) (type: user-account)
Owner of the @command{mympd} process. Owner of the @command{mympd} process.
@item @code{group} (default: @code{"nogroup"}) (type: string) The default @code{%mympd-user} is a system user with the name ``mympd'',
who is a part of the group @var{group} (see below).
@item @code{group} (default: @code{%mympd-group}) (type: user-group)
Owner group of the @command{mympd} process. Owner group of the @command{mympd} process.
The default @code{%mympd-group} is a system group with name ``mympd''.
@item @code{work-directory} (default: @code{"/var/lib/mympd"}) (type: string) @item @code{work-directory} (default: @code{"/var/lib/mympd"}) (type: string)
Where myMPD will store its data. Where myMPD will store its data.

View File

@ -658,6 +658,48 @@ appended to the configuration.")
(define-maybe/no-serialization integer) (define-maybe/no-serialization integer)
(define-maybe/no-serialization mympd-ip-acl) (define-maybe/no-serialization mympd-ip-acl)
(define %mympd-user
(user-account
(name "mympd")
(group %lazy-group)
(system? #t)
(comment "myMPD user")
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin"))))
(define %mympd-group
(user-group
(name "mympd")
(system? #t)))
;;; TODO: Procedures for unsupported value types, to be removed.
(define (mympd-user-sanitizer value)
(cond ((user-account? value) value)
((string? value)
(warning (G_ "string value for 'user' is not supported, use \
user-account instead~%"))
(user-account
(inherit %mympd-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 (mympd-group-sanitizer value)
(cond ((user-group? value) value)
((string? value)
(warning (G_ "string value for 'group' is not supported, use \
user-group instead~%"))
(user-group
(inherit %mympd-group)
(name value)))
(else
(configuration-field-error #f 'group value))))
;;;
;; XXX: The serialization procedures are insufficient since we require ;; XXX: The serialization procedures are insufficient since we require
;; access to multiple fields at once. ;; access to multiple fields at once.
;; Fields marked with empty-serializer are never serialized and are ;; Fields marked with empty-serializer are never serialized and are
@ -675,13 +717,15 @@ will depend on."
empty-serializer) empty-serializer)
(user (user
(string "mympd") (user-account %mympd-user)
"Owner of the @command{mympd} process." "Owner of the @command{mympd} process."
(sanitizer mympd-user-sanitizer)
empty-serializer) empty-serializer)
(group (group
(string "nogroup") (user-group %mympd-group)
"Owner group of the @command{mympd} process." "Owner group of the @command{mympd} process."
(sanitizer mympd-group-sanitizer)
empty-serializer) empty-serializer)
(work-directory (work-directory
@ -816,7 +860,8 @@ prompting a pin from the user.")
(match-record config <mympd-configuration> (package shepherd-requirement (match-record config <mympd-configuration> (package shepherd-requirement
user work-directory user work-directory
cache-directory log-level log-to) cache-directory log-level log-to)
(let ((log-level* (format #f "MYMPD_LOGLEVEL=~a" log-level))) (let ((log-level* (format #f "MYMPD_LOGLEVEL=~a" log-level))
(username (user-account-name user)))
(shepherd-service (shepherd-service
(documentation "Run the myMPD daemon.") (documentation "Run the myMPD daemon.")
(requirement `(loopback user-processes (requirement `(loopback user-processes
@ -826,7 +871,7 @@ prompting a pin from the user.")
,@shepherd-requirement)) ,@shepherd-requirement))
(provision '(mympd)) (provision '(mympd))
(start #~(begin (start #~(begin
(let* ((pw (getpwnam #$user)) (let* ((pw (getpwnam #$username))
(uid (passwd:uid pw)) (uid (passwd:uid pw))
(gid (passwd:gid pw))) (gid (passwd:gid pw)))
(for-each (lambda (dir) (for-each (lambda (dir)
@ -836,8 +881,8 @@ prompting a pin from the user.")
(make-forkexec-constructor (make-forkexec-constructor
`(#$(file-append package "/bin/mympd") `(#$(file-append package "/bin/mympd")
"--user" #$user "--user" #$username
#$@(if (eqv? log-to 'syslog) '("--syslog") '()) #$@(if (eq? log-to 'syslog) '("--syslog") '())
"--workdir" #$work-directory "--workdir" #$work-directory
"--cachedir" #$cache-directory) "--cachedir" #$cache-directory)
#:environment-variables (list #$log-level*) #:environment-variables (list #$log-level*)
@ -846,14 +891,11 @@ prompting a pin from the user.")
(define (mympd-accounts config) (define (mympd-accounts config)
(match-record config <mympd-configuration> (user group) (match-record config <mympd-configuration> (user group)
(list (user-group (name group) ;; TODO: Deprecation code, to be removed.
(system? #t)) (let ((user (if (eq? (user-account-group user) %lazy-group)
(user-account (name user) (%set-user-group user group)
(group group) user)))
(system? #t) (list user group))))
(comment "myMPD user")
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin"))))))
(define (mympd-log-rotation config) (define (mympd-log-rotation config)
(match-record config <mympd-configuration> (log-to) (match-record config <mympd-configuration> (log-to)