From unknown Fri Jun 20 07:09:35 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#28059 <28059@debbugs.gnu.org> To: bug#28059 <28059@debbugs.gnu.org> Subject: Status: [PATCH] gnu: Add mpd service. Reply-To: bug#28059 <28059@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:09:35 +0000 retitle 28059 [PATCH] gnu: Add mpd service. reassign 28059 guix-patches submitter 28059 Peter Mikkelsen severity 28059 normal tag 28059 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 11 21:52:46 2017 Received: (at submit) by debbugs.gnu.org; 12 Aug 2017 01:52:46 +0000 Received: from localhost ([127.0.0.1]:56165 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgLbZ-0003gU-MA for submit@debbugs.gnu.org; Fri, 11 Aug 2017 21:52:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgLbU-0003gD-4S for submit@debbugs.gnu.org; Fri, 11 Aug 2017 21:52:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dgLbM-0006h2-GX for submit@debbugs.gnu.org; Fri, 11 Aug 2017 21:52:34 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:57065) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dgLbM-0006gt-Dh for submit@debbugs.gnu.org; Fri, 11 Aug 2017 21:52:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgLbK-0007es-3V for guix-patches@gnu.org; Fri, 11 Aug 2017 21:52:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dgLbG-0006fd-5x for guix-patches@gnu.org; Fri, 11 Aug 2017 21:52:30 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:34389) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dgLbF-0006fM-RG for guix-patches@gnu.org; Fri, 11 Aug 2017 21:52:26 -0400 Received: by mail-wr0-x233.google.com with SMTP id c24so18596353wra.1 for ; Fri, 11 Aug 2017 18:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ro9mdA7uwfszWXfG8VW3rr0QzRuDGJkoAPsnkvxaNMA=; b=DMMHKXCjB+RjxQZZXtRYsS+pg5egsVfRJG4kqOTd+dqxwwsPQ472Mcpg6r8cYuXAIt fP7J9ci+XhvPHqoPBu9ESrxR2/xdNa/GR99WvUHILlZXffbKSFSO5i+iXhzHD/IUtTG3 AXtpHLn9pMBpHZi13sB2PExVFDhD4H0UK+bD7y7rIRINVqNHZ8MlP2shsr48SiL4ATtA R2MZldO7GJUhMtZC8SNrR6ZPN8OTyWtUbU9KyoOS3Lmmxdef0jSsOifxwx30zILsz7eY 82nwPakw9jAgmqn7j5H3/AEDhPpe5kwqUonGLIUEITbuRV0x3bs2hMbJHpsUPr5lEsae RPgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ro9mdA7uwfszWXfG8VW3rr0QzRuDGJkoAPsnkvxaNMA=; b=jyH4FL8f87F9O3458aIyaD6hIoI/g/o5gw9dI5VZEkpG2PC0ugZ4rDBkgAkPuiGNmR ypzUKBg8cUJsRR6iTamjJltrzVYSBWAWgbQw0fDgoI03R7KIJhawhjvLbZget/FMgxBX q40NKHdkvPjLELMtHGqDMY8ejcjdprAUyYXr+k6mp1kjXiGeito3Vldo8AaEhSsdTgJ5 uL9SDMwzxofM86D1UjWvcT8duVT4ZlGjP8T0mlJzQvU37zzfKIfWQl8pXpHzkGFx65na Bgi4SBT+UgE02QQwijCKoNcl1YiC8vZD58mQ+qSAT51+SGRF2ZsBTcGIDYPERQirCd6e hZtw== X-Gm-Message-State: AHYfb5jA2Lhf9LXWsRBniX3/YzRqiRhGxAV/CAsg2oq77fh5E19DK5dn aOtiUmx6lka9+wImYiPX5A== X-Received: by 10.223.166.173 with SMTP id t42mr12232283wrc.272.1502502742791; Fri, 11 Aug 2017 18:52:22 -0700 (PDT) Received: from guixsd.bbsyd.net (D470980C.rev.sefiber.dk. [212.112.152.12]) by smtp.gmail.com with ESMTPSA id v44sm4302429wrb.53.2017.08.11.18.52.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Aug 2017 18:52:19 -0700 (PDT) From: Peter Mikkelsen To: guix-patches@gnu.org Subject: [PATCH] gnu: Add mpd service. Date: Sat, 12 Aug 2017 03:52:11 +0200 Message-Id: <20170812015211.5411-1-petermikkelsen10@gmail.com> X-Mailer: git-send-email 2.14.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit Cc: Peter Mikkelsen X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) * doc/guix.text: Add documentation. * gnu/services/music.scm (): New record type. (mpd-service): New service extension. (mpd-service-type): New service type. * gnu/tests/music.scm: New file. * gnu/local.mk: Add new files. --- doc/guix.texi | 53 +++++++++++++++++++++++++++++++ gnu/local.mk | 2 ++ gnu/services/music.scm | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ gnu/tests/music.scm | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 gnu/services/music.scm create mode 100644 gnu/tests/music.scm diff --git a/doc/guix.texi b/doc/guix.texi index 8f14ddd50..e565dfdc9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -227,6 +227,7 @@ Services * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. * Power management Services:: The TLP tool. +* Music Services:: The MPD. * Miscellaneous Services:: Other services. Defining Services @@ -9035,6 +9036,7 @@ declaration. * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. * Power management Services:: The TLP tool. +* Music Services:: The MPD. * Miscellaneous Services:: Other services. @end menu @@ -15635,6 +15637,57 @@ Package object of thermald. @end table @end deftp +@node Music Services +@subsubsection Music Services + +@cindex mpd +@subsubheading Music Player Daemon + +The @code{(gnu services music)} provides a service to start MPD (the Music +Player Daemon). It uses pulseaudio for output. + +@defvr {Scheme Variable} mpd-service-type +The service type for @command{mpd} +@end defvr + +@deftp {Data Type} mpd-configuration +Data type representing the configuration of @command{mpd}. + +@table @asis +@item @code{user} (default: @code{"mpd"}) +The user to run mpd as. + +@item @code{music-dir} (default: @code{"~/Music"}) +The directory to scan for music files. + +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) +The directory to store playlists. + +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) +The file mpd wil store its PID. + +@item @code{port} (default: @code{"6600"}) +The port to run mpd on. + +@item @code{address} (default: @code{"any"}) +The address that mpd will bind to. To use a Unix domain socket, +an absolute path can be specified here. + +@end table +@end deftp + +@deffn {Scheme Procedure} mpd-service [#:config (mpd-configuration)] +Return a service that runs @code{mpd} using @var{configuration}, +a @code{} object. + +The following example shows how one might run @code{mpd} as user +@code{"bob"} on port @code{6666}. +@example +(mpd-service (mpd-configuration + (user "bob") + (port "6666"))) +@end example +@end deffn @node Miscellaneous Services @subsubsection Miscellaneous Services diff --git a/gnu/local.mk b/gnu/local.mk index b1ff72d6a..cad0ba38d 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES = \ %D%/services/mail.scm \ %D%/services/mcron.scm \ %D%/services/messaging.scm \ + %D%/services/music.scm \ %D%/services/networking.scm \ %D%/services/nfs.scm \ %D%/services/shepherd.scm \ @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES = \ %D%/tests/install.scm \ %D%/tests/mail.scm \ %D%/tests/messaging.scm \ + %D%/tests/music.scm \ %D%/tests/networking.scm \ %D%/tests/ssh.scm \ %D%/tests/web.scm diff --git a/gnu/services/music.scm b/gnu/services/music.scm new file mode 100644 index 000000000..77912d5c6 --- /dev/null +++ b/gnu/services/music.scm @@ -0,0 +1,84 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2017 Peter Mikkelsen +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services music) + #:use-module (guix gexp) + #:use-module (gnu services) + #:use-module (gnu services shepherd) + #:use-module (gnu packages mpd) + #:use-module (guix records) + #:export (mpd-configuration + mpd-configuration? + mpd-service + mpd-service-type)) + +;;; Commentary: +;;; +;;; Music related services +;;; +;;; Code: + +(define-record-type* + mpd-configuration make-mpd-configuration + mpd-configuration? + (user mpd-configuration-user + (default "mpd")) + (music-dir mpd-configuration-music-dir + (default "~/Music")) + (playlist-dir mpd-configuration-playlist-dir + (default "~/.mpd/playlists")) + (port mpd-configuration-port + (default "6600")) + (address mpd-configuration-address + (default "any")) + (pid-file mpd-configuration-pid-file + (default "~/.mpd-pid"))) + +(define (mpd-config->file config) + (apply + mixed-text-file "mpd.conf" + "audio_output {\n" + " type \"pulse\"\n" + " name \"MPD\"\n" + "}\n" + (map (lambda (config-line) + (let ((config-name (car config-line)) + (config-val (cadr config-line))) + (string-append config-name " \"" (config-val config) "\"\n"))) + `(("user" ,mpd-configuration-user) + ("music_directory" ,mpd-configuration-music-dir) + ("playlist_directory" ,mpd-configuration-playlist-dir) + ("port" ,mpd-configuration-port) + ("bind_to_address" ,mpd-configuration-address) + ("pid_file" ,mpd-configuration-pid-file))))) + +(define mpd-service-type + (shepherd-service-type + 'mpd + (lambda (config) + (shepherd-service + (documentation "Run the MPD (Music Player Daemon)") + (provision '(mpd)) + (start #~(make-forkexec-constructor + (list #$(file-append mpd "/bin/mpd") + "--no-daemon" + #$(mpd-config->file config)))) + (stop #~(make-kill-destructor)))))) + +(define* (mpd-service #:optional (config (mpd-configuration))) + (service mpd-service-type config)) diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm new file mode 100644 index 000000000..158513098 --- /dev/null +++ b/gnu/tests/music.scm @@ -0,0 +1,83 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2017 Peter Mikkelsen +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu tests music) + #:use-module (gnu tests) + #:use-module (gnu system) + #:use-module (gnu system vm) + #:use-module (gnu services) + #:use-module (gnu services music) + #:use-module (gnu packages mpd) + #:use-module (guix gexp) + #:export (%test-mpd)) + +(define %mpd-os + (simple-operating-system + (mpd-service (mpd-configuration + (user "root"))))) + +(define (run-mpd-test) + "Run tests in %mpd-os, which has mpd running." + (define os + (marionette-operating-system + %mpd-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine os)) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-64) + (gnu build marionette)) + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "mpd") + + (test-eq "service is running" + 'running! + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'mpd) + 'running!) + marionette)) + + (test-assert "pid file" + (wait-for-file "/root/.mpd-pid" + marionette)) + + (test-assert "mpc connect" + (marionette-eval + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) + marionette)) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + (gexp->derivation "mpd-test" test)) + +(define %test-mpd + (system-test + (name "mpd") + (description "Test that the mpd can run and be connected to.") + (value (run-mpd-test)))) -- 2.14.0 From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 12 06:50:26 2017 Received: (at 28059) by debbugs.gnu.org; 12 Aug 2017 10:50:26 +0000 Received: from localhost ([127.0.0.1]:56299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgTzs-0003Xh-K5 for submit@debbugs.gnu.org; Sat, 12 Aug 2017 06:50:26 -0400 Received: from li622-129.members.linode.com ([212.71.249.129]:51918 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgTzm-0003Xb-Vj for 28059@debbugs.gnu.org; Sat, 12 Aug 2017 06:50:22 -0400 Received: by mira.cbaines.net (Postfix, from userid 113) id 16DB913D1DA; Sat, 12 Aug 2017 11:50:18 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (17.71.125.91.dyn.plus.net [91.125.71.17]) by mira.cbaines.net (Postfix) with ESMTPSA id 5056013D1D5; Sat, 12 Aug 2017 11:50:17 +0100 (BST) Date: Sat, 12 Aug 2017 11:50:11 +0100 From: Christopher Baines To: Peter Mikkelsen Subject: Re: [bug#28059] [PATCH] gnu: Add mpd service. Message-ID: <20170812115011.4c076108@cbaines.net> In-Reply-To: <20170812015211.5411-1-petermikkelsen10@gmail.com> References: <20170812015211.5411-1-petermikkelsen10@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/afMO+hGIgha25Hk2KS4XiSW"; protocol="application/pgp-signature" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28059 Cc: 28059@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --Sig_/afMO+hGIgha25Hk2KS4XiSW Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hey, This looks great Peter, awesome job :) I've made some notes about potential improvements inline below. I've succeeded in running the system test locally, but there was some suspicious output in the log: exception: bind to '0.0.0.0:6600' failed (continuing anyway, because binding to '[::]:6600' succeeded): Failed to bind socket: Address already in use exception: Failed to access /root/.mpd/playlists: No such file or directory On Sat, 12 Aug 2017 03:52:11 +0200 Peter Mikkelsen wrote: > * doc/guix.text: Add documentation. Typo above, text rather than texi. > * gnu/services/music.scm (): New record type. > (mpd-service): New service extension. > (mpd-service-type): New service type. > * gnu/tests/music.scm: New file. > * gnu/local.mk: Add new files. >=20 > --- > doc/guix.texi | 53 +++++++++++++++++++++++++++++++ > gnu/local.mk | 2 ++ > gnu/services/music.scm | 84 > ++++++++++++++++++++++++++++++++++++++++++++++++++ > gnu/tests/music.scm | 83 > +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, > 222 insertions(+) create mode 100644 gnu/services/music.scm create > mode 100644 gnu/tests/music.scm >=20 > diff --git a/doc/guix.texi b/doc/guix.texi > index 8f14ddd50..e565dfdc9 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -227,6 +227,7 @@ Services > * Network File System:: NFS related services. > * Continuous Integration:: The Cuirass service. > * Power management Services:: The TLP tool. > +* Music Services:: The MPD. > * Miscellaneous Services:: Other services. > =20 > Defining Services > @@ -9035,6 +9036,7 @@ declaration. > * Network File System:: NFS related services. > * Continuous Integration:: The Cuirass service. > * Power management Services:: The TLP tool. > +* Music Services:: The MPD. > * Miscellaneous Services:: Other services. > @end menu > =20 > @@ -15635,6 +15637,57 @@ Package object of thermald. > @end table > @end deftp > =20 > +@node Music Services > +@subsubsection Music Services I'm wondering if Audio services, rather than Music services might be better? Maybe this would fit in other services related to audio, e.g. Jack, MIDI stuff, etc... > +@cindex mpd > +@subsubheading Music Player Daemon > + > +The @code{(gnu services music)} provides a service to start MPD (the > Music +Player Daemon). It uses pulseaudio for output. > + > +@defvr {Scheme Variable} mpd-service-type > +The service type for @command{mpd} > +@end defvr > + > +@deftp {Data Type} mpd-configuration > +Data type representing the configuration of @command{mpd}. > + > +@table @asis > +@item @code{user} (default: @code{"mpd"}) > +The user to run mpd as. > + > +@item @code{music-dir} (default: @code{"~/Music"}) > +The directory to scan for music files. > + > +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) > +The directory to store playlists. > + > +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) > +The file mpd wil store its PID. > + > +@item @code{port} (default: @code{"6600"}) > +The port to run mpd on. > + > +@item @code{address} (default: @code{"any"}) > +The address that mpd will bind to. To use a Unix domain socket, > +an absolute path can be specified here. The style for Guix is to use two spaces between sentences, I always forget about this too. > + > +@end table > +@end deftp > + > +@deffn {Scheme Procedure} mpd-service [#:config (mpd-configuration)] > +Return a service that runs @code{mpd} using @var{configuration}, > +a @code{} object. > + > +The following example shows how one might run @code{mpd} as user > +@code{"bob"} on port @code{6666}. > +@example > +(mpd-service (mpd-configuration > + (user "bob") > + (port "6666"))) > +@end example > +@end deffn > =20 > @node Miscellaneous Services > @subsubsection Miscellaneous Services > diff --git a/gnu/local.mk b/gnu/local.mk > index b1ff72d6a..cad0ba38d 100644 > --- a/gnu/local.mk > +++ b/gnu/local.mk > @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES > =3D \ > %D%/services/mail.scm \ > %D%/services/mcron.scm \ > %D%/services/messaging.scm \ > + %D%/services/music.scm \ > %D%/services/networking.scm \ > %D%/services/nfs.scm \ > %D%/services/shepherd.scm \ > @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES > =3D \ > %D%/tests/install.scm \ > %D%/tests/mail.scm \ > %D%/tests/messaging.scm \ > + %D%/tests/music.scm \ > %D%/tests/networking.scm \ > %D%/tests/ssh.scm \ > %D%/tests/web.scm > diff --git a/gnu/services/music.scm b/gnu/services/music.scm > new file mode 100644 > index 000000000..77912d5c6 > --- /dev/null > +++ b/gnu/services/music.scm > @@ -0,0 +1,84 @@ > +;;; GNU Guix --- Functional package management for GNU > +;;; Copyright =C2=A9 2017 Peter Mikkelsen > +;;; > +;;; This file is part of GNU Guix. > +;;; > +;;; GNU Guix is free software; you can redistribute it and/or modify > it +;;; under the terms of the GNU General Public License as > published by +;;; the Free Software Foundation; either version 3 of > the License, or (at +;;; your option) any later version. > +;;; > +;;; GNU Guix is distributed in the hope that it will be useful, but > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +;;; GNU General Public License for more details. > +;;; > +;;; You should have received a copy of the GNU General Public License > +;;; along with GNU Guix. If not, see . > + > +(define-module (gnu services music) > + #:use-module (guix gexp) > + #:use-module (gnu services) > + #:use-module (gnu services shepherd) > + #:use-module (gnu packages mpd) > + #:use-module (guix records) > + #:export (mpd-configuration > + mpd-configuration? > + mpd-service > + mpd-service-type)) > + > +;;; Commentary: > +;;; > +;;; Music related services > +;;; > +;;; Code: > + > +(define-record-type* > + mpd-configuration make-mpd-configuration > + mpd-configuration? > + (user mpd-configuration-user > + (default "mpd")) > + (music-dir mpd-configuration-music-dir > + (default "~/Music")) > + (playlist-dir mpd-configuration-playlist-dir > + (default "~/.mpd/playlists")) > + (port mpd-configuration-port > + (default "6600")) > + (address mpd-configuration-address > + (default "any")) > + (pid-file mpd-configuration-pid-file > + (default "~/.mpd-pid"))) > + > +(define (mpd-config->file config) > + (apply > + mixed-text-file "mpd.conf" > + "audio_output {\n" > + " type \"pulse\"\n" > + " name \"MPD\"\n" > + "}\n" > + (map (lambda (config-line) > + (let ((config-name (car config-line)) > + (config-val (cadr config-line))) > + (string-append config-name " \"" (config-val config) > "\"\n"))) > + `(("user" ,mpd-configuration-user) > + ("music_directory" ,mpd-configuration-music-dir) > + ("playlist_directory" ,mpd-configuration-playlist-dir) > + ("port" ,mpd-configuration-port) > + ("bind_to_address" ,mpd-configuration-address) > + ("pid_file" ,mpd-configuration-pid-file))))) > + > +(define mpd-service-type > + (shepherd-service-type > + 'mpd > + (lambda (config) > + (shepherd-service > + (documentation "Run the MPD (Music Player Daemon)") > + (provision '(mpd)) > + (start #~(make-forkexec-constructor > + (list #$(file-append mpd "/bin/mpd") > + "--no-daemon" > + #$(mpd-config->file config)))) > + (stop #~(make-kill-destructor)))))) > + > +(define* (mpd-service #:optional (config (mpd-configuration))) > + (service mpd-service-type config)) I've been trying a slightly different style for this recently. At the moment, if you had a configuration file for MPD, you couldn't use this with the service here. One way of addressing this is to do something like the Tailon service, and define a gexp compiler for the configuration file (e.g. [1]). For the Tailon service, this means that you should be able to pass your own configuration file to the service. Also, now that a can have a default-value, I think its easier to just have the mpd-service-type, without the mpd-service procedure. If you add a default value, you should be able to do (service mpd-service-type). 1: https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/admin.scm#n255 > diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm > new file mode 100644 > index 000000000..158513098 > --- /dev/null > +++ b/gnu/tests/music.scm > @@ -0,0 +1,83 @@ > +;;; GNU Guix --- Functional package management for GNU > +;;; Copyright =C2=A9 2017 Peter Mikkelsen > +;;; > +;;; This file is part of GNU Guix. > +;;; > +;;; GNU Guix is free software; you can redistribute it and/or modify > it +;;; under the terms of the GNU General Public License as > published by +;;; the Free Software Foundation; either version 3 of > the License, or (at +;;; your option) any later version. > +;;; > +;;; GNU Guix is distributed in the hope that it will be useful, but > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +;;; GNU General Public License for more details. > +;;; > +;;; You should have received a copy of the GNU General Public License > +;;; along with GNU Guix. If not, see . > + > +(define-module (gnu tests music) > + #:use-module (gnu tests) > + #:use-module (gnu system) > + #:use-module (gnu system vm) > + #:use-module (gnu services) > + #:use-module (gnu services music) > + #:use-module (gnu packages mpd) > + #:use-module (guix gexp) > + #:export (%test-mpd)) > + > +(define %mpd-os > + (simple-operating-system > + (mpd-service (mpd-configuration > + (user "root"))))) > + > +(define (run-mpd-test) > + "Run tests in %mpd-os, which has mpd running." > + (define os > + (marionette-operating-system > + %mpd-os > + #:imported-modules '((gnu services herd)))) > + > + (define vm > + (virtual-machine os)) > + > + (define test > + (with-imported-modules '((gnu build marionette)) > + #~(begin > + (use-modules (srfi srfi-64) > + (gnu build marionette)) > + (define marionette > + (make-marionette (list #$vm))) > + > + (mkdir #$output) > + (chdir #$output) > + > + (test-begin "mpd") > + > + (test-eq "service is running" > + 'running! > + (marionette-eval > + '(begin > + (use-modules (gnu services herd)) > + (start-service 'mpd) > + 'running!) > + marionette)) Recently, the start-service procedure was changed to return the information from the shepherd, and this can be used to make this check a bit more rigorous. I've got an patch for the Memcached service which demonstrates this here [2], as with the test above, it will not always fail, even if the service fails to create the PID file. 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28021 > + (test-assert "pid file" > + (wait-for-file "/root/.mpd-pid" > + marionette)) If this is useful when using MPD, then I think it would be valuable to get the shepherd to wait for the PID file. I think you can do this by adding #:pid-file to the make-forkexec-constructor call. If you do this, them I'm not sure this test adds anything, as I think the start-service call would only return successfully when the service has started, and created the PID file. > + (test-assert "mpc connect" > + (marionette-eval > + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) > + marionette)) > + > + (test-end) > + (exit (=3D (test-runner-fail-count (test-runner-current)) > 0))))) > + (gexp->derivation "mpd-test" test)) > + > +(define %test-mpd > + (system-test > + (name "mpd") > + (description "Test that the mpd can run and be connected to.") > + (value (run-mpd-test)))) --Sig_/afMO+hGIgha25Hk2KS4XiSW Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmO3WNfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE 9XccJA//d0rxgDfJa2ZQMaebLVS7ypfGadwibnx3ksTWi+xS1OO2ZkybQc/cWaFW HRlSTWvvVue9yjNqdXu4tMBa2XTR43PGmXrZjVi10zJBlZL988n7Abj5Y0jp7c+y f7kc5KHGOEH/CbTNqcKaxxX774z2ADh5lHIXARyLwnnw6nutQqWRWucgD3rvt9wX eGM7Q3YGZdMjojFXspqxocfi67n1PF5FyrqGWPwVFsu9quX+hhBUVL0v9eA58IV2 xrJLNGfLh2EmZqfneWKymFI0Bd0G7dFxJDfr3xzRX5n/IzQfyLc6pCgYJud/ZgLe JRGOzg2LA8/HZZknFOP4kGcCu+z9ykcxcY3IpkFQIqYUroHJD7I/SwLBAoulpDbK tK0wbdQx3edhhtTja6YH35bZzz3EM2Q2BGcKFtIni3Qnrsp65ZDHXazaBv5q+fOS 88g6WHUB3pjXVhCmsvmCKcO9MbuNRA6DTE88LyKqZi7o4g+XbpSLNMw0sBQNCPNQ 4xdg+9tzghoR9kqE8CgHCM1KXjMiEgUvqqhqB+BxZZ2FRtpR6ZRm4+fQ8uTMbPaj YPLZJZeqByHlvgQGM+bHyE4Bzj1n3cesLxO6HVhAKql4YHqfArXzyc3MkAb8lnmw jUp0xxNBlz+LagtQrTX7+CBQ8phCvVhrb1Izxw3B4bCT4Y/8MII= =ojeq -----END PGP SIGNATURE----- --Sig_/afMO+hGIgha25Hk2KS4XiSW-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 12 06:57:01 2017 Received: (at 28059) by debbugs.gnu.org; 12 Aug 2017 10:57:01 +0000 Received: from localhost ([127.0.0.1]:56303 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgU6B-0003aG-2O for submit@debbugs.gnu.org; Sat, 12 Aug 2017 06:57:00 -0400 Received: from aibo.runbox.com ([91.220.196.211]:46374) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgU65-0003a8-Da for 28059@debbugs.gnu.org; Sat, 12 Aug 2017 06:56:53 -0400 Received: from [10.9.9.210] (helo=mailfront10.runbox.com) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1dgU62-0000DO-VB; Sat, 12 Aug 2017 12:56:47 +0200 Received: from sunfire-cape.gate.wayne-enterprises.company ([79.134.234.247] helo=localhost) by mailfront10.runbox.com with esmtpsa (uid:892961 ) (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) id 1dgU5w-0001fE-5Q; Sat, 12 Aug 2017 12:56:40 +0200 Date: Sat, 12 Aug 2017 10:56:37 +0000 From: ng0 To: Christopher Baines Subject: Re: [bug#28059] [PATCH] gnu: Add mpd service. Message-ID: <20170812105637.xzh5ri245i7oxoqb@abyayala> Mail-Followup-To: Christopher Baines , Peter Mikkelsen , 28059@debbugs.gnu.org References: <20170812015211.5411-1-petermikkelsen10@gmail.com> <20170812115011.4c076108@cbaines.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hl5ldumazpjt3qfi" Content-Disposition: inline In-Reply-To: <20170812115011.4c076108@cbaines.net> X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 28059 Cc: 28059@debbugs.gnu.org, Peter Mikkelsen X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --hl5ldumazpjt3qfi Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Christopher Baines transcribed 13K bytes: > Hey, >=20 > This looks great Peter, awesome job :) I've made some notes about > potential improvements inline below. >=20 > I've succeeded in running the system test locally, but there was some > suspicious output in the log: >=20 > exception: bind to '0.0.0.0:6600' failed (continuing anyway, because > binding to '[::]:6600' succeeded): Failed to bind socket: Address > already in use exception: Failed to access /root/.mpd/playlists: No > such file or directory Isn't this normal for MPD? I haven't used any system service for it in a very long time and starting mpd as a user process always gives me a message like this. >=20 > On Sat, 12 Aug 2017 03:52:11 +0200 > Peter Mikkelsen wrote: > > * doc/guix.text: Add documentation. >=20 > Typo above, text rather than texi. >=20 > > * gnu/services/music.scm (): New record type. > > (mpd-service): New service extension. > > (mpd-service-type): New service type. > > * gnu/tests/music.scm: New file. > > * gnu/local.mk: Add new files. > >=20 > > --- > > doc/guix.texi | 53 +++++++++++++++++++++++++++++++ > > gnu/local.mk | 2 ++ > > gnu/services/music.scm | 84 > > ++++++++++++++++++++++++++++++++++++++++++++++++++ > > gnu/tests/music.scm | 83 > > +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, > > 222 insertions(+) create mode 100644 gnu/services/music.scm create > > mode 100644 gnu/tests/music.scm > >=20 > > diff --git a/doc/guix.texi b/doc/guix.texi > > index 8f14ddd50..e565dfdc9 100644 > > --- a/doc/guix.texi > > +++ b/doc/guix.texi > > @@ -227,6 +227,7 @@ Services > > * Network File System:: NFS related services. > > * Continuous Integration:: The Cuirass service. > > * Power management Services:: The TLP tool. > > +* Music Services:: The MPD. > > * Miscellaneous Services:: Other services. > > =20 > > Defining Services > > @@ -9035,6 +9036,7 @@ declaration. > > * Network File System:: NFS related services. > > * Continuous Integration:: The Cuirass service. > > * Power management Services:: The TLP tool. > > +* Music Services:: The MPD. > > * Miscellaneous Services:: Other services. > > @end menu > > =20 > > @@ -15635,6 +15637,57 @@ Package object of thermald. > > @end table > > @end deftp > > =20 > > +@node Music Services > > +@subsubsection Music Services >=20 > I'm wondering if Audio services, rather than Music services might be > better? Maybe this would fit in other services related to audio, e.g. > Jack, MIDI stuff, etc... >=20 > > +@cindex mpd > > +@subsubheading Music Player Daemon > > + > > +The @code{(gnu services music)} provides a service to start MPD (the > > Music +Player Daemon). It uses pulseaudio for output. > > + > > +@defvr {Scheme Variable} mpd-service-type > > +The service type for @command{mpd} > > +@end defvr > > + > > +@deftp {Data Type} mpd-configuration > > +Data type representing the configuration of @command{mpd}. > > + > > +@table @asis > > +@item @code{user} (default: @code{"mpd"}) > > +The user to run mpd as. > > + > > +@item @code{music-dir} (default: @code{"~/Music"}) > > +The directory to scan for music files. > > + > > +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) > > +The directory to store playlists. > > + > > +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) > > +The file mpd wil store its PID. > > + > > +@item @code{port} (default: @code{"6600"}) > > +The port to run mpd on. > > + > > +@item @code{address} (default: @code{"any"}) > > +The address that mpd will bind to. To use a Unix domain socket, > > +an absolute path can be specified here. >=20 > The style for Guix is to use two spaces between sentences, I always > forget about this too. >=20 > > + > > +@end table > > +@end deftp > > + > > +@deffn {Scheme Procedure} mpd-service [#:config (mpd-configuration)] > > +Return a service that runs @code{mpd} using @var{configuration}, > > +a @code{} object. > > + > > +The following example shows how one might run @code{mpd} as user > > +@code{"bob"} on port @code{6666}. > > +@example > > +(mpd-service (mpd-configuration > > + (user "bob") > > + (port "6666"))) > > +@end example > > +@end deffn > > =20 > > @node Miscellaneous Services > > @subsubsection Miscellaneous Services > > diff --git a/gnu/local.mk b/gnu/local.mk > > index b1ff72d6a..cad0ba38d 100644 > > --- a/gnu/local.mk > > +++ b/gnu/local.mk > > @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES > > =3D \ > > %D%/services/mail.scm \ > > %D%/services/mcron.scm \ > > %D%/services/messaging.scm \ > > + %D%/services/music.scm \ > > %D%/services/networking.scm \ > > %D%/services/nfs.scm \ > > %D%/services/shepherd.scm \ > > @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES > > =3D \ > > %D%/tests/install.scm \ > > %D%/tests/mail.scm \ > > %D%/tests/messaging.scm \ > > + %D%/tests/music.scm \ > > %D%/tests/networking.scm \ > > %D%/tests/ssh.scm \ > > %D%/tests/web.scm > > diff --git a/gnu/services/music.scm b/gnu/services/music.scm > > new file mode 100644 > > index 000000000..77912d5c6 > > --- /dev/null > > +++ b/gnu/services/music.scm > > @@ -0,0 +1,84 @@ > > +;;; GNU Guix --- Functional package management for GNU > > +;;; Copyright =C2=A9 2017 Peter Mikkelsen > > +;;; > > +;;; This file is part of GNU Guix. > > +;;; > > +;;; GNU Guix is free software; you can redistribute it and/or modify > > it +;;; under the terms of the GNU General Public License as > > published by +;;; the Free Software Foundation; either version 3 of > > the License, or (at +;;; your option) any later version. > > +;;; > > +;;; GNU Guix is distributed in the hope that it will be useful, but > > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > +;;; GNU General Public License for more details. > > +;;; > > +;;; You should have received a copy of the GNU General Public License > > +;;; along with GNU Guix. If not, see . > > + > > +(define-module (gnu services music) > > + #:use-module (guix gexp) > > + #:use-module (gnu services) > > + #:use-module (gnu services shepherd) > > + #:use-module (gnu packages mpd) > > + #:use-module (guix records) > > + #:export (mpd-configuration > > + mpd-configuration? > > + mpd-service > > + mpd-service-type)) > > + > > +;;; Commentary: > > +;;; > > +;;; Music related services > > +;;; > > +;;; Code: > > + > > +(define-record-type* > > + mpd-configuration make-mpd-configuration > > + mpd-configuration? > > + (user mpd-configuration-user > > + (default "mpd")) > > + (music-dir mpd-configuration-music-dir > > + (default "~/Music")) > > + (playlist-dir mpd-configuration-playlist-dir > > + (default "~/.mpd/playlists")) > > + (port mpd-configuration-port > > + (default "6600")) > > + (address mpd-configuration-address > > + (default "any")) > > + (pid-file mpd-configuration-pid-file > > + (default "~/.mpd-pid"))) > > + > > +(define (mpd-config->file config) > > + (apply > > + mixed-text-file "mpd.conf" > > + "audio_output {\n" > > + " type \"pulse\"\n" > > + " name \"MPD\"\n" > > + "}\n" > > + (map (lambda (config-line) > > + (let ((config-name (car config-line)) > > + (config-val (cadr config-line))) > > + (string-append config-name " \"" (config-val config) > > "\"\n"))) > > + `(("user" ,mpd-configuration-user) > > + ("music_directory" ,mpd-configuration-music-dir) > > + ("playlist_directory" ,mpd-configuration-playlist-dir) > > + ("port" ,mpd-configuration-port) > > + ("bind_to_address" ,mpd-configuration-address) > > + ("pid_file" ,mpd-configuration-pid-file))))) > > + > > +(define mpd-service-type > > + (shepherd-service-type > > + 'mpd > > + (lambda (config) > > + (shepherd-service > > + (documentation "Run the MPD (Music Player Daemon)") > > + (provision '(mpd)) > > + (start #~(make-forkexec-constructor > > + (list #$(file-append mpd "/bin/mpd") > > + "--no-daemon" > > + #$(mpd-config->file config)))) > > + (stop #~(make-kill-destructor)))))) > > + > > +(define* (mpd-service #:optional (config (mpd-configuration))) > > + (service mpd-service-type config)) >=20 > I've been trying a slightly different style for this recently. At the > moment, if you had a configuration file for MPD, you couldn't use this > with the service here. One way of addressing this is to do something > like the Tailon service, and define a gexp compiler for the > configuration file (e.g. [1]). For the Tailon service, this means that > you should be able to pass your own configuration file to the service. >=20 > Also, now that a can have a default-value, I think its > easier to just have the mpd-service-type, without the mpd-service > procedure. If you add a default value, you should be able to do > (service mpd-service-type). >=20 > 1: > https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/admin.scm#n2= 55 >=20 > > diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm > > new file mode 100644 > > index 000000000..158513098 > > --- /dev/null > > +++ b/gnu/tests/music.scm > > @@ -0,0 +1,83 @@ > > +;;; GNU Guix --- Functional package management for GNU > > +;;; Copyright =C2=A9 2017 Peter Mikkelsen > > +;;; > > +;;; This file is part of GNU Guix. > > +;;; > > +;;; GNU Guix is free software; you can redistribute it and/or modify > > it +;;; under the terms of the GNU General Public License as > > published by +;;; the Free Software Foundation; either version 3 of > > the License, or (at +;;; your option) any later version. > > +;;; > > +;;; GNU Guix is distributed in the hope that it will be useful, but > > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > +;;; GNU General Public License for more details. > > +;;; > > +;;; You should have received a copy of the GNU General Public License > > +;;; along with GNU Guix. If not, see . > > + > > +(define-module (gnu tests music) > > + #:use-module (gnu tests) > > + #:use-module (gnu system) > > + #:use-module (gnu system vm) > > + #:use-module (gnu services) > > + #:use-module (gnu services music) > > + #:use-module (gnu packages mpd) > > + #:use-module (guix gexp) > > + #:export (%test-mpd)) > > + > > +(define %mpd-os > > + (simple-operating-system > > + (mpd-service (mpd-configuration > > + (user "root"))))) > > + > > +(define (run-mpd-test) > > + "Run tests in %mpd-os, which has mpd running." > > + (define os > > + (marionette-operating-system > > + %mpd-os > > + #:imported-modules '((gnu services herd)))) > > + > > + (define vm > > + (virtual-machine os)) > > + > > + (define test > > + (with-imported-modules '((gnu build marionette)) > > + #~(begin > > + (use-modules (srfi srfi-64) > > + (gnu build marionette)) > > + (define marionette > > + (make-marionette (list #$vm))) > > + > > + (mkdir #$output) > > + (chdir #$output) > > + > > + (test-begin "mpd") > > + > > + (test-eq "service is running" > > + 'running! > > + (marionette-eval > > + '(begin > > + (use-modules (gnu services herd)) > > + (start-service 'mpd) > > + 'running!) > > + marionette)) >=20 > Recently, the start-service procedure was changed to return the > information from the shepherd, and this can be used to make this check > a bit more rigorous. >=20 > I've got an patch for the Memcached service which demonstrates this > here [2], as with the test above, it will not always fail, even if the > service fails to create the PID file. >=20 > 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28021 >=20 > > + (test-assert "pid file" > > + (wait-for-file "/root/.mpd-pid" > > + marionette)) >=20 > If this is useful when using MPD, then I think it would be valuable to > get the shepherd to wait for the PID file. I think you can do this by > adding #:pid-file to the make-forkexec-constructor call. >=20 > If you do this, them I'm not sure this test adds anything, as I think > the start-service call would only return successfully when the service > has started, and created the PID file. >=20 > > + (test-assert "mpc connect" > > + (marionette-eval > > + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) > > + marionette)) > > + > > + (test-end) > > + (exit (=3D (test-runner-fail-count (test-runner-current)) > > 0))))) > > + (gexp->derivation "mpd-test" test)) > > + > > +(define %test-mpd > > + (system-test > > + (name "mpd") > > + (description "Test that the mpd can run and be connected to.") > > + (value (run-mpd-test)))) --=20 ng0 GnuPG: A88C8ADD129828D7EAC02E52E22F9BBFEE348588 GnuPG: https://n0is.noblogs.org/my-keys https://www.infotropique.org https://krosos.org --hl5ldumazpjt3qfi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEqIyK3RKYKNfqwC5S4i+bv+40hYgFAlmO3uUACgkQ4i+bv+40 hYhsbg//a68v+UmHV5a+f7yePp9lK00rNZ2Vg/TDcibMd9PyHPTMCL4Z+iAvtklQ EbRzpo/7MnvWygfYfvoZ1HmrsT4eTb1zvSj9KBU9vV4Ur2BSNT2U/zifiYxrKmGd YZVPgDFIcxYPp6zNHyIPtbeCBUT9Gx5uE9vpH6HIl+vGPB+6svQ50CqNNByW+4Ko xxplJG6xcqMPpJCJrC5+i245IdqPw2gaI3E7ffXADKJk/h9ygYroTALIwkD0EQ5W dyvNL0W8eLp2RIZEh97nSDaxF9FAssXgCxNofuXwcLLzEufgD15dvSfQh+uITec2 62epvnSNuCA4OAnjgblqGAUuyY3FGTYIQALmXgWLtrNGwBPku5DwQKZxtIslHSNe WvYcKtwe6qeJDjYqeLysqyBkZgf7QU3172rGe8WP2saUD7XQ6dK/4l9yrRDg2pqf WkqbnrtYeuy1IO1+ZHdakvyjaDmCouGjI/WB0BT5zkKKvVygJeSLAmh/6FDVxg+C BLhMiE6VJ6pIQnycMT6HVUL4mjw+noWghHPItMaBEZ5FHhfSJQppySsBN29CRGwo VjloikhURYqNHVSOftmxjyrFg2oFzH3qujGuK69UEpqE93I+p39Ua2uDzgj1NVC7 OW/KsjdhtLPl7TNWAErkVKKSfw+39ebk34xa1fzw5lNGqSqjc0U= =Gott -----END PGP SIGNATURE----- --hl5ldumazpjt3qfi-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 12 13:10:21 2017 Received: (at 28059) by debbugs.gnu.org; 12 Aug 2017 17:10:21 +0000 Received: from localhost ([127.0.0.1]:57238 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgZvY-0003a1-VM for submit@debbugs.gnu.org; Sat, 12 Aug 2017 13:10:21 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:35537) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgZvV-0003Zv-0a for 28059@debbugs.gnu.org; Sat, 12 Aug 2017 13:10:19 -0400 Received: by mail-wm0-f43.google.com with SMTP id m85so11845518wma.0 for <28059@debbugs.gnu.org>; Sat, 12 Aug 2017 10:10:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=UJ3qc+G0Z4ienBkZALFlI367ccsHbt3gGEYxPEfks0s=; b=amYpTTan6Tq+8WI2eZLzC+pV6LYYyB+9z5l/6la56fOlzlXgbWfP4tDujLTfW5EzpW pFFa1VyXBU1j3UkT6D6ptttajJGgh3FK3VqyQYr+j4QuOD7lzJbHDCNHQu3zXy2n8kTi T4WIwu0Bjs9xvpwBTTS+QUyxKKcRGrhZ7XySWgdHRpc4quxgOAIsXI7vOh1iKolVsMhx hxJK4FceuwzWTqAqoHRE5C2y8IXrf3OHxtNa0KPRA2gOSnt51BDgMNDBL7FIWQz4YzBR n3QxYi+ZUmmiJg0TAuRpULYlouZloWeAgQDkG1zz8sVAZkGLRid0SCARS5K6LSabNMT0 bvww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=UJ3qc+G0Z4ienBkZALFlI367ccsHbt3gGEYxPEfks0s=; b=firKhrWa3YQ+YE67o7+qVefQgqzd8UnJPpOxGQ7LjYJymZk+oN9Ijb4hQ5n4Uztzop g5izSc0hoWdHVhIQ/YBDwGYAOWHAYNgZMy71Qr1rgCax+budOzd93RjmktIhRpFqol3r XaXa9/ryV5Gisg9fPqKqJPWQKv7ImEgm+Kyb8l6ZpL6s1Bh0RRujrMS6cK2SwuKibotu wqwZQSB5zKe9JOG2aNnM2SlLS1isa3SAZo04hWKXQqYNvhQBVwfK0yBUcg7EqyFskkkS i1ktSJ45PyA8qituSHjotOhGJGqLAOgLaBZxhOqubMtr2zr2anE9twWGMR+s7hgUky/x ybYg== X-Gm-Message-State: AHYfb5jNPSJgW/I++/mVqGXokxo/axng8L80JyMXECdrJsLW0Ym6l8HH Z8PjSfhbgo9cfoLydbg= X-Received: by 10.80.220.5 with SMTP id q5mr19864006edk.223.1502557810863; Sat, 12 Aug 2017 10:10:10 -0700 (PDT) Received: from guixsd (D4709868.rev.sefiber.dk. [212.112.152.104]) by smtp.gmail.com with ESMTPSA id g44sm2371251edc.27.2017.08.12.10.10.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 12 Aug 2017 10:10:09 -0700 (PDT) From: Peter Mikkelsen To: Christopher Baines Subject: Re: [bug#28059] [PATCH] gnu: Add mpd service. References: <20170812015211.5411-1-petermikkelsen10@gmail.com> <20170812115011.4c076108@cbaines.net> Date: Sat, 12 Aug 2017 19:10:08 +0200 In-Reply-To: <20170812115011.4c076108@cbaines.net> (Christopher Baines's message of "Sat, 12 Aug 2017 11:50:11 +0100") Message-ID: <87a834u2z3.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.2 (/) X-Debbugs-Envelope-To: 28059 Cc: 28059@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, thanks for the quick review! Christopher Baines writes: > Hey, > > This looks great Peter, awesome job :) I've made some notes about > potential improvements inline below. > > I've succeeded in running the system test locally, but there was some > suspicious output in the log: > > exception: bind to '0.0.0.0:6600' failed (continuing anyway, because > binding to '[::]:6600' succeeded): Failed to bind socket: Address > already in use exception: Failed to access /root/.mpd/playlists: No > such file or directory > This is pretty normal for mpd, and I believe happens because it first binds on IPv6 and then fails for IPv4. The error about the playlist dir happens because it does not exist, but AFAIK it is no problem unless you want to save playlists. The user can just create the dir. > > On Sat, 12 Aug 2017 03:52:11 +0200 > Peter Mikkelsen wrote: >> * doc/guix.text: Add documentation. > > Typo above, text rather than texi. > Ups, my mistake. >> * gnu/services/music.scm (): New record type. >> (mpd-service): New service extension. >> (mpd-service-type): New service type. >> * gnu/tests/music.scm: New file. >> * gnu/local.mk: Add new files. >> >> --- >> doc/guix.texi | 53 +++++++++++++++++++++++++++++++ >> gnu/local.mk | 2 ++ >> gnu/services/music.scm | 84 >> ++++++++++++++++++++++++++++++++++++++++++++++++++ >> gnu/tests/music.scm | 83 >> +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, >> 222 insertions(+) create mode 100644 gnu/services/music.scm create >> mode 100644 gnu/tests/music.scm >> >> diff --git a/doc/guix.texi b/doc/guix.texi >> index 8f14ddd50..e565dfdc9 100644 >> --- a/doc/guix.texi >> +++ b/doc/guix.texi >> @@ -227,6 +227,7 @@ Services >> * Network File System:: NFS related services. >> * Continuous Integration:: The Cuirass service. >> * Power management Services:: The TLP tool. >> +* Music Services:: The MPD. >> * Miscellaneous Services:: Other services. >> >> Defining Services >> @@ -9035,6 +9036,7 @@ declaration. >> * Network File System:: NFS related services. >> * Continuous Integration:: The Cuirass service. >> * Power management Services:: The TLP tool. >> +* Music Services:: The MPD. >> * Miscellaneous Services:: Other services. >> @end menu >> >> @@ -15635,6 +15637,57 @@ Package object of thermald. >> @end table >> @end deftp >> >> +@node Music Services >> +@subsubsection Music Services > > I'm wondering if Audio services, rather than Music services might be > better? Maybe this would fit in other services related to audio, e.g. > Jack, MIDI stuff, etc... > That sounds like a good idea. >> +@cindex mpd >> +@subsubheading Music Player Daemon >> + >> +The @code{(gnu services music)} provides a service to start MPD (the >> Music +Player Daemon). It uses pulseaudio for output. >> + >> +@defvr {Scheme Variable} mpd-service-type >> +The service type for @command{mpd} >> +@end defvr >> + >> +@deftp {Data Type} mpd-configuration >> +Data type representing the configuration of @command{mpd}. >> + >> +@table @asis >> +@item @code{user} (default: @code{"mpd"}) >> +The user to run mpd as. >> + >> +@item @code{music-dir} (default: @code{"~/Music"}) >> +The directory to scan for music files. >> + >> +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) >> +The directory to store playlists. >> + >> +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) >> +The file mpd wil store its PID. >> + >> +@item @code{port} (default: @code{"6600"}) >> +The port to run mpd on. >> + >> +@item @code{address} (default: @code{"any"}) >> +The address that mpd will bind to. To use a Unix domain socket, >> +an absolute path can be specified here. > > The style for Guix is to use two spaces between sentences, I always > forget about this too. > Oh yes, me too. >> + >> +@end table >> +@end deftp >> + >> +@deffn {Scheme Procedure} mpd-service [#:config (mpd-configuration)] >> +Return a service that runs @code{mpd} using @var{configuration}, >> +a @code{} object. >> + >> +The following example shows how one might run @code{mpd} as user >> +@code{"bob"} on port @code{6666}. >> +@example >> +(mpd-service (mpd-configuration >> + (user "bob") >> + (port "6666"))) >> +@end example >> +@end deffn >> >> @node Miscellaneous Services >> @subsubsection Miscellaneous Services >> diff --git a/gnu/local.mk b/gnu/local.mk >> index b1ff72d6a..cad0ba38d 100644 >> --- a/gnu/local.mk >> +++ b/gnu/local.mk >> @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES >> =3D \ >> %D%/services/mail.scm \ >> %D%/services/mcron.scm \ >> %D%/services/messaging.scm \ >> + %D%/services/music.scm \ >> %D%/services/networking.scm \ >> %D%/services/nfs.scm \ >> %D%/services/shepherd.scm \ >> @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES >> =3D \ >> %D%/tests/install.scm \ >> %D%/tests/mail.scm \ >> %D%/tests/messaging.scm \ >> + %D%/tests/music.scm \ >> %D%/tests/networking.scm \ >> %D%/tests/ssh.scm \ >> %D%/tests/web.scm >> diff --git a/gnu/services/music.scm b/gnu/services/music.scm >> new file mode 100644 >> index 000000000..77912d5c6 >> --- /dev/null >> +++ b/gnu/services/music.scm >> @@ -0,0 +1,84 @@ >> +;;; GNU Guix --- Functional package management for GNU >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen >> +;;; >> +;;; This file is part of GNU Guix. >> +;;; >> +;;; GNU Guix is free software; you can redistribute it and/or modify >> it +;;; under the terms of the GNU General Public License as >> published by +;;; the Free Software Foundation; either version 3 of >> the License, or (at +;;; your option) any later version. >> +;;; >> +;;; GNU Guix is distributed in the hope that it will be useful, but >> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> +;;; GNU General Public License for more details. >> +;;; >> +;;; You should have received a copy of the GNU General Public License >> +;;; along with GNU Guix. If not, see . >> + >> +(define-module (gnu services music) >> + #:use-module (guix gexp) >> + #:use-module (gnu services) >> + #:use-module (gnu services shepherd) >> + #:use-module (gnu packages mpd) >> + #:use-module (guix records) >> + #:export (mpd-configuration >> + mpd-configuration? >> + mpd-service >> + mpd-service-type)) >> + >> +;;; Commentary: >> +;;; >> +;;; Music related services >> +;;; >> +;;; Code: >> + >> +(define-record-type* >> + mpd-configuration make-mpd-configuration >> + mpd-configuration? >> + (user mpd-configuration-user >> + (default "mpd")) >> + (music-dir mpd-configuration-music-dir >> + (default "~/Music")) >> + (playlist-dir mpd-configuration-playlist-dir >> + (default "~/.mpd/playlists")) >> + (port mpd-configuration-port >> + (default "6600")) >> + (address mpd-configuration-address >> + (default "any")) >> + (pid-file mpd-configuration-pid-file >> + (default "~/.mpd-pid"))) >> + >> +(define (mpd-config->file config) >> + (apply >> + mixed-text-file "mpd.conf" >> + "audio_output {\n" >> + " type \"pulse\"\n" >> + " name \"MPD\"\n" >> + "}\n" >> + (map (lambda (config-line) >> + (let ((config-name (car config-line)) >> + (config-val (cadr config-line))) >> + (string-append config-name " \"" (config-val config) >> "\"\n"))) >> + `(("user" ,mpd-configuration-user) >> + ("music_directory" ,mpd-configuration-music-dir) >> + ("playlist_directory" ,mpd-configuration-playlist-dir) >> + ("port" ,mpd-configuration-port) >> + ("bind_to_address" ,mpd-configuration-address) >> + ("pid_file" ,mpd-configuration-pid-file))))) >> + >> +(define mpd-service-type >> + (shepherd-service-type >> + 'mpd >> + (lambda (config) >> + (shepherd-service >> + (documentation "Run the MPD (Music Player Daemon)") >> + (provision '(mpd)) >> + (start #~(make-forkexec-constructor >> + (list #$(file-append mpd "/bin/mpd") >> + "--no-daemon" >> + #$(mpd-config->file config)))) >> + (stop #~(make-kill-destructor)))))) >> + >> +(define* (mpd-service #:optional (config (mpd-configuration))) >> + (service mpd-service-type config)) > > I've been trying a slightly different style for this recently. At the > moment, if you had a configuration file for MPD, you couldn't use this > with the service here. One way of addressing this is to do something > like the Tailon service, and define a gexp compiler for the > configuration file (e.g. [1]). For the Tailon service, this means that > you should be able to pass your own configuration file to the service. > I am not sure I get how this works, and I would probs just make a big mess. What about we take my approach first, and then I can come back to it when I learn some more about guix? > Also, now that a can have a default-value, I think its > easier to just have the mpd-service-type, without the mpd-service > procedure. If you add a default value, you should be able to do > (service mpd-service-type). > Ok with me. > 1: > https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/admin.scm#n2= 55 > >> diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm >> new file mode 100644 >> index 000000000..158513098 >> --- /dev/null >> +++ b/gnu/tests/music.scm >> @@ -0,0 +1,83 @@ >> +;;; GNU Guix --- Functional package management for GNU >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen >> +;;; >> +;;; This file is part of GNU Guix. >> +;;; >> +;;; GNU Guix is free software; you can redistribute it and/or modify >> it +;;; under the terms of the GNU General Public License as >> published by +;;; the Free Software Foundation; either version 3 of >> the License, or (at +;;; your option) any later version. >> +;;; >> +;;; GNU Guix is distributed in the hope that it will be useful, but >> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> +;;; GNU General Public License for more details. >> +;;; >> +;;; You should have received a copy of the GNU General Public License >> +;;; along with GNU Guix. If not, see . >> + >> +(define-module (gnu tests music) >> + #:use-module (gnu tests) >> + #:use-module (gnu system) >> + #:use-module (gnu system vm) >> + #:use-module (gnu services) >> + #:use-module (gnu services music) >> + #:use-module (gnu packages mpd) >> + #:use-module (guix gexp) >> + #:export (%test-mpd)) >> + >> +(define %mpd-os >> + (simple-operating-system >> + (mpd-service (mpd-configuration >> + (user "root"))))) >> + >> +(define (run-mpd-test) >> + "Run tests in %mpd-os, which has mpd running." >> + (define os >> + (marionette-operating-system >> + %mpd-os >> + #:imported-modules '((gnu services herd)))) >> + >> + (define vm >> + (virtual-machine os)) >> + >> + (define test >> + (with-imported-modules '((gnu build marionette)) >> + #~(begin >> + (use-modules (srfi srfi-64) >> + (gnu build marionette)) >> + (define marionette >> + (make-marionette (list #$vm))) >> + >> + (mkdir #$output) >> + (chdir #$output) >> + >> + (test-begin "mpd") >> + >> + (test-eq "service is running" >> + 'running! >> + (marionette-eval >> + '(begin >> + (use-modules (gnu services herd)) >> + (start-service 'mpd) >> + 'running!) >> + marionette)) > > Recently, the start-service procedure was changed to return the > information from the shepherd, and this can be used to make this check > a bit more rigorous. > > I've got an patch for the Memcached service which demonstrates this > here [2], as with the test above, it will not always fail, even if the > service fails to create the PID file. > > 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28021 > >> + (test-assert "pid file" >> + (wait-for-file "/root/.mpd-pid" >> + marionette)) > > If this is useful when using MPD, then I think it would be valuable to > get the shepherd to wait for the PID file. I think you can do this by > adding #:pid-file to the make-forkexec-constructor call. > > If you do this, them I'm not sure this test adds anything, as I think > the start-service call would only return successfully when the service > has started, and created the PID file. > Right, I have removed this test. >> + (test-assert "mpc connect" >> + (marionette-eval >> + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) >> + marionette)) >> + >> + (test-end) >> + (exit (=3D (test-runner-fail-count (test-runner-current)) >> 0))))) >> + (gexp->derivation "mpd-test" test)) >> + >> +(define %test-mpd >> + (system-test >> + (name "mpd") >> + (description "Test that the mpd can run and be connected to.") >> + (value (run-mpd-test)))) I think I have fixed all of your suggestions (apart from the gexp-compiler one). Please see my new patch. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-gnu-Add-mpd-service.patch Content-Transfer-Encoding: quoted-printable >From 419a8df59bc958ee87ece5519393b32cfbef609c Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sat, 12 Aug 2017 03:40:25 +0200 Subject: [PATCH] gnu: Add mpd service. * doc/guix.texi: Add documentation. * gnu/services/audio.scm (): New record type. (mpd-service-type): New service type. * gnu/tests/audio.scm: New file. * gnu/local.mk: Add new files. --- doc/guix.texi | 49 ++++++++++++++++++++++++++++ gnu/local.mk | 2 ++ gnu/services/audio.scm | 86 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ gnu/tests/audio.scm | 78 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 215 insertions(+) create mode 100644 gnu/services/audio.scm create mode 100644 gnu/tests/audio.scm diff --git a/doc/guix.texi b/doc/guix.texi index 8f14ddd50..754408ade 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -227,6 +227,7 @@ Services * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. * Power management Services:: The TLP tool. +* Audio Services:: The MPD. * Miscellaneous Services:: Other services. =20 Defining Services @@ -9035,6 +9036,7 @@ declaration. * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. * Power management Services:: The TLP tool. +* Audio Services:: The MPD. * Miscellaneous Services:: Other services. @end menu =20 @@ -15635,6 +15637,53 @@ Package object of thermald. @end table @end deftp =20 +@node Audio Services +@subsubsection Audio Services + +@cindex mpd +@subsubheading Music Player Daemon + +The @code{(gnu services audio)} provides a service to start MPD (the Music +Player Daemon). It uses pulseaudio for output. + +@defvr {Scheme Variable} mpd-service-type +The service type for @command{mpd} +@end defvr + +@deftp {Data Type} mpd-configuration +Data type representing the configuration of @command{mpd}. + +@table @asis +@item @code{user} (default: @code{"mpd"}) +The user to run mpd as. + +@item @code{music-dir} (default: @code{"~/Music"}) +The directory to scan for music files. + +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) +The directory to store playlists. + +@item @code{pid-file} (default: @code{"/var/run/mpd.pid"}) +The file mpd wil store its PID. This must be an absolute path. + +@item @code{port} (default: @code{"6600"}) +The port to run mpd on. + +@item @code{address} (default: @code{"any"}) +The address that mpd will bind to. To use a Unix domain socket, +an absolute path can be specified here. + +@end table +@end deftp + +The following example shows how one might run @code{mpd} as user +@code{"bob"} on port @code{6666}. +@example +(service mpd-service-type + (mpd-configuration + (user "bob") + (port "6666"))) +@end example =20 @node Miscellaneous Services @subsubsection Miscellaneous Services diff --git a/gnu/local.mk b/gnu/local.mk index cffb18d3a..c12fd8559 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -426,6 +426,7 @@ GNU_SYSTEM_MODULES =3D \ \ %D%/services.scm \ %D%/services/admin.scm \ + %D%/services/audio.scm \ %D%/services/avahi.scm \ %D%/services/base.scm \ %D%/services/configuration.scm \ @@ -481,6 +482,7 @@ GNU_SYSTEM_MODULES =3D \ \ %D%/tests.scm \ %D%/tests/admin.scm \ + %D%/tests/audio.scm \ %D%/tests/base.scm \ %D%/tests/databases.scm \ %D%/tests/dict.scm \ diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm new file mode 100644 index 000000000..f5c465341 --- /dev/null +++ b/gnu/services/audio.scm @@ -0,0 +1,86 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2017 Peter Mikkelsen +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services audio) + #:use-module (guix gexp) + #:use-module (gnu services) + #:use-module (gnu services shepherd) + #:use-module (gnu packages mpd) + #:use-module (guix records) + #:export (mpd-configuration + mpd-configuration? + mpd-service-type)) + +;;; Commentary: +;;; +;;; Audio related services +;;; +;;; Code: + +(define-record-type* + mpd-configuration make-mpd-configuration + mpd-configuration? + (user mpd-configuration-user + (default "mpd")) + (music-dir mpd-configuration-music-dir + (default "~/Music")) + (playlist-dir mpd-configuration-playlist-dir + (default "~/.mpd/playlists")) + (port mpd-configuration-port + (default "6600")) + (address mpd-configuration-address + (default "any")) + (pid-file mpd-configuration-pid-file + (default "/var/run/mpd.pid"))) + +(define (mpd-config->file config) + (apply + mixed-text-file "mpd.conf" + "audio_output {\n" + " type \"pulse\"\n" + " name \"MPD\"\n" + "}\n" + (map (lambda (config-line) + (let ((config-name (car config-line)) + (config-val (cadr config-line))) + (string-append config-name " \"" (config-val config) "\"\n"))) + `(("user" ,mpd-configuration-user) + ("music_directory" ,mpd-configuration-music-dir) + ("playlist_directory" ,mpd-configuration-playlist-dir) + ("port" ,mpd-configuration-port) + ("bind_to_address" ,mpd-configuration-address) + ("pid_file" ,mpd-configuration-pid-file))))) + +(define (mpd-service config) + (shepherd-service + (documentation "Run the MPD (Music Player Daemon)") + (provision '(mpd)) + (start #~(make-forkexec-constructor + (list #$(file-append mpd "/bin/mpd") + "--no-daemon" + #$(mpd-config->file config)) + #:pid-file #$(mpd-configuration-pid-file config))) + (stop #~(make-kill-destructor)))) + +(define mpd-service-type + (service-type + (name 'mpd) + (extensions + (list (service-extension shepherd-root-service-type + (compose list mpd-service)))) + (default-value (mpd-configuration)))) diff --git a/gnu/tests/audio.scm b/gnu/tests/audio.scm new file mode 100644 index 000000000..8eadaf02e --- /dev/null +++ b/gnu/tests/audio.scm @@ -0,0 +1,78 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2017 Peter Mikkelsen +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu tests audio) + #:use-module (gnu tests) + #:use-module (gnu system) + #:use-module (gnu system vm) + #:use-module (gnu services) + #:use-module (gnu services audio) + #:use-module (gnu packages mpd) + #:use-module (guix gexp) + #:export (%test-mpd)) + +(define %mpd-os + (simple-operating-system + (service mpd-service-type + (mpd-configuration + (user "root"))))) + +(define (run-mpd-test) + "Run tests in %mpd-os, which has mpd running." + (define os + (marionette-operating-system + %mpd-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine os)) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-64) + (gnu build marionette)) + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "mpd") + + (test-assert "service is running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'mpd)) + marionette)) + + (test-assert "mpc connect" + (marionette-eval + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) + marionette)) + + (test-end) + (exit (=3D (test-runner-fail-count (test-runner-current)) 0))))) + (gexp->derivation "mpd-test" test)) + +(define %test-mpd + (system-test + (name "mpd") + (description "Test that the mpd can run and be connected to.") + (value (run-mpd-test)))) --=20 2.14.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 12 16:58:47 2017 Received: (at 28059) by debbugs.gnu.org; 12 Aug 2017 20:58:48 +0000 Received: from localhost ([127.0.0.1]:58202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgdUc-0006nK-W4 for submit@debbugs.gnu.org; Sat, 12 Aug 2017 16:58:47 -0400 Received: from li622-129.members.linode.com ([212.71.249.129]:52395 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgdUZ-0006nC-19 for 28059@debbugs.gnu.org; Sat, 12 Aug 2017 16:58:46 -0400 Received: by mira.cbaines.net (Postfix, from userid 113) id 4E64A13E3DE; Sat, 12 Aug 2017 21:58:41 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (17.71.125.91.dyn.plus.net [91.125.71.17]) by mira.cbaines.net (Postfix) with ESMTPSA id E7B6A13D1E0; Sat, 12 Aug 2017 21:58:39 +0100 (BST) Date: Sat, 12 Aug 2017 21:58:33 +0100 From: Christopher Baines To: Peter Mikkelsen Subject: Re: [bug#28059] [PATCH] gnu: Add mpd service. Message-ID: <20170812215833.0b957af6@cbaines.net> In-Reply-To: <87a834u2z3.fsf@gmail.com> References: <20170812015211.5411-1-petermikkelsen10@gmail.com> <20170812115011.4c076108@cbaines.net> <87a834u2z3.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/tgbmddloz8wtrS4SdScYoqp"; protocol="application/pgp-signature" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28059 Cc: 28059@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --Sig_/tgbmddloz8wtrS4SdScYoqp Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, 12 Aug 2017 19:10:08 +0200 Peter Mikkelsen wrote: > Hi, thanks for the quick review! >=20 > Christopher Baines writes: >=20 > > Hey, > > > > This looks great Peter, awesome job :) I've made some notes about > > potential improvements inline below. > > > > I've succeeded in running the system test locally, but there was > > some suspicious output in the log: > > > > exception: bind to '0.0.0.0:6600' failed (continuing anyway, because > > binding to '[::]:6600' succeeded): Failed to bind socket: Address > > already in use exception: Failed to access /root/.mpd/playlists: No > > such file or directory > > =20 >=20 > This is pretty normal for mpd, and I believe happens because it first > binds on IPv6 and then fails for IPv4. The error about the playlist > dir happens because it does not exist, but AFAIK it is no problem > unless you want to save playlists. The user can just create the dir. Ok, good to know :) > > On Sat, 12 Aug 2017 03:52:11 +0200 > > Peter Mikkelsen wrote: =20 > >> * doc/guix.text: Add documentation. =20 > > > > Typo above, text rather than texi. > > =20 >=20 > Ups, my mistake. >=20 > >> * gnu/services/music.scm (): New record type. > >> (mpd-service): New service extension. > >> (mpd-service-type): New service type. > >> * gnu/tests/music.scm: New file. > >> * gnu/local.mk: Add new files. > >> > >> --- > >> doc/guix.texi | 53 +++++++++++++++++++++++++++++++ > >> gnu/local.mk | 2 ++ > >> gnu/services/music.scm | 84 > >> ++++++++++++++++++++++++++++++++++++++++++++++++++ > >> gnu/tests/music.scm | 83 > >> +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, > >> 222 insertions(+) create mode 100644 gnu/services/music.scm create > >> mode 100644 gnu/tests/music.scm > >> > >> diff --git a/doc/guix.texi b/doc/guix.texi > >> index 8f14ddd50..e565dfdc9 100644 > >> --- a/doc/guix.texi > >> +++ b/doc/guix.texi > >> @@ -227,6 +227,7 @@ Services > >> * Network File System:: NFS related services. > >> * Continuous Integration:: The Cuirass service. > >> * Power management Services:: The TLP tool. > >> +* Music Services:: The MPD. > >> * Miscellaneous Services:: Other services. > >> > >> Defining Services > >> @@ -9035,6 +9036,7 @@ declaration. > >> * Network File System:: NFS related services. > >> * Continuous Integration:: The Cuirass service. > >> * Power management Services:: The TLP tool. > >> +* Music Services:: The MPD. > >> * Miscellaneous Services:: Other services. > >> @end menu > >> > >> @@ -15635,6 +15637,57 @@ Package object of thermald. > >> @end table > >> @end deftp > >> > >> +@node Music Services > >> +@subsubsection Music Services =20 > > > > I'm wondering if Audio services, rather than Music services might be > > better? Maybe this would fit in other services related to audio, > > e.g. Jack, MIDI stuff, etc... > > =20 >=20 > That sounds like a good idea. >=20 > >> +@cindex mpd > >> +@subsubheading Music Player Daemon > >> + > >> +The @code{(gnu services music)} provides a service to start MPD > >> (the Music +Player Daemon). It uses pulseaudio for output. > >> + > >> +@defvr {Scheme Variable} mpd-service-type > >> +The service type for @command{mpd} > >> +@end defvr > >> + > >> +@deftp {Data Type} mpd-configuration > >> +Data type representing the configuration of @command{mpd}. > >> + > >> +@table @asis > >> +@item @code{user} (default: @code{"mpd"}) > >> +The user to run mpd as. > >> + > >> +@item @code{music-dir} (default: @code{"~/Music"}) > >> +The directory to scan for music files. > >> + > >> +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) > >> +The directory to store playlists. > >> + > >> +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) > >> +The file mpd wil store its PID. > >> + > >> +@item @code{port} (default: @code{"6600"}) > >> +The port to run mpd on. > >> + > >> +@item @code{address} (default: @code{"any"}) > >> +The address that mpd will bind to. To use a Unix domain socket, > >> +an absolute path can be specified here. =20 > > > > The style for Guix is to use two spaces between sentences, I always > > forget about this too. > > =20 >=20 > Oh yes, me too. >=20 > >> + > >> +@end table > >> +@end deftp > >> + > >> +@deffn {Scheme Procedure} mpd-service [#:config > >> (mpd-configuration)] +Return a service that runs @code{mpd} using > >> @var{configuration}, +a @code{} object. > >> + > >> +The following example shows how one might run @code{mpd} as user > >> +@code{"bob"} on port @code{6666}. > >> +@example > >> +(mpd-service (mpd-configuration > >> + (user "bob") > >> + (port "6666"))) > >> +@end example > >> +@end deffn > >> > >> @node Miscellaneous Services > >> @subsubsection Miscellaneous Services > >> diff --git a/gnu/local.mk b/gnu/local.mk > >> index b1ff72d6a..cad0ba38d 100644 > >> --- a/gnu/local.mk > >> +++ b/gnu/local.mk > >> @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES > >> =3D \ > >> %D%/services/mail.scm \ > >> %D%/services/mcron.scm \ > >> %D%/services/messaging.scm \ > >> + %D%/services/music.scm \ > >> %D%/services/networking.scm \ > >> %D%/services/nfs.scm \ > >> %D%/services/shepherd.scm \ > >> @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES > >> =3D \ > >> %D%/tests/install.scm \ > >> %D%/tests/mail.scm \ > >> %D%/tests/messaging.scm \ > >> + %D%/tests/music.scm \ > >> %D%/tests/networking.scm \ > >> %D%/tests/ssh.scm \ > >> %D%/tests/web.scm > >> diff --git a/gnu/services/music.scm b/gnu/services/music.scm > >> new file mode 100644 > >> index 000000000..77912d5c6 > >> --- /dev/null > >> +++ b/gnu/services/music.scm > >> @@ -0,0 +1,84 @@ > >> +;;; GNU Guix --- Functional package management for GNU > >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen > >> +;;; > >> +;;; This file is part of GNU Guix. > >> +;;; > >> +;;; GNU Guix is free software; you can redistribute it and/or > >> modify it +;;; under the terms of the GNU General Public License as > >> published by +;;; the Free Software Foundation; either version 3 of > >> the License, or (at +;;; your option) any later version. > >> +;;; > >> +;;; GNU Guix is distributed in the hope that it will be useful, > >> but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > >> +;;; GNU General Public License for more details. > >> +;;; > >> +;;; You should have received a copy of the GNU General Public > >> License +;;; along with GNU Guix. If not, see > >> . + > >> +(define-module (gnu services music) > >> + #:use-module (guix gexp) > >> + #:use-module (gnu services) > >> + #:use-module (gnu services shepherd) > >> + #:use-module (gnu packages mpd) > >> + #:use-module (guix records) > >> + #:export (mpd-configuration > >> + mpd-configuration? > >> + mpd-service > >> + mpd-service-type)) > >> + > >> +;;; Commentary: > >> +;;; > >> +;;; Music related services > >> +;;; > >> +;;; Code: > >> + > >> +(define-record-type* > >> + mpd-configuration make-mpd-configuration > >> + mpd-configuration? > >> + (user mpd-configuration-user > >> + (default "mpd")) > >> + (music-dir mpd-configuration-music-dir > >> + (default "~/Music")) > >> + (playlist-dir mpd-configuration-playlist-dir > >> + (default "~/.mpd/playlists")) > >> + (port mpd-configuration-port > >> + (default "6600")) > >> + (address mpd-configuration-address > >> + (default "any")) > >> + (pid-file mpd-configuration-pid-file > >> + (default "~/.mpd-pid"))) > >> + > >> +(define (mpd-config->file config) > >> + (apply > >> + mixed-text-file "mpd.conf" > >> + "audio_output {\n" > >> + " type \"pulse\"\n" > >> + " name \"MPD\"\n" > >> + "}\n" > >> + (map (lambda (config-line) > >> + (let ((config-name (car config-line)) > >> + (config-val (cadr config-line))) > >> + (string-append config-name " \"" (config-val config) > >> "\"\n"))) > >> + `(("user" ,mpd-configuration-user) > >> + ("music_directory" ,mpd-configuration-music-dir) > >> + ("playlist_directory" ,mpd-configuration-playlist-dir) > >> + ("port" ,mpd-configuration-port) > >> + ("bind_to_address" ,mpd-configuration-address) > >> + ("pid_file" ,mpd-configuration-pid-file))))) > >> + > >> +(define mpd-service-type > >> + (shepherd-service-type > >> + 'mpd > >> + (lambda (config) > >> + (shepherd-service > >> + (documentation "Run the MPD (Music Player Daemon)") > >> + (provision '(mpd)) > >> + (start #~(make-forkexec-constructor > >> + (list #$(file-append mpd "/bin/mpd") > >> + "--no-daemon" > >> + #$(mpd-config->file config)))) > >> + (stop #~(make-kill-destructor)))))) > >> + > >> +(define* (mpd-service #:optional (config (mpd-configuration))) > >> + (service mpd-service-type config)) =20 > > > > I've been trying a slightly different style for this recently. At > > the moment, if you had a configuration file for MPD, you couldn't > > use this with the service here. One way of addressing this is to do > > something like the Tailon service, and define a gexp compiler for > > the configuration file (e.g. [1]). For the Tailon service, this > > means that you should be able to pass your own configuration file > > to the service.=20 >=20 > I am not sure I get how this works, and I would probs just make a big > mess. What about we take my approach first, and then I can come back > to it when I learn some more about guix? No problem. Looking at it again, I think it might be a bit trickier than I initially assumed, as the pid-file value is used. > > Also, now that a can have a default-value, I think > > its easier to just have the mpd-service-type, without the > > mpd-service procedure. If you add a default value, you should be > > able to do (service mpd-service-type). > > =20 > Ok with me. >=20 > > 1: > > https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/admin.scm#= n255 > > =20 > >> diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm > >> new file mode 100644 > >> index 000000000..158513098 > >> --- /dev/null > >> +++ b/gnu/tests/music.scm > >> @@ -0,0 +1,83 @@ > >> +;;; GNU Guix --- Functional package management for GNU > >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen > >> +;;; > >> +;;; This file is part of GNU Guix. > >> +;;; > >> +;;; GNU Guix is free software; you can redistribute it and/or > >> modify it +;;; under the terms of the GNU General Public License as > >> published by +;;; the Free Software Foundation; either version 3 of > >> the License, or (at +;;; your option) any later version. > >> +;;; > >> +;;; GNU Guix is distributed in the hope that it will be useful, > >> but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > >> +;;; GNU General Public License for more details. > >> +;;; > >> +;;; You should have received a copy of the GNU General Public > >> License +;;; along with GNU Guix. If not, see > >> . + > >> +(define-module (gnu tests music) > >> + #:use-module (gnu tests) > >> + #:use-module (gnu system) > >> + #:use-module (gnu system vm) > >> + #:use-module (gnu services) > >> + #:use-module (gnu services music) > >> + #:use-module (gnu packages mpd) > >> + #:use-module (guix gexp) > >> + #:export (%test-mpd)) > >> + > >> +(define %mpd-os > >> + (simple-operating-system > >> + (mpd-service (mpd-configuration > >> + (user "root"))))) > >> + > >> +(define (run-mpd-test) > >> + "Run tests in %mpd-os, which has mpd running." > >> + (define os > >> + (marionette-operating-system > >> + %mpd-os > >> + #:imported-modules '((gnu services herd)))) > >> + > >> + (define vm > >> + (virtual-machine os)) > >> + > >> + (define test > >> + (with-imported-modules '((gnu build marionette)) > >> + #~(begin > >> + (use-modules (srfi srfi-64) > >> + (gnu build marionette)) > >> + (define marionette > >> + (make-marionette (list #$vm))) > >> + > >> + (mkdir #$output) > >> + (chdir #$output) > >> + > >> + (test-begin "mpd") > >> + > >> + (test-eq "service is running" > >> + 'running! > >> + (marionette-eval > >> + '(begin > >> + (use-modules (gnu services herd)) > >> + (start-service 'mpd) > >> + 'running!) > >> + marionette)) =20 > > > > Recently, the start-service procedure was changed to return the > > information from the shepherd, and this can be used to make this > > check a bit more rigorous. > > > > I've got an patch for the Memcached service which demonstrates this > > here [2], as with the test above, it will not always fail, even if > > the service fails to create the PID file. > > > > 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28021 > > =20 > >> + (test-assert "pid file" > >> + (wait-for-file "/root/.mpd-pid" > >> + marionette)) =20 > > > > If this is useful when using MPD, then I think it would be valuable > > to get the shepherd to wait for the PID file. I think you can do > > this by adding #:pid-file to the make-forkexec-constructor call. > > > > If you do this, them I'm not sure this test adds anything, as I > > think the start-service call would only return successfully when > > the service has started, and created the PID file. > > =20 >=20 > Right, I have removed this test. Great. Just to check I wasn't wrong, I've just tested what happens if you break the service by getting mpd to create the PID file, and shepherd to look for it in different places, and the previous test about starting the service does indeed fail, which is what we want :D > >> + (test-assert "mpc connect" > >> + (marionette-eval > >> + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) > >> + marionette)) > >> + > >> + (test-end) > >> + (exit (=3D (test-runner-fail-count (test-runner-current)) > >> 0))))) > >> + (gexp->derivation "mpd-test" test)) > >> + > >> +(define %test-mpd > >> + (system-test > >> + (name "mpd") > >> + (description "Test that the mpd can run and be connected to.") > >> + (value (run-mpd-test)))) =20 >=20 > I think I have fixed all of your suggestions (apart from the > gexp-compiler one). Please see my new patch. Awesome, I've put a couple more suggestions below, but just on the docs and a bit of code style. Regardless of these, I think this is good to go. > From 419a8df59bc958ee87ece5519393b32cfbef609c Mon Sep 17 00:00:00 2001 > From: Peter Mikkelsen > Date: Sat, 12 Aug 2017 03:40:25 +0200 > Subject: [PATCH] gnu: Add mpd service. >=20 > * doc/guix.texi: Add documentation. > * gnu/services/audio.scm (): New record type. > (mpd-service-type): New service type. > * gnu/tests/audio.scm: New file. > * gnu/local.mk: Add new files. > --- > doc/guix.texi | 49 ++++++++++++++++++++++++++++ > gnu/local.mk | 2 ++ > gnu/services/audio.scm | 86 > ++++++++++++++++++++++++++++++++++++++++++++++++++ > gnu/tests/audio.scm | 78 > +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 215 > insertions(+) create mode 100644 gnu/services/audio.scm create mode > 100644 gnu/tests/audio.scm >=20 > diff --git a/doc/guix.texi b/doc/guix.texi > index 8f14ddd50..754408ade 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -227,6 +227,7 @@ Services > * Network File System:: NFS related services. > * Continuous Integration:: The Cuirass service. > * Power management Services:: The TLP tool. > +* Audio Services:: The MPD. > * Miscellaneous Services:: Other services. > =20 > Defining Services > @@ -9035,6 +9036,7 @@ declaration. > * Network File System:: NFS related services. > * Continuous Integration:: The Cuirass service. > * Power management Services:: The TLP tool. > +* Audio Services:: The MPD. > * Miscellaneous Services:: Other services. > @end menu > =20 > @@ -15635,6 +15637,53 @@ Package object of thermald. > @end table > @end deftp > =20 > +@node Audio Services > +@subsubsection Audio Services > + > +@cindex mpd > +@subsubheading Music Player Daemon > + > +The @code{(gnu services audio)} provides a service to start MPD (the > Music +Player Daemon). It uses pulseaudio for output. > + > +@defvr {Scheme Variable} mpd-service-type > +The service type for @command{mpd} > +@end defvr > + > +@deftp {Data Type} mpd-configuration > +Data type representing the configuration of @command{mpd}. > + > +@table @asis > +@item @code{user} (default: @code{"mpd"}) > +The user to run mpd as. > + > +@item @code{music-dir} (default: @code{"~/Music"}) > +The directory to scan for music files. > + > +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) > +The directory to store playlists. > + > +@item @code{pid-file} (default: @code{"/var/run/mpd.pid"}) > +The file mpd wil store its PID. This must be an absolute path. > + > +@item @code{port} (default: @code{"6600"}) > +The port to run mpd on. > + > +@item @code{address} (default: @code{"any"}) > +The address that mpd will bind to. To use a Unix domain socket, > +an absolute path can be specified here. > + > +@end table > +@end deftp > + > +The following example shows how one might run @code{mpd} as user > +@code{"bob"} on port @code{6666}. > +@example > +(service mpd-service-type > + (mpd-configuration > + (user "bob") > + (port "6666"))) > +@end example I've got a few suggestions for the docs. Nothing too important, and I'm fine if you still prefer docs without the suggestions below, but feel free to pick and choose any changes that you think are good, I've put my reasoning inline in round brackets. @node Audio Services @subsubsection Audio Services The @code{(gnu services audio)} module provides a service to start MPD (the Music Player Daemon). =20 ( Having the introduction to the module above the Music Player Daemon subsubheading seems neater. Also, I think adding "module" after @code{(gnu services audio)} helps with readability. ) @cindex mpd @subsubheading Music Player Daemon The Music Player Daemon (MPD) is a service that can play music while being controlled from the local machine or over the network by a variety of clients. ( An introductory paragraph about what the service does might be useful, so I've written one above. ) The following example shows how one might run @code{mpd} as user @code{"bob"} on port @code{6666}. It uses pulseaudio for output. @example (service mpd-service-type (mpd-configuration (user "bob") (port "6666"))) @end example ( Moving the example here might be more visible, rather than below the reference documentation. ) @defvr {Scheme Variable} mpd-service-type The service type for @command{mpd} @end defvr @deftp {Data Type} mpd-configuration Data type representing the configuration of @command{mpd}. ... @end table @end deftp > @node Miscellaneous Services > @subsubsection Miscellaneous Services > diff --git a/gnu/local.mk b/gnu/local.mk > index cffb18d3a..c12fd8559 100644 > --- a/gnu/local.mk > +++ b/gnu/local.mk > @@ -426,6 +426,7 @@ GNU_SYSTEM_MODULES > =3D \ \ > %D%/services.scm \ > %D%/services/admin.scm \ > + %D%/services/audio.scm \ > %D%/services/avahi.scm \ > %D%/services/base.scm \ > %D%/services/configuration.scm \ > @@ -481,6 +482,7 @@ GNU_SYSTEM_MODULES > =3D \ \ > %D%/tests.scm \ > %D%/tests/admin.scm \ > + %D%/tests/audio.scm \ > %D%/tests/base.scm \ > %D%/tests/databases.scm \ > %D%/tests/dict.scm \ > diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm > new file mode 100644 > index 000000000..f5c465341 > --- /dev/null > +++ b/gnu/services/audio.scm > @@ -0,0 +1,86 @@ > +;;; GNU Guix --- Functional package management for GNU > +;;; Copyright =C2=A9 2017 Peter Mikkelsen > +;;; > +;;; This file is part of GNU Guix. > +;;; > +;;; GNU Guix is free software; you can redistribute it and/or modify > it +;;; under the terms of the GNU General Public License as > published by +;;; the Free Software Foundation; either version 3 of > the License, or (at +;;; your option) any later version. > +;;; > +;;; GNU Guix is distributed in the hope that it will be useful, but > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +;;; GNU General Public License for more details. > +;;; > +;;; You should have received a copy of the GNU General Public License > +;;; along with GNU Guix. If not, see . > + > +(define-module (gnu services audio) > + #:use-module (guix gexp) > + #:use-module (gnu services) > + #:use-module (gnu services shepherd) > + #:use-module (gnu packages mpd) > + #:use-module (guix records) > + #:export (mpd-configuration > + mpd-configuration? > + mpd-service-type)) > + > +;;; Commentary: > +;;; > +;;; Audio related services > +;;; > +;;; Code: > + > +(define-record-type* > + mpd-configuration make-mpd-configuration > + mpd-configuration? > + (user mpd-configuration-user > + (default "mpd")) > + (music-dir mpd-configuration-music-dir > + (default "~/Music")) > + (playlist-dir mpd-configuration-playlist-dir > + (default "~/.mpd/playlists")) > + (port mpd-configuration-port > + (default "6600")) > + (address mpd-configuration-address > + (default "any")) > + (pid-file mpd-configuration-pid-file > + (default "/var/run/mpd.pid"))) > + > +(define (mpd-config->file config) > + (apply > + mixed-text-file "mpd.conf" > + "audio_output {\n" > + " type \"pulse\"\n" > + " name \"MPD\"\n" > + "}\n" > + (map (lambda (config-line) > + (let ((config-name (car config-line)) > + (config-val (cadr config-line))) > + (string-append config-name " \"" (config-val config) > "\"\n"))) One way of making this a bit more concise and remove the need for car and cadr is to use the match module (ice-9 match). (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) > + ("port" ,mpd-configuration-port) > + ("bind_to_address" ,mpd-configuration-address) > + ("pid_file" ,mpd-configuration-pid-file))))) > + ... --Sig_/tgbmddloz8wtrS4SdScYoqp Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmPa/lfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE 9Xe+SRAAgwTVkz4OJTADFu0adeUi4sMQEMlxEhNStkLcRrGEksr6zYREHvsjA9s1 6PoNsW6V1yOLsi2dU4Tt57iVnCTtS5Xl0Y8ZPlr8xMjbghm2dzpvtbjmsP9w6pfm hg/Gx7YEB1jyzdkH1QQqAq2FY0JAzWg8H5c487bRVQ42fQ/D1WF9LUy8NU2ZhsTM GGPmQXIzv+Yw/UV3KmtNFkFDoUeQBdJnDHH3C3qMfUaJKxSxh4e0L7YV5jvyFZ4J vtyptfRtUDak2IQ8/P4GfrM13NC/FxXZPoJm0NC61Pz9C5Fmn14Xo2zvwEYK/PlN Ml22nOQ/XesiF+W6T4LwbKWSAGVNSoTyRLYy0qGkvqT0ieoD0yPVVKb/uvGAuOT8 qepxoYYfyjbwO+xA/dXab3ZLrwwXqwk5wxenGvVQWlJFFvybnTGsKrwoikNoGPHq srgZNqxqiy53XnzMEXD1r6uzDCBCrmcW5vZbnDflIlIONWXcnka84HA6PJrnWcek nstMpTimsdjHDUPQGEBtHazmmUu29NQvR65i03n42OmR4U07i7k+LP7AQbz05NQK d9ZkGPpNlbR9PdUqpQ2vP9jKAZvfW7ayVM0Y5cFDAJ2dDcXWI4aDqgxFEHm8Vx0C GlfJbR5aKRQIB/+om4g7J5qO24tjwsHrpgeQWpjmP/uDK1hZOZE= =UErP -----END PGP SIGNATURE----- --Sig_/tgbmddloz8wtrS4SdScYoqp-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 12 18:04:24 2017 Received: (at 28059) by debbugs.gnu.org; 12 Aug 2017 22:04:24 +0000 Received: from localhost ([127.0.0.1]:58474 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgeW7-0007K7-7q for submit@debbugs.gnu.org; Sat, 12 Aug 2017 18:04:24 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:35785) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgeW2-0007K1-80 for 28059@debbugs.gnu.org; Sat, 12 Aug 2017 18:04:21 -0400 Received: by mail-wm0-f50.google.com with SMTP id m85so14331763wma.0 for <28059@debbugs.gnu.org>; Sat, 12 Aug 2017 15:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=vJeiXiLwXjYN83hCEzbVXJMDSGJBGZl2dmJ/OUU2V0I=; b=OGPHVqFRPzgziaqVSZ1ZCXINWteDr1B0Mdr5Ph1SeGUGeKIRXTJW0RVsxnAxmPd1VF xiFD/XLG9wlNVMWaN3QgoukZYOoVY8LSel0HX0hq5xNQnkQPbdyS2QBM2+OODh3vWm3n 7mb9awJK+frJOQc7cPg7w8frAgstqSXsHqBDcRPVC7CuLMzjK3KBGQH0FGoSSBUvaN9O xLrzg2crCZRgNf71rug6Ar+75vEGm6KPZlqP+rfAgOg657uDeOl4VsT8mYqZid655Ovw pGFvtt0RhG/hAI3L0q0SF6rNiv2CdVi8tgP6MPkljkosr1TUQvBw3yuteH/Hpd8vbrvW vIkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=vJeiXiLwXjYN83hCEzbVXJMDSGJBGZl2dmJ/OUU2V0I=; b=HqK1pqi193bYuZBB6FGRDRifMICzvIhj0hD91JKRdAsCD+Yt1PnWRr771nt3h4sULa d/DvsNdoa4SgfZrepz1+4+LN+6Ur+as5euoC+l1tv3d6gQcyPTQLiNwsx+o1l0r7kdQm It/iBNeT3np9woQkB8Ma98dRmFQD0Y9rhMCb/zpF0Bg7875wlXUZyKUj3rPN533gszXp VwSEBh0JRVOPTYTjUY1fA7zQaMkaxpVIsehQvbvNLgSKMOWaur30RSZBVBAOFzy2snng eOoWsQ9tRFNt/IpDAxydbQFBvjokPmy5cycDhoBHaeJUHDl4D2UoucCKyLLKwmE75OWQ mraQ== X-Gm-Message-State: AHYfb5iPgy1Q5HHdHlHzrf6t9Gog5ALM1gFq1eU1R4rKvlgrQRt7tMq9 YXRIwGEdePW8rCgDaag= X-Received: by 10.80.153.75 with SMTP id l11mr20409767edb.7.1502575451540; Sat, 12 Aug 2017 15:04:11 -0700 (PDT) Received: from guixsd (D4709868.rev.sefiber.dk. [212.112.152.104]) by smtp.gmail.com with ESMTPSA id i22sm2302523eda.10.2017.08.12.15.04.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 12 Aug 2017 15:04:10 -0700 (PDT) From: Peter Mikkelsen To: Christopher Baines Subject: Re: [bug#28059] [PATCH] gnu: Add mpd service. References: <20170812015211.5411-1-petermikkelsen10@gmail.com> <20170812115011.4c076108@cbaines.net> <87a834u2z3.fsf@gmail.com> <20170812215833.0b957af6@cbaines.net> Date: Sun, 13 Aug 2017 00:04:04 +0200 In-Reply-To: <20170812215833.0b957af6@cbaines.net> (Christopher Baines's message of "Sat, 12 Aug 2017 21:58:33 +0100") Message-ID: <87wp68cujv.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.2 (/) X-Debbugs-Envelope-To: 28059 Cc: 28059@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Christopher Baines writes: > On Sat, 12 Aug 2017 19:10:08 +0200 > Peter Mikkelsen wrote: > >> Hi, thanks for the quick review! >> >> Christopher Baines writes: >> >> > Hey, >> > >> > This looks great Peter, awesome job :) I've made some notes about >> > potential improvements inline below. >> > >> > I've succeeded in running the system test locally, but there was >> > some suspicious output in the log: >> > >> > exception: bind to '0.0.0.0:6600' failed (continuing anyway, because >> > binding to '[::]:6600' succeeded): Failed to bind socket: Address >> > already in use exception: Failed to access /root/.mpd/playlists: No >> > such file or directory >> > >> >> This is pretty normal for mpd, and I believe happens because it first >> binds on IPv6 and then fails for IPv4. The error about the playlist >> dir happens because it does not exist, but AFAIK it is no problem >> unless you want to save playlists. The user can just create the dir. > > Ok, good to know :) > >> > On Sat, 12 Aug 2017 03:52:11 +0200 >> > Peter Mikkelsen wrote: >> >> * doc/guix.text: Add documentation. >> > >> > Typo above, text rather than texi. >> > >> >> Ups, my mistake. >> >> >> * gnu/services/music.scm (): New record type. >> >> (mpd-service): New service extension. >> >> (mpd-service-type): New service type. >> >> * gnu/tests/music.scm: New file. >> >> * gnu/local.mk: Add new files. >> >> >> >> --- >> >> doc/guix.texi | 53 +++++++++++++++++++++++++++++++ >> >> gnu/local.mk | 2 ++ >> >> gnu/services/music.scm | 84 >> >> ++++++++++++++++++++++++++++++++++++++++++++++++++ >> >> gnu/tests/music.scm | 83 >> >> +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, >> >> 222 insertions(+) create mode 100644 gnu/services/music.scm create >> >> mode 100644 gnu/tests/music.scm >> >> >> >> diff --git a/doc/guix.texi b/doc/guix.texi >> >> index 8f14ddd50..e565dfdc9 100644 >> >> --- a/doc/guix.texi >> >> +++ b/doc/guix.texi >> >> @@ -227,6 +227,7 @@ Services >> >> * Network File System:: NFS related services. >> >> * Continuous Integration:: The Cuirass service. >> >> * Power management Services:: The TLP tool. >> >> +* Music Services:: The MPD. >> >> * Miscellaneous Services:: Other services. >> >> >> >> Defining Services >> >> @@ -9035,6 +9036,7 @@ declaration. >> >> * Network File System:: NFS related services. >> >> * Continuous Integration:: The Cuirass service. >> >> * Power management Services:: The TLP tool. >> >> +* Music Services:: The MPD. >> >> * Miscellaneous Services:: Other services. >> >> @end menu >> >> >> >> @@ -15635,6 +15637,57 @@ Package object of thermald. >> >> @end table >> >> @end deftp >> >> >> >> +@node Music Services >> >> +@subsubsection Music Services >> > >> > I'm wondering if Audio services, rather than Music services might be >> > better? Maybe this would fit in other services related to audio, >> > e.g. Jack, MIDI stuff, etc... >> > >> >> That sounds like a good idea. >> >> >> +@cindex mpd >> >> +@subsubheading Music Player Daemon >> >> + >> >> +The @code{(gnu services music)} provides a service to start MPD >> >> (the Music +Player Daemon). It uses pulseaudio for output. >> >> + >> >> +@defvr {Scheme Variable} mpd-service-type >> >> +The service type for @command{mpd} >> >> +@end defvr >> >> + >> >> +@deftp {Data Type} mpd-configuration >> >> +Data type representing the configuration of @command{mpd}. >> >> + >> >> +@table @asis >> >> +@item @code{user} (default: @code{"mpd"}) >> >> +The user to run mpd as. >> >> + >> >> +@item @code{music-dir} (default: @code{"~/Music"}) >> >> +The directory to scan for music files. >> >> + >> >> +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) >> >> +The directory to store playlists. >> >> + >> >> +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) >> >> +The file mpd wil store its PID. >> >> + >> >> +@item @code{port} (default: @code{"6600"}) >> >> +The port to run mpd on. >> >> + >> >> +@item @code{address} (default: @code{"any"}) >> >> +The address that mpd will bind to. To use a Unix domain socket, >> >> +an absolute path can be specified here. >> > >> > The style for Guix is to use two spaces between sentences, I always >> > forget about this too. >> > >> >> Oh yes, me too. >> >> >> + >> >> +@end table >> >> +@end deftp >> >> + >> >> +@deffn {Scheme Procedure} mpd-service [#:config >> >> (mpd-configuration)] +Return a service that runs @code{mpd} using >> >> @var{configuration}, +a @code{} object. >> >> + >> >> +The following example shows how one might run @code{mpd} as user >> >> +@code{"bob"} on port @code{6666}. >> >> +@example >> >> +(mpd-service (mpd-configuration >> >> + (user "bob") >> >> + (port "6666"))) >> >> +@end example >> >> +@end deffn >> >> >> >> @node Miscellaneous Services >> >> @subsubsection Miscellaneous Services >> >> diff --git a/gnu/local.mk b/gnu/local.mk >> >> index b1ff72d6a..cad0ba38d 100644 >> >> --- a/gnu/local.mk >> >> +++ b/gnu/local.mk >> >> @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES >> >> =3D \ >> >> %D%/services/mail.scm \ >> >> %D%/services/mcron.scm \ >> >> %D%/services/messaging.scm \ >> >> + %D%/services/music.scm \ >> >> %D%/services/networking.scm \ >> >> %D%/services/nfs.scm \ >> >> %D%/services/shepherd.scm \ >> >> @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES >> >> =3D \ >> >> %D%/tests/install.scm \ >> >> %D%/tests/mail.scm \ >> >> %D%/tests/messaging.scm \ >> >> + %D%/tests/music.scm \ >> >> %D%/tests/networking.scm \ >> >> %D%/tests/ssh.scm \ >> >> %D%/tests/web.scm >> >> diff --git a/gnu/services/music.scm b/gnu/services/music.scm >> >> new file mode 100644 >> >> index 000000000..77912d5c6 >> >> --- /dev/null >> >> +++ b/gnu/services/music.scm >> >> @@ -0,0 +1,84 @@ >> >> +;;; GNU Guix --- Functional package management for GNU >> >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen >> >> +;;; >> >> +;;; This file is part of GNU Guix. >> >> +;;; >> >> +;;; GNU Guix is free software; you can redistribute it and/or >> >> modify it +;;; under the terms of the GNU General Public License as >> >> published by +;;; the Free Software Foundation; either version 3 of >> >> the License, or (at +;;; your option) any later version. >> >> +;;; >> >> +;;; GNU Guix is distributed in the hope that it will be useful, >> >> but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of >> >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> >> +;;; GNU General Public License for more details. >> >> +;;; >> >> +;;; You should have received a copy of the GNU General Public >> >> License +;;; along with GNU Guix. If not, see >> >> . + >> >> +(define-module (gnu services music) >> >> + #:use-module (guix gexp) >> >> + #:use-module (gnu services) >> >> + #:use-module (gnu services shepherd) >> >> + #:use-module (gnu packages mpd) >> >> + #:use-module (guix records) >> >> + #:export (mpd-configuration >> >> + mpd-configuration? >> >> + mpd-service >> >> + mpd-service-type)) >> >> + >> >> +;;; Commentary: >> >> +;;; >> >> +;;; Music related services >> >> +;;; >> >> +;;; Code: >> >> + >> >> +(define-record-type* >> >> + mpd-configuration make-mpd-configuration >> >> + mpd-configuration? >> >> + (user mpd-configuration-user >> >> + (default "mpd")) >> >> + (music-dir mpd-configuration-music-dir >> >> + (default "~/Music")) >> >> + (playlist-dir mpd-configuration-playlist-dir >> >> + (default "~/.mpd/playlists")) >> >> + (port mpd-configuration-port >> >> + (default "6600")) >> >> + (address mpd-configuration-address >> >> + (default "any")) >> >> + (pid-file mpd-configuration-pid-file >> >> + (default "~/.mpd-pid"))) >> >> + >> >> +(define (mpd-config->file config) >> >> + (apply >> >> + mixed-text-file "mpd.conf" >> >> + "audio_output {\n" >> >> + " type \"pulse\"\n" >> >> + " name \"MPD\"\n" >> >> + "}\n" >> >> + (map (lambda (config-line) >> >> + (let ((config-name (car config-line)) >> >> + (config-val (cadr config-line))) >> >> + (string-append config-name " \"" (config-val config) >> >> "\"\n"))) >> >> + `(("user" ,mpd-configuration-user) >> >> + ("music_directory" ,mpd-configuration-music-dir) >> >> + ("playlist_directory" ,mpd-configuration-playlist-dir) >> >> + ("port" ,mpd-configuration-port) >> >> + ("bind_to_address" ,mpd-configuration-address) >> >> + ("pid_file" ,mpd-configuration-pid-file))))) >> >> + >> >> +(define mpd-service-type >> >> + (shepherd-service-type >> >> + 'mpd >> >> + (lambda (config) >> >> + (shepherd-service >> >> + (documentation "Run the MPD (Music Player Daemon)") >> >> + (provision '(mpd)) >> >> + (start #~(make-forkexec-constructor >> >> + (list #$(file-append mpd "/bin/mpd") >> >> + "--no-daemon" >> >> + #$(mpd-config->file config)))) >> >> + (stop #~(make-kill-destructor)))))) >> >> + >> >> +(define* (mpd-service #:optional (config (mpd-configuration))) >> >> + (service mpd-service-type config)) >> > >> > I've been trying a slightly different style for this recently. At >> > the moment, if you had a configuration file for MPD, you couldn't >> > use this with the service here. One way of addressing this is to do >> > something like the Tailon service, and define a gexp compiler for >> > the configuration file (e.g. [1]). For the Tailon service, this >> > means that you should be able to pass your own configuration file >> > to the service. >> >> I am not sure I get how this works, and I would probs just make a big >> mess. What about we take my approach first, and then I can come back >> to it when I learn some more about guix? > > No problem. Looking at it again, I think it might be a bit trickier > than I initially assumed, as the pid-file value is used. > Oh i see. >> > Also, now that a can have a default-value, I think >> > its easier to just have the mpd-service-type, without the >> > mpd-service procedure. If you add a default value, you should be >> > able to do (service mpd-service-type). >> > >> Ok with me. >> >> > 1: >> > https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/admin.scm= #n255 >> > >> >> diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm >> >> new file mode 100644 >> >> index 000000000..158513098 >> >> --- /dev/null >> >> +++ b/gnu/tests/music.scm >> >> @@ -0,0 +1,83 @@ >> >> +;;; GNU Guix --- Functional package management for GNU >> >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen >> >> +;;; >> >> +;;; This file is part of GNU Guix. >> >> +;;; >> >> +;;; GNU Guix is free software; you can redistribute it and/or >> >> modify it +;;; under the terms of the GNU General Public License as >> >> published by +;;; the Free Software Foundation; either version 3 of >> >> the License, or (at +;;; your option) any later version. >> >> +;;; >> >> +;;; GNU Guix is distributed in the hope that it will be useful, >> >> but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of >> >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> >> +;;; GNU General Public License for more details. >> >> +;;; >> >> +;;; You should have received a copy of the GNU General Public >> >> License +;;; along with GNU Guix. If not, see >> >> . + >> >> +(define-module (gnu tests music) >> >> + #:use-module (gnu tests) >> >> + #:use-module (gnu system) >> >> + #:use-module (gnu system vm) >> >> + #:use-module (gnu services) >> >> + #:use-module (gnu services music) >> >> + #:use-module (gnu packages mpd) >> >> + #:use-module (guix gexp) >> >> + #:export (%test-mpd)) >> >> + >> >> +(define %mpd-os >> >> + (simple-operating-system >> >> + (mpd-service (mpd-configuration >> >> + (user "root"))))) >> >> + >> >> +(define (run-mpd-test) >> >> + "Run tests in %mpd-os, which has mpd running." >> >> + (define os >> >> + (marionette-operating-system >> >> + %mpd-os >> >> + #:imported-modules '((gnu services herd)))) >> >> + >> >> + (define vm >> >> + (virtual-machine os)) >> >> + >> >> + (define test >> >> + (with-imported-modules '((gnu build marionette)) >> >> + #~(begin >> >> + (use-modules (srfi srfi-64) >> >> + (gnu build marionette)) >> >> + (define marionette >> >> + (make-marionette (list #$vm))) >> >> + >> >> + (mkdir #$output) >> >> + (chdir #$output) >> >> + >> >> + (test-begin "mpd") >> >> + >> >> + (test-eq "service is running" >> >> + 'running! >> >> + (marionette-eval >> >> + '(begin >> >> + (use-modules (gnu services herd)) >> >> + (start-service 'mpd) >> >> + 'running!) >> >> + marionette)) >> > >> > Recently, the start-service procedure was changed to return the >> > information from the shepherd, and this can be used to make this >> > check a bit more rigorous. >> > >> > I've got an patch for the Memcached service which demonstrates this >> > here [2], as with the test above, it will not always fail, even if >> > the service fails to create the PID file. >> > >> > 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28021 >> > >> >> + (test-assert "pid file" >> >> + (wait-for-file "/root/.mpd-pid" >> >> + marionette)) >> > >> > If this is useful when using MPD, then I think it would be valuable >> > to get the shepherd to wait for the PID file. I think you can do >> > this by adding #:pid-file to the make-forkexec-constructor call. >> > >> > If you do this, them I'm not sure this test adds anything, as I >> > think the start-service call would only return successfully when >> > the service has started, and created the PID file. >> > >> >> Right, I have removed this test. > > Great. Just to check I wasn't wrong, I've just tested what happens if > you break the service by getting mpd to create the PID file, and > shepherd to look for it in different places, and the previous test > about starting the service does indeed fail, which is what we want :D > Great! >> >> + (test-assert "mpc connect" >> >> + (marionette-eval >> >> + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) >> >> + marionette)) >> >> + >> >> + (test-end) >> >> + (exit (=3D (test-runner-fail-count (test-runner-current)) >> >> 0))))) >> >> + (gexp->derivation "mpd-test" test)) >> >> + >> >> +(define %test-mpd >> >> + (system-test >> >> + (name "mpd") >> >> + (description "Test that the mpd can run and be connected to.") >> >> + (value (run-mpd-test)))) >> >> I think I have fixed all of your suggestions (apart from the >> gexp-compiler one). Please see my new patch. > > Awesome, I've put a couple more suggestions below, but just on the docs > and a bit of code style. Regardless of these, I think this is good to > go. > > >> From 419a8df59bc958ee87ece5519393b32cfbef609c Mon Sep 17 00:00:00 2001 >> From: Peter Mikkelsen >> Date: Sat, 12 Aug 2017 03:40:25 +0200 >> Subject: [PATCH] gnu: Add mpd service. >> >> * doc/guix.texi: Add documentation. >> * gnu/services/audio.scm (): New record type. >> (mpd-service-type): New service type. >> * gnu/tests/audio.scm: New file. >> * gnu/local.mk: Add new files. >> --- >> doc/guix.texi | 49 ++++++++++++++++++++++++++++ >> gnu/local.mk | 2 ++ >> gnu/services/audio.scm | 86 >> ++++++++++++++++++++++++++++++++++++++++++++++++++ >> gnu/tests/audio.scm | 78 >> +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 215 >> insertions(+) create mode 100644 gnu/services/audio.scm create mode >> 100644 gnu/tests/audio.scm >> >> diff --git a/doc/guix.texi b/doc/guix.texi >> index 8f14ddd50..754408ade 100644 >> --- a/doc/guix.texi >> +++ b/doc/guix.texi >> @@ -227,6 +227,7 @@ Services >> * Network File System:: NFS related services. >> * Continuous Integration:: The Cuirass service. >> * Power management Services:: The TLP tool. >> +* Audio Services:: The MPD. >> * Miscellaneous Services:: Other services. >> >> Defining Services >> @@ -9035,6 +9036,7 @@ declaration. >> * Network File System:: NFS related services. >> * Continuous Integration:: The Cuirass service. >> * Power management Services:: The TLP tool. >> +* Audio Services:: The MPD. >> * Miscellaneous Services:: Other services. >> @end menu >> >> @@ -15635,6 +15637,53 @@ Package object of thermald. >> @end table >> @end deftp >> >> +@node Audio Services >> +@subsubsection Audio Services >> + >> +@cindex mpd >> +@subsubheading Music Player Daemon >> + >> +The @code{(gnu services audio)} provides a service to start MPD (the >> Music +Player Daemon). It uses pulseaudio for output. >> + >> +@defvr {Scheme Variable} mpd-service-type >> +The service type for @command{mpd} >> +@end defvr >> + >> +@deftp {Data Type} mpd-configuration >> +Data type representing the configuration of @command{mpd}. >> + >> +@table @asis >> +@item @code{user} (default: @code{"mpd"}) >> +The user to run mpd as. >> + >> +@item @code{music-dir} (default: @code{"~/Music"}) >> +The directory to scan for music files. >> + >> +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) >> +The directory to store playlists. >> + >> +@item @code{pid-file} (default: @code{"/var/run/mpd.pid"}) >> +The file mpd wil store its PID. This must be an absolute path. >> + >> +@item @code{port} (default: @code{"6600"}) >> +The port to run mpd on. >> + >> +@item @code{address} (default: @code{"any"}) >> +The address that mpd will bind to. To use a Unix domain socket, >> +an absolute path can be specified here. >> + >> +@end table >> +@end deftp >> + >> +The following example shows how one might run @code{mpd} as user >> +@code{"bob"} on port @code{6666}. >> +@example >> +(service mpd-service-type >> + (mpd-configuration >> + (user "bob") >> + (port "6666"))) >> +@end example > > I've got a few suggestions for the docs. Nothing too important, and I'm > fine if you still prefer docs without the suggestions below, but feel > free to pick and choose any changes that you think are good, I've put > my reasoning inline in round brackets. > > > @node Audio Services > @subsubsection Audio Services > > The @code{(gnu services audio)} module provides a service to > start MPD (the Music Player Daemon). > > ( > Having the introduction to the module above the Music Player Daemon > subsubheading seems neater. Also, I think adding "module" after > @code{(gnu services audio)} helps with readability. > ) > > @cindex mpd > @subsubheading Music Player Daemon > > The Music Player Daemon (MPD) is a service that can play music while > being controlled from the local machine or over the network by a > variety of clients. > > ( > An introductory paragraph about what the service does might be > useful, so I've written one above. > ) > > The following example shows how one might run @code{mpd} as user > @code{"bob"} on port @code{6666}. It uses pulseaudio for output. > > @example > (service mpd-service-type > (mpd-configuration > (user "bob") > (port "6666"))) > @end example > > ( > Moving the example here might be more visible, rather than below the > reference documentation. > ) > > @defvr {Scheme Variable} mpd-service-type > The service type for @command{mpd} > @end defvr > > @deftp {Data Type} mpd-configuration > Data type representing the configuration of @command{mpd}. > > ... > > @end table > @end deftp > > I like all your suggestions and they are all part of the new patch, thanks! >> @node Miscellaneous Services >> @subsubsection Miscellaneous Services >> diff --git a/gnu/local.mk b/gnu/local.mk >> index cffb18d3a..c12fd8559 100644 >> --- a/gnu/local.mk >> +++ b/gnu/local.mk >> @@ -426,6 +426,7 @@ GNU_SYSTEM_MODULES >> =3D \ \ >> %D%/services.scm \ >> %D%/services/admin.scm \ >> + %D%/services/audio.scm \ >> %D%/services/avahi.scm \ >> %D%/services/base.scm \ >> %D%/services/configuration.scm \ >> @@ -481,6 +482,7 @@ GNU_SYSTEM_MODULES >> =3D \ \ >> %D%/tests.scm \ >> %D%/tests/admin.scm \ >> + %D%/tests/audio.scm \ >> %D%/tests/base.scm \ >> %D%/tests/databases.scm \ >> %D%/tests/dict.scm \ >> diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm >> new file mode 100644 >> index 000000000..f5c465341 >> --- /dev/null >> +++ b/gnu/services/audio.scm >> @@ -0,0 +1,86 @@ >> +;;; GNU Guix --- Functional package management for GNU >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen >> +;;; >> +;;; This file is part of GNU Guix. >> +;;; >> +;;; GNU Guix is free software; you can redistribute it and/or modify >> it +;;; under the terms of the GNU General Public License as >> published by +;;; the Free Software Foundation; either version 3 of >> the License, or (at +;;; your option) any later version. >> +;;; >> +;;; GNU Guix is distributed in the hope that it will be useful, but >> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> +;;; GNU General Public License for more details. >> +;;; >> +;;; You should have received a copy of the GNU General Public License >> +;;; along with GNU Guix. If not, see . >> + >> +(define-module (gnu services audio) >> + #:use-module (guix gexp) >> + #:use-module (gnu services) >> + #:use-module (gnu services shepherd) >> + #:use-module (gnu packages mpd) >> + #:use-module (guix records) >> + #:export (mpd-configuration >> + mpd-configuration? >> + mpd-service-type)) >> + >> +;;; Commentary: >> +;;; >> +;;; Audio related services >> +;;; >> +;;; Code: >> + >> +(define-record-type* >> + mpd-configuration make-mpd-configuration >> + mpd-configuration? >> + (user mpd-configuration-user >> + (default "mpd")) >> + (music-dir mpd-configuration-music-dir >> + (default "~/Music")) >> + (playlist-dir mpd-configuration-playlist-dir >> + (default "~/.mpd/playlists")) >> + (port mpd-configuration-port >> + (default "6600")) >> + (address mpd-configuration-address >> + (default "any")) >> + (pid-file mpd-configuration-pid-file >> + (default "/var/run/mpd.pid"))) >> + >> +(define (mpd-config->file config) >> + (apply >> + mixed-text-file "mpd.conf" >> + "audio_output {\n" >> + " type \"pulse\"\n" >> + " name \"MPD\"\n" >> + "}\n" >> + (map (lambda (config-line) >> + (let ((config-name (car config-line)) >> + (config-val (cadr config-line))) >> + (string-append config-name " \"" (config-val config) >> "\"\n"))) > > One way of making this a bit more concise and remove the need for car > and cadr is to use the match module (ice-9 match). > > (map (match-lambda > ((config-name config-val) > (string-append config-name " \"" (config-val config) "\"\n"))) > ... > > I didn't know about match-lambda, but it seems pretty neat, so I used your example here, thanks. >> + `(("user" ,mpd-configuration-user) >> + ("music_directory" ,mpd-configuration-music-dir) >> + ("playlist_directory" ,mpd-configuration-playlist-dir) >> + ("port" ,mpd-configuration-port) >> + ("bind_to_address" ,mpd-configuration-address) >> + ("pid_file" ,mpd-configuration-pid-file))))) >> + > > ... --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-gnu-Add-mpd-service.patch Content-Transfer-Encoding: quoted-printable >From 54850337156401f92b836580a8340c3e250ecc61 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sat, 12 Aug 2017 03:40:25 +0200 Subject: [PATCH] gnu: Add mpd service. * doc/guix.texi: Add documentation. * gnu/services/audio.scm (): New record type. (mpd-service-type): New service type. * gnu/tests/audio.scm: New file. * gnu/local.mk: Add new files. --- doc/guix.texi | 54 +++++++++++++++++++++++++++++++ gnu/local.mk | 2 ++ gnu/services/audio.scm | 86 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ gnu/tests/audio.scm | 78 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 gnu/services/audio.scm create mode 100644 gnu/tests/audio.scm diff --git a/doc/guix.texi b/doc/guix.texi index 8f14ddd50..2f8a2efd0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -227,6 +227,7 @@ Services * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. * Power management Services:: The TLP tool. +* Audio Services:: The MPD. * Miscellaneous Services:: Other services. =20 Defining Services @@ -9035,6 +9036,7 @@ declaration. * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. * Power management Services:: The TLP tool. +* Audio Services:: The MPD. * Miscellaneous Services:: Other services. @end menu =20 @@ -15635,6 +15637,58 @@ Package object of thermald. @end table @end deftp =20 +@node Audio Services +@subsubsection Audio Services + +The @code{(gnu services audio)} module provides a service to start MPD +(the Music Player Daemon). + +@cindex mpd +@subsubheading Music Player Daemon + +The Music Player Daemon (MPD) is a service that can play music while +being controlled from the local machine or over the network by a variety +of clients. + +The following example shows how one might run @code{mpd} as user +@code{"bob"} on port @code{6666}. It uses pulseaudio for output. + +@example +(service mpd-service-type + (mpd-configuration + (user "bob") + (port "6666"))) +@end example + +@defvr {Scheme Variable} mpd-service-type +The service type for @command{mpd} +@end defvr + +@deftp {Data Type} mpd-configuration +Data type representing the configuration of @command{mpd}. + +@table @asis +@item @code{user} (default: @code{"mpd"}) +The user to run mpd as. + +@item @code{music-dir} (default: @code{"~/Music"}) +The directory to scan for music files. + +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) +The directory to store playlists. + +@item @code{pid-file} (default: @code{"/var/run/mpd.pid"}) +The file mpd wil store its PID. This must be an absolute path. + +@item @code{port} (default: @code{"6600"}) +The port to run mpd on. + +@item @code{address} (default: @code{"any"}) +The address that mpd will bind to. To use a Unix domain socket, +an absolute path can be specified here. + +@end table +@end deftp =20 @node Miscellaneous Services @subsubsection Miscellaneous Services diff --git a/gnu/local.mk b/gnu/local.mk index cffb18d3a..c12fd8559 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -426,6 +426,7 @@ GNU_SYSTEM_MODULES =3D \ \ %D%/services.scm \ %D%/services/admin.scm \ + %D%/services/audio.scm \ %D%/services/avahi.scm \ %D%/services/base.scm \ %D%/services/configuration.scm \ @@ -481,6 +482,7 @@ GNU_SYSTEM_MODULES =3D \ \ %D%/tests.scm \ %D%/tests/admin.scm \ + %D%/tests/audio.scm \ %D%/tests/base.scm \ %D%/tests/databases.scm \ %D%/tests/dict.scm \ diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm new file mode 100644 index 000000000..22814a6c0 --- /dev/null +++ b/gnu/services/audio.scm @@ -0,0 +1,86 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2017 Peter Mikkelsen +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services audio) + #:use-module (guix gexp) + #:use-module (gnu services) + #:use-module (gnu services shepherd) + #:use-module (gnu packages mpd) + #:use-module (guix records) + #:use-module (ice-9 match) + #:export (mpd-configuration + mpd-configuration? + mpd-service-type)) + +;;; Commentary: +;;; +;;; Audio related services +;;; +;;; Code: + +(define-record-type* + mpd-configuration make-mpd-configuration + mpd-configuration? + (user mpd-configuration-user + (default "mpd")) + (music-dir mpd-configuration-music-dir + (default "~/Music")) + (playlist-dir mpd-configuration-playlist-dir + (default "~/.mpd/playlists")) + (port mpd-configuration-port + (default "6600")) + (address mpd-configuration-address + (default "any")) + (pid-file mpd-configuration-pid-file + (default "/var/run/mpd.pid"))) + +(define (mpd-config->file config) + (apply + mixed-text-file "mpd.conf" + "audio_output {\n" + " type \"pulse\"\n" + " name \"MPD\"\n" + "}\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) + ("port" ,mpd-configuration-port) + ("bind_to_address" ,mpd-configuration-address) + ("pid_file" ,mpd-configuration-pid-file))))) + +(define (mpd-service config) + (shepherd-service + (documentation "Run the MPD (Music Player Daemon)") + (provision '(mpd)) + (start #~(make-forkexec-constructor + (list #$(file-append mpd "/bin/mpd") + "--no-daemon" + #$(mpd-config->file config)) + #:pid-file #$(mpd-configuration-pid-file config))) + (stop #~(make-kill-destructor)))) + +(define mpd-service-type + (service-type + (name 'mpd) + (extensions + (list (service-extension shepherd-root-service-type + (compose list mpd-service)))) + (default-value (mpd-configuration)))) diff --git a/gnu/tests/audio.scm b/gnu/tests/audio.scm new file mode 100644 index 000000000..8eadaf02e --- /dev/null +++ b/gnu/tests/audio.scm @@ -0,0 +1,78 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2017 Peter Mikkelsen +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu tests audio) + #:use-module (gnu tests) + #:use-module (gnu system) + #:use-module (gnu system vm) + #:use-module (gnu services) + #:use-module (gnu services audio) + #:use-module (gnu packages mpd) + #:use-module (guix gexp) + #:export (%test-mpd)) + +(define %mpd-os + (simple-operating-system + (service mpd-service-type + (mpd-configuration + (user "root"))))) + +(define (run-mpd-test) + "Run tests in %mpd-os, which has mpd running." + (define os + (marionette-operating-system + %mpd-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine os)) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-64) + (gnu build marionette)) + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "mpd") + + (test-assert "service is running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'mpd)) + marionette)) + + (test-assert "mpc connect" + (marionette-eval + '(zero? (system #$(file-append mpd-mpc "/bin/mpc"))) + marionette)) + + (test-end) + (exit (=3D (test-runner-fail-count (test-runner-current)) 0))))) + (gexp->derivation "mpd-test" test)) + +(define %test-mpd + (system-test + (name "mpd") + (description "Test that the mpd can run and be connected to.") + (value (run-mpd-test)))) --=20 2.14.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 13 03:15:24 2017 Received: (at 28059-done) by debbugs.gnu.org; 13 Aug 2017 07:15:24 +0000 Received: from localhost ([127.0.0.1]:59112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgn7L-0005Hh-A2 for submit@debbugs.gnu.org; Sun, 13 Aug 2017 03:15:24 -0400 Received: from li622-129.members.linode.com ([212.71.249.129]:52767 helo=mira.cbaines.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dgn7H-0005Hb-Ts for 28059-done@debbugs.gnu.org; Sun, 13 Aug 2017 03:15:22 -0400 Received: by mira.cbaines.net (Postfix, from userid 113) id 1034613E3E4; Sun, 13 Aug 2017 08:15:19 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (17.71.125.91.dyn.plus.net [91.125.71.17]) by mira.cbaines.net (Postfix) with ESMTPSA id 11A8F13E3E2; Sun, 13 Aug 2017 08:15:17 +0100 (BST) Date: Sun, 13 Aug 2017 08:15:10 +0100 From: Christopher Baines To: Peter Mikkelsen Subject: Re: [bug#28059] [PATCH] gnu: Add mpd service. Message-ID: <20170813081510.0c06683c@cbaines.net> In-Reply-To: <87wp68cujv.fsf@gmail.com> References: <20170812015211.5411-1-petermikkelsen10@gmail.com> <20170812115011.4c076108@cbaines.net> <87a834u2z3.fsf@gmail.com> <20170812215833.0b957af6@cbaines.net> <87wp68cujv.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/nENCve.rh+HWAjhYskz=319"; protocol="application/pgp-signature" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 28059-done Cc: 28059-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --Sig_/nENCve.rh+HWAjhYskz=319 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, 13 Aug 2017 00:04:04 +0200 Peter Mikkelsen wrote: > Christopher Baines writes: >=20 > > On Sat, 12 Aug 2017 19:10:08 +0200 > > Peter Mikkelsen wrote: > > =20 > >> Hi, thanks for the quick review! > >> > >> Christopher Baines writes: > >> =20 > >> > Hey, > >> > > >> > This looks great Peter, awesome job :) I've made some notes about > >> > potential improvements inline below. > >> > > >> > I've succeeded in running the system test locally, but there was > >> > some suspicious output in the log: > >> > > >> > exception: bind to '0.0.0.0:6600' failed (continuing anyway, > >> > because binding to '[::]:6600' succeeded): Failed to bind > >> > socket: Address already in use exception: Failed to > >> > access /root/.mpd/playlists: No such file or directory > >> > =20 > >> > >> This is pretty normal for mpd, and I believe happens because it > >> first binds on IPv6 and then fails for IPv4. The error about the > >> playlist dir happens because it does not exist, but AFAIK it is no > >> problem unless you want to save playlists. The user can just > >> create the dir. =20 > > > > Ok, good to know :) > > =20 > >> > On Sat, 12 Aug 2017 03:52:11 +0200 > >> > Peter Mikkelsen wrote: =20 > >> >> * doc/guix.text: Add documentation. =20 > >> > > >> > Typo above, text rather than texi. > >> > =20 > >> > >> Ups, my mistake. > >> =20 > >> >> * gnu/services/music.scm (): New record type. > >> >> (mpd-service): New service extension. > >> >> (mpd-service-type): New service type. > >> >> * gnu/tests/music.scm: New file. > >> >> * gnu/local.mk: Add new files. > >> >> > >> >> --- > >> >> doc/guix.texi | 53 +++++++++++++++++++++++++++++++ > >> >> gnu/local.mk | 2 ++ > >> >> gnu/services/music.scm | 84 > >> >> ++++++++++++++++++++++++++++++++++++++++++++++++++ > >> >> gnu/tests/music.scm | 83 > >> >> +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files > >> >> changed, 222 insertions(+) create mode 100644 > >> >> gnu/services/music.scm create mode 100644 gnu/tests/music.scm > >> >> > >> >> diff --git a/doc/guix.texi b/doc/guix.texi > >> >> index 8f14ddd50..e565dfdc9 100644 > >> >> --- a/doc/guix.texi > >> >> +++ b/doc/guix.texi > >> >> @@ -227,6 +227,7 @@ Services > >> >> * Network File System:: NFS related services. > >> >> * Continuous Integration:: The Cuirass service. > >> >> * Power management Services:: The TLP tool. > >> >> +* Music Services:: The MPD. > >> >> * Miscellaneous Services:: Other services. > >> >> > >> >> Defining Services > >> >> @@ -9035,6 +9036,7 @@ declaration. > >> >> * Network File System:: NFS related services. > >> >> * Continuous Integration:: The Cuirass service. > >> >> * Power management Services:: The TLP tool. > >> >> +* Music Services:: The MPD. > >> >> * Miscellaneous Services:: Other services. > >> >> @end menu > >> >> > >> >> @@ -15635,6 +15637,57 @@ Package object of thermald. > >> >> @end table > >> >> @end deftp > >> >> > >> >> +@node Music Services > >> >> +@subsubsection Music Services =20 > >> > > >> > I'm wondering if Audio services, rather than Music services > >> > might be better? Maybe this would fit in other services related > >> > to audio, e.g. Jack, MIDI stuff, etc... > >> > =20 > >> > >> That sounds like a good idea. > >> =20 > >> >> +@cindex mpd > >> >> +@subsubheading Music Player Daemon > >> >> + > >> >> +The @code{(gnu services music)} provides a service to start MPD > >> >> (the Music +Player Daemon). It uses pulseaudio for output. > >> >> + > >> >> +@defvr {Scheme Variable} mpd-service-type > >> >> +The service type for @command{mpd} > >> >> +@end defvr > >> >> + > >> >> +@deftp {Data Type} mpd-configuration > >> >> +Data type representing the configuration of @command{mpd}. > >> >> + > >> >> +@table @asis > >> >> +@item @code{user} (default: @code{"mpd"}) > >> >> +The user to run mpd as. > >> >> + > >> >> +@item @code{music-dir} (default: @code{"~/Music"}) > >> >> +The directory to scan for music files. > >> >> + > >> >> +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) > >> >> +The directory to store playlists. > >> >> + > >> >> +@item @code{pid-file} (default: @code{"~/.mpd-pid"}) > >> >> +The file mpd wil store its PID. > >> >> + > >> >> +@item @code{port} (default: @code{"6600"}) > >> >> +The port to run mpd on. > >> >> + > >> >> +@item @code{address} (default: @code{"any"}) > >> >> +The address that mpd will bind to. To use a Unix domain socket, > >> >> +an absolute path can be specified here. =20 > >> > > >> > The style for Guix is to use two spaces between sentences, I > >> > always forget about this too. > >> > =20 > >> > >> Oh yes, me too. > >> =20 > >> >> + > >> >> +@end table > >> >> +@end deftp > >> >> + > >> >> +@deffn {Scheme Procedure} mpd-service [#:config > >> >> (mpd-configuration)] +Return a service that runs @code{mpd} > >> >> using @var{configuration}, +a @code{} object. > >> >> + > >> >> +The following example shows how one might run @code{mpd} as > >> >> user +@code{"bob"} on port @code{6666}. > >> >> +@example > >> >> +(mpd-service (mpd-configuration > >> >> + (user "bob") > >> >> + (port "6666"))) > >> >> +@end example > >> >> +@end deffn > >> >> > >> >> @node Miscellaneous Services > >> >> @subsubsection Miscellaneous Services > >> >> diff --git a/gnu/local.mk b/gnu/local.mk > >> >> index b1ff72d6a..cad0ba38d 100644 > >> >> --- a/gnu/local.mk > >> >> +++ b/gnu/local.mk > >> >> @@ -441,6 +441,7 @@ GNU_SYSTEM_MODULES > >> >> =3D \ > >> >> %D%/services/mail.scm \ > >> >> %D%/services/mcron.scm \ > >> >> %D%/services/messaging.scm \ > >> >> + %D%/services/music.scm \ > >> >> %D%/services/networking.scm \ > >> >> %D%/services/nfs.scm \ > >> >> %D%/services/shepherd.scm \ > >> >> @@ -488,6 +489,7 @@ GNU_SYSTEM_MODULES > >> >> =3D \ > >> >> %D%/tests/install.scm \ > >> >> %D%/tests/mail.scm \ > >> >> %D%/tests/messaging.scm \ > >> >> + %D%/tests/music.scm \ > >> >> %D%/tests/networking.scm \ > >> >> %D%/tests/ssh.scm \ > >> >> %D%/tests/web.scm > >> >> diff --git a/gnu/services/music.scm b/gnu/services/music.scm > >> >> new file mode 100644 > >> >> index 000000000..77912d5c6 > >> >> --- /dev/null > >> >> +++ b/gnu/services/music.scm > >> >> @@ -0,0 +1,84 @@ > >> >> +;;; GNU Guix --- Functional package management for GNU > >> >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen > >> >> +;;; > >> >> +;;; This file is part of GNU Guix. > >> >> +;;; > >> >> +;;; GNU Guix is free software; you can redistribute it and/or > >> >> modify it +;;; under the terms of the GNU General Public > >> >> License as published by +;;; the Free Software Foundation; > >> >> either version 3 of the License, or (at +;;; your option) any > >> >> later version. +;;; > >> >> +;;; GNU Guix is distributed in the hope that it will be useful, > >> >> but +;;; WITHOUT ANY WARRANTY; without even the implied > >> >> warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR > >> >> PURPOSE. See the +;;; GNU General Public License for more > >> >> details. +;;; > >> >> +;;; You should have received a copy of the GNU General Public > >> >> License +;;; along with GNU Guix. If not, see > >> >> . + > >> >> +(define-module (gnu services music) > >> >> + #:use-module (guix gexp) > >> >> + #:use-module (gnu services) > >> >> + #:use-module (gnu services shepherd) > >> >> + #:use-module (gnu packages mpd) > >> >> + #:use-module (guix records) > >> >> + #:export (mpd-configuration > >> >> + mpd-configuration? > >> >> + mpd-service > >> >> + mpd-service-type)) > >> >> + > >> >> +;;; Commentary: > >> >> +;;; > >> >> +;;; Music related services > >> >> +;;; > >> >> +;;; Code: > >> >> + > >> >> +(define-record-type* > >> >> + mpd-configuration make-mpd-configuration > >> >> + mpd-configuration? > >> >> + (user mpd-configuration-user > >> >> + (default "mpd")) > >> >> + (music-dir mpd-configuration-music-dir > >> >> + (default "~/Music")) > >> >> + (playlist-dir mpd-configuration-playlist-dir > >> >> + (default "~/.mpd/playlists")) > >> >> + (port mpd-configuration-port > >> >> + (default "6600")) > >> >> + (address mpd-configuration-address > >> >> + (default "any")) > >> >> + (pid-file mpd-configuration-pid-file > >> >> + (default "~/.mpd-pid"))) > >> >> + > >> >> +(define (mpd-config->file config) > >> >> + (apply > >> >> + mixed-text-file "mpd.conf" > >> >> + "audio_output {\n" > >> >> + " type \"pulse\"\n" > >> >> + " name \"MPD\"\n" > >> >> + "}\n" > >> >> + (map (lambda (config-line) > >> >> + (let ((config-name (car config-line)) > >> >> + (config-val (cadr config-line))) > >> >> + (string-append config-name " \"" (config-val > >> >> config) "\"\n"))) > >> >> + `(("user" ,mpd-configuration-user) > >> >> + ("music_directory" ,mpd-configuration-music-dir) > >> >> + > >> >> ("playlist_directory" ,mpd-configuration-playlist-dir) > >> >> + ("port" ,mpd-configuration-port) > >> >> + ("bind_to_address" ,mpd-configuration-address) > >> >> + ("pid_file" ,mpd-configuration-pid-file))))) > >> >> + > >> >> +(define mpd-service-type > >> >> + (shepherd-service-type > >> >> + 'mpd > >> >> + (lambda (config) > >> >> + (shepherd-service > >> >> + (documentation "Run the MPD (Music Player Daemon)") > >> >> + (provision '(mpd)) > >> >> + (start #~(make-forkexec-constructor > >> >> + (list #$(file-append mpd "/bin/mpd") > >> >> + "--no-daemon" > >> >> + #$(mpd-config->file config)))) > >> >> + (stop #~(make-kill-destructor)))))) > >> >> + > >> >> +(define* (mpd-service #:optional (config (mpd-configuration))) > >> >> + (service mpd-service-type config)) =20 > >> > > >> > I've been trying a slightly different style for this recently. At > >> > the moment, if you had a configuration file for MPD, you couldn't > >> > use this with the service here. One way of addressing this is to > >> > do something like the Tailon service, and define a gexp compiler > >> > for the configuration file (e.g. [1]). For the Tailon service, > >> > this means that you should be able to pass your own > >> > configuration file to the service. =20 > >> > >> I am not sure I get how this works, and I would probs just make a > >> big mess. What about we take my approach first, and then I can > >> come back to it when I learn some more about guix? =20 > > > > No problem. Looking at it again, I think it might be a bit trickier > > than I initially assumed, as the pid-file value is used. > > =20 > Oh i see. > >> > Also, now that a can have a default-value, I think > >> > its easier to just have the mpd-service-type, without the > >> > mpd-service procedure. If you add a default value, you should be > >> > able to do (service mpd-service-type). > >> > =20 > >> Ok with me. > >> =20 > >> > 1: > >> > https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/admin.s= cm#n255 > >> > =20 > >> >> diff --git a/gnu/tests/music.scm b/gnu/tests/music.scm > >> >> new file mode 100644 > >> >> index 000000000..158513098 > >> >> --- /dev/null > >> >> +++ b/gnu/tests/music.scm > >> >> @@ -0,0 +1,83 @@ > >> >> +;;; GNU Guix --- Functional package management for GNU > >> >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen > >> >> +;;; > >> >> +;;; This file is part of GNU Guix. > >> >> +;;; > >> >> +;;; GNU Guix is free software; you can redistribute it and/or > >> >> modify it +;;; under the terms of the GNU General Public > >> >> License as published by +;;; the Free Software Foundation; > >> >> either version 3 of the License, or (at +;;; your option) any > >> >> later version. +;;; > >> >> +;;; GNU Guix is distributed in the hope that it will be useful, > >> >> but +;;; WITHOUT ANY WARRANTY; without even the implied > >> >> warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR > >> >> PURPOSE. See the +;;; GNU General Public License for more > >> >> details. +;;; > >> >> +;;; You should have received a copy of the GNU General Public > >> >> License +;;; along with GNU Guix. If not, see > >> >> . + > >> >> +(define-module (gnu tests music) > >> >> + #:use-module (gnu tests) > >> >> + #:use-module (gnu system) > >> >> + #:use-module (gnu system vm) > >> >> + #:use-module (gnu services) > >> >> + #:use-module (gnu services music) > >> >> + #:use-module (gnu packages mpd) > >> >> + #:use-module (guix gexp) > >> >> + #:export (%test-mpd)) > >> >> + > >> >> +(define %mpd-os > >> >> + (simple-operating-system > >> >> + (mpd-service (mpd-configuration > >> >> + (user "root"))))) > >> >> + > >> >> +(define (run-mpd-test) > >> >> + "Run tests in %mpd-os, which has mpd running." > >> >> + (define os > >> >> + (marionette-operating-system > >> >> + %mpd-os > >> >> + #:imported-modules '((gnu services herd)))) > >> >> + > >> >> + (define vm > >> >> + (virtual-machine os)) > >> >> + > >> >> + (define test > >> >> + (with-imported-modules '((gnu build marionette)) > >> >> + #~(begin > >> >> + (use-modules (srfi srfi-64) > >> >> + (gnu build marionette)) > >> >> + (define marionette > >> >> + (make-marionette (list #$vm))) > >> >> + > >> >> + (mkdir #$output) > >> >> + (chdir #$output) > >> >> + > >> >> + (test-begin "mpd") > >> >> + > >> >> + (test-eq "service is running" > >> >> + 'running! > >> >> + (marionette-eval > >> >> + '(begin > >> >> + (use-modules (gnu services herd)) > >> >> + (start-service 'mpd) > >> >> + 'running!) > >> >> + marionette)) =20 > >> > > >> > Recently, the start-service procedure was changed to return the > >> > information from the shepherd, and this can be used to make this > >> > check a bit more rigorous. > >> > > >> > I've got an patch for the Memcached service which demonstrates > >> > this here [2], as with the test above, it will not always fail, > >> > even if the service fails to create the PID file. > >> > > >> > 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28021 > >> > =20 > >> >> + (test-assert "pid file" > >> >> + (wait-for-file "/root/.mpd-pid" > >> >> + marionette)) =20 > >> > > >> > If this is useful when using MPD, then I think it would be > >> > valuable to get the shepherd to wait for the PID file. I think > >> > you can do this by adding #:pid-file to the > >> > make-forkexec-constructor call. > >> > > >> > If you do this, them I'm not sure this test adds anything, as I > >> > think the start-service call would only return successfully when > >> > the service has started, and created the PID file. > >> > =20 > >> > >> Right, I have removed this test. =20 > > > > Great. Just to check I wasn't wrong, I've just tested what happens > > if you break the service by getting mpd to create the PID file, and > > shepherd to look for it in different places, and the previous test > > about starting the service does indeed fail, which is what we > > want :D=20 >=20 > Great! > >> >> + (test-assert "mpc connect" > >> >> + (marionette-eval > >> >> + '(zero? (system #$(file-append mpd-mpc > >> >> "/bin/mpc"))) > >> >> + marionette)) > >> >> + > >> >> + (test-end) > >> >> + (exit (=3D (test-runner-fail-count > >> >> (test-runner-current)) 0))))) > >> >> + (gexp->derivation "mpd-test" test)) > >> >> + > >> >> +(define %test-mpd > >> >> + (system-test > >> >> + (name "mpd") > >> >> + (description "Test that the mpd can run and be connected > >> >> to.") > >> >> + (value (run-mpd-test)))) =20 > >> > >> I think I have fixed all of your suggestions (apart from the > >> gexp-compiler one). Please see my new patch. =20 > > > > Awesome, I've put a couple more suggestions below, but just on the > > docs and a bit of code style. Regardless of these, I think this is > > good to go. > > > > =20 > >> From 419a8df59bc958ee87ece5519393b32cfbef609c Mon Sep 17 00:00:00 > >> 2001 From: Peter Mikkelsen > >> Date: Sat, 12 Aug 2017 03:40:25 +0200 > >> Subject: [PATCH] gnu: Add mpd service. > >> > >> * doc/guix.texi: Add documentation. > >> * gnu/services/audio.scm (): New record type. > >> (mpd-service-type): New service type. > >> * gnu/tests/audio.scm: New file. > >> * gnu/local.mk: Add new files. > >> --- > >> doc/guix.texi | 49 ++++++++++++++++++++++++++++ > >> gnu/local.mk | 2 ++ > >> gnu/services/audio.scm | 86 > >> ++++++++++++++++++++++++++++++++++++++++++++++++++ > >> gnu/tests/audio.scm | 78 > >> +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 215 > >> insertions(+) create mode 100644 gnu/services/audio.scm create mode > >> 100644 gnu/tests/audio.scm > >> > >> diff --git a/doc/guix.texi b/doc/guix.texi > >> index 8f14ddd50..754408ade 100644 > >> --- a/doc/guix.texi > >> +++ b/doc/guix.texi > >> @@ -227,6 +227,7 @@ Services > >> * Network File System:: NFS related services. > >> * Continuous Integration:: The Cuirass service. > >> * Power management Services:: The TLP tool. > >> +* Audio Services:: The MPD. > >> * Miscellaneous Services:: Other services. > >> > >> Defining Services > >> @@ -9035,6 +9036,7 @@ declaration. > >> * Network File System:: NFS related services. > >> * Continuous Integration:: The Cuirass service. > >> * Power management Services:: The TLP tool. > >> +* Audio Services:: The MPD. > >> * Miscellaneous Services:: Other services. > >> @end menu > >> > >> @@ -15635,6 +15637,53 @@ Package object of thermald. > >> @end table > >> @end deftp > >> > >> +@node Audio Services > >> +@subsubsection Audio Services > >> + > >> +@cindex mpd > >> +@subsubheading Music Player Daemon > >> + > >> +The @code{(gnu services audio)} provides a service to start MPD > >> (the Music +Player Daemon). It uses pulseaudio for output. > >> + > >> +@defvr {Scheme Variable} mpd-service-type > >> +The service type for @command{mpd} > >> +@end defvr > >> + > >> +@deftp {Data Type} mpd-configuration > >> +Data type representing the configuration of @command{mpd}. > >> + > >> +@table @asis > >> +@item @code{user} (default: @code{"mpd"}) > >> +The user to run mpd as. > >> + > >> +@item @code{music-dir} (default: @code{"~/Music"}) > >> +The directory to scan for music files. > >> + > >> +@item @code{playlist-dir} (default: @code{"~/.mpd/playlists"}) > >> +The directory to store playlists. > >> + > >> +@item @code{pid-file} (default: @code{"/var/run/mpd.pid"}) > >> +The file mpd wil store its PID. This must be an absolute path. > >> + > >> +@item @code{port} (default: @code{"6600"}) > >> +The port to run mpd on. > >> + > >> +@item @code{address} (default: @code{"any"}) > >> +The address that mpd will bind to. To use a Unix domain socket, > >> +an absolute path can be specified here. > >> + > >> +@end table > >> +@end deftp > >> + > >> +The following example shows how one might run @code{mpd} as user > >> +@code{"bob"} on port @code{6666}. > >> +@example > >> +(service mpd-service-type > >> + (mpd-configuration > >> + (user "bob") > >> + (port "6666"))) > >> +@end example =20 > > > > I've got a few suggestions for the docs. Nothing too important, and > > I'm fine if you still prefer docs without the suggestions below, > > but feel free to pick and choose any changes that you think are > > good, I've put my reasoning inline in round brackets. > > > > > > @node Audio Services > > @subsubsection Audio Services > > > > The @code{(gnu services audio)} module provides a service to > > start MPD (the Music Player Daemon). > > > > ( > > Having the introduction to the module above the Music Player > > Daemon subsubheading seems neater. Also, I think adding "module" > > after @code{(gnu services audio)} helps with readability. > > ) > > > > @cindex mpd > > @subsubheading Music Player Daemon > > > > The Music Player Daemon (MPD) is a service that can play music while > > being controlled from the local machine or over the network by a > > variety of clients. > > > > ( > > An introductory paragraph about what the service does might be > > useful, so I've written one above. > > ) > > > > The following example shows how one might run @code{mpd} as user > > @code{"bob"} on port @code{6666}. It uses pulseaudio for output. > > > > @example > > (service mpd-service-type > > (mpd-configuration > > (user "bob") > > (port "6666"))) > > @end example > > > > ( > > Moving the example here might be more visible, rather than below > > the reference documentation. > > ) > > > > @defvr {Scheme Variable} mpd-service-type > > The service type for @command{mpd} > > @end defvr > > > > @deftp {Data Type} mpd-configuration > > Data type representing the configuration of @command{mpd}. > > > > ... > > > > @end table > > @end deftp > > > > =20 > I like all your suggestions and they are all part of the new patch, > thanks! > >> @node Miscellaneous Services > >> @subsubsection Miscellaneous Services > >> diff --git a/gnu/local.mk b/gnu/local.mk > >> index cffb18d3a..c12fd8559 100644 > >> --- a/gnu/local.mk > >> +++ b/gnu/local.mk > >> @@ -426,6 +426,7 @@ GNU_SYSTEM_MODULES > >> =3D \ \ > >> %D%/services.scm \ > >> %D%/services/admin.scm \ > >> + %D%/services/audio.scm \ > >> %D%/services/avahi.scm \ > >> %D%/services/base.scm \ > >> %D%/services/configuration.scm \ > >> @@ -481,6 +482,7 @@ GNU_SYSTEM_MODULES > >> =3D \ \ > >> %D%/tests.scm \ > >> %D%/tests/admin.scm \ > >> + %D%/tests/audio.scm \ > >> %D%/tests/base.scm \ > >> %D%/tests/databases.scm \ > >> %D%/tests/dict.scm \ > >> diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm > >> new file mode 100644 > >> index 000000000..f5c465341 > >> --- /dev/null > >> +++ b/gnu/services/audio.scm > >> @@ -0,0 +1,86 @@ > >> +;;; GNU Guix --- Functional package management for GNU > >> +;;; Copyright =C2=A9 2017 Peter Mikkelsen > >> +;;; > >> +;;; This file is part of GNU Guix. > >> +;;; > >> +;;; GNU Guix is free software; you can redistribute it and/or > >> modify it +;;; under the terms of the GNU General Public License as > >> published by +;;; the Free Software Foundation; either version 3 of > >> the License, or (at +;;; your option) any later version. > >> +;;; > >> +;;; GNU Guix is distributed in the hope that it will be useful, > >> but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > >> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > >> +;;; GNU General Public License for more details. > >> +;;; > >> +;;; You should have received a copy of the GNU General Public > >> License +;;; along with GNU Guix. If not, see > >> . + > >> +(define-module (gnu services audio) > >> + #:use-module (guix gexp) > >> + #:use-module (gnu services) > >> + #:use-module (gnu services shepherd) > >> + #:use-module (gnu packages mpd) > >> + #:use-module (guix records) > >> + #:export (mpd-configuration > >> + mpd-configuration? > >> + mpd-service-type)) > >> + > >> +;;; Commentary: > >> +;;; > >> +;;; Audio related services > >> +;;; > >> +;;; Code: > >> + > >> +(define-record-type* > >> + mpd-configuration make-mpd-configuration > >> + mpd-configuration? > >> + (user mpd-configuration-user > >> + (default "mpd")) > >> + (music-dir mpd-configuration-music-dir > >> + (default "~/Music")) > >> + (playlist-dir mpd-configuration-playlist-dir > >> + (default "~/.mpd/playlists")) > >> + (port mpd-configuration-port > >> + (default "6600")) > >> + (address mpd-configuration-address > >> + (default "any")) > >> + (pid-file mpd-configuration-pid-file > >> + (default "/var/run/mpd.pid"))) > >> + > >> +(define (mpd-config->file config) > >> + (apply > >> + mixed-text-file "mpd.conf" > >> + "audio_output {\n" > >> + " type \"pulse\"\n" > >> + " name \"MPD\"\n" > >> + "}\n" > >> + (map (lambda (config-line) > >> + (let ((config-name (car config-line)) > >> + (config-val (cadr config-line))) > >> + (string-append config-name " \"" (config-val config) > >> "\"\n"))) =20 > > > > One way of making this a bit more concise and remove the need for > > car and cadr is to use the match module (ice-9 match). > > > > (map (match-lambda > > ((config-name config-val) > > (string-append config-name " \"" (config-val config) > > "\"\n"))) ... > > > > =20 >=20 > I didn't know about match-lambda, but it seems pretty neat, so I used > your example here, thanks. >=20 > >> + `(("user" ,mpd-configuration-user) > >> + ("music_directory" ,mpd-configuration-music-dir) > >> + ("playlist_directory" ,mpd-configuration-playlist-dir) > >> + ("port" ,mpd-configuration-port) > >> + ("bind_to_address" ,mpd-configuration-address) > >> + ("pid_file" ,mpd-configuration-pid-file))))) > >> + =20 > > > > ... =20 Awesome, I've now pushed this to master :) --Sig_/nENCve.rh+HWAjhYskz=319 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmP/H5fFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE 9XfXoQ/+IP1Kgwz67KaJ8V5mr4QiBLVYs2nzdFeOiroOkeFFvg1AZ1JjDwGxQN4T 61sH8N68eofJXFWQyns8QwDgDEXvGzYTRZHVddKvobByEM1SQoI1ttweOWMXpMIh wWhye4vI3ddaXg0U4HiOkNXeKQ6U10e3wleTYckiMLVdVur4QQw1wPYUuzzHWXt5 ndjNMb8ozqU27EqnK3w/xqkyG4RGV+y27YHnrK3t4CrOlf1Ya/Usgxlm5THKqJYE OVwIx3agcpYW7ls/a79F6k5W5IEHnYYGQ43E2nndgYqjl37xCtC1bqfF7O0fvQ3U mg2qVPpS/qm7T9Q8TE/4Qfz52IgHhzmPC95uRp8XPU8a8nD46AtkNDzsdSM7nBOC rNSnWQWEsPIlu+teZoulcUSBtUlIRazXNQuXUyI4qApRl/wyOO3Z5k+8KnjsAXJU A+mmOR3K1Q8gi4ivbSwfgVWXkuSw4iGKfdYR5mUoXes0FmhQzrxKYMjeZZOAmiUD 2qwBecBYPOlfqPfyY2FROqiTVO7aZVCjt2xO4LKUKZzqEA/gUdsCJztOxCnqF3Qd W0GitrUL/vCgGRSZr4o1cIWynOM+29zg9zueZcQ6wAdWjq00Pv74d1+RvpZT3Mkb i0V1YSYeExDrLFv6BNp1P61Ko2mjYTRmsUCb1bKGwVRc5GDyaoY= =uXCh -----END PGP SIGNATURE----- --Sig_/nENCve.rh+HWAjhYskz=319-- From unknown Fri Jun 20 07:09:35 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 10 Sep 2017 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator