From 878e0e1bb0d15809c6582436d53498f3e6385524 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 29 Oct 2019 15:07:25 +0100 Subject: gnu: mpd-service-type: Support configuration of outputs. * gnu/services/audio.scm (): New record type. ()[outputs]: New field. (mpd-output, mpd-output?, mpd-output->string): New procedures. (mpd-config->file): Use mpd-output->string. * doc/guix.texi (Audio Services): Document mpd-output fields. --- gnu/services/audio.scm | 85 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 17 deletions(-) (limited to 'gnu/services') diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index ebfe05abd0..471c5fd95f 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Peter Mikkelsen +;;; Copyright © 2019 Ricardo Wurmus ;;; ;;; This file is part of GNU Guix. ;;; @@ -23,7 +24,9 @@ #:use-module (gnu packages mpd) #:use-module (guix records) #:use-module (ice-9 match) - #:export (mpd-configuration + #:export (mpd-output + mpd-output? + mpd-configuration mpd-configuration? mpd-service-type)) @@ -33,6 +36,25 @@ ;;; ;;; Code: +(define-record-type* + mpd-output make-mpd-output + mpd-output? + (type mpd-output-type + (default "pulse")) + (name mpd-output-name + (default "MPD")) + (enabled? mpd-output-enabled? + (default #t)) + (tags? mpd-output-tags? + (default #t)) + (always-on? mpd-output-always-on? + (default #f)) + (mixer-type mpd-output-mixer-type + ;; valid: hardware, software, null, none + (default #f)) + (extra-options mpd-output-extra-options + (default '()))) + (define-record-type* mpd-configuration make-mpd-configuration mpd-configuration? @@ -51,27 +73,56 @@ (port mpd-configuration-port (default "6600")) (address mpd-configuration-address - (default "any"))) + (default "any")) + (outputs mpd-configuration-outputs + (default (list (mpd-output))))) + +(define (mpd-output->string output) + "Convert the OUTPUT of type to a configuration file snippet." + (let ((extra (string-join + (map (match-lambda + ((key . value) + (format #f " ~a \"~a\"" + (string-map + (lambda (c) (if (char=? c #\-) #\_ c)) + (symbol->string key)) + value))) + (mpd-output-extra-options output)) + "\n"))) + (format #f "\ +audio_output { + type \"~a\" + name \"~a\" +~:[ enabled \"no\"~%~;~]\ +~:[ tags \"no\"~%~;~]\ +~:[~; always_on \"yes\"~%~]\ +~@[ mixer_type \"~a\"~%~]\ +~a~%}~%" + (mpd-output-type output) + (mpd-output-name output) + (mpd-output-enabled? output) + (mpd-output-tags? output) + (mpd-output-always-on? output) + (mpd-output-mixer-type output) + extra))) (define (mpd-config->file config) (apply mixed-text-file "mpd.conf" - "audio_output {\n" - " type \"pulse\"\n" - " name \"MPD\"\n" - "}\n" "pid_file \"" (mpd-file-name config "pid") "\"\n" - (map (match-lambda - ((config-name config-val) - (string-append config-name " \"" (config-val config) "\"\n"))) - `(("user" ,mpd-configuration-user) - ("music_directory" ,mpd-configuration-music-dir) - ("playlist_directory" ,mpd-configuration-playlist-dir) - ("db_file" ,mpd-configuration-db-file) - ("state_file" ,mpd-configuration-state-file) - ("sticker_file" ,mpd-configuration-sticker-file) - ("port" ,mpd-configuration-port) - ("bind_to_address" ,mpd-configuration-address))))) + (append (map mpd-output->string + (mpd-configuration-outputs config)) + (map (match-lambda + ((config-name config-val) + (string-append config-name " \"" (config-val config) "\"\n"))) + `(("user" ,mpd-configuration-user) + ("music_directory" ,mpd-configuration-music-dir) + ("playlist_directory" ,mpd-configuration-playlist-dir) + ("db_file" ,mpd-configuration-db-file) + ("state_file" ,mpd-configuration-state-file) + ("sticker_file" ,mpd-configuration-sticker-file) + ("port" ,mpd-configuration-port) + ("bind_to_address" ,mpd-configuration-address)))))) (define (mpd-file-name config file) "Return a path in /var/run/mpd/ that is writable -- cgit v1.2.3