[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/01: gnu: Add mpd service.
From: |
Christopher Baines |
Subject: |
01/01: gnu: Add mpd service. |
Date: |
Sun, 13 Aug 2017 03:05:18 -0400 (EDT) |
cbaines pushed a commit to branch master
in repository guix.
commit 06465d2ba4291eb2046c90c3977a295a9b7c434b
Author: Peter Mikkelsen <address@hidden>
Date: Sun Aug 13 00:04:04 2017 +0200
gnu: Add mpd service.
* doc/guix.texi: Add documentation.
* gnu/services/audio.scm (<mpd-configuration>): New record type.
(mpd-service-type): New service type.
* gnu/tests/audio.scm: New file.
* gnu/local.mk: Add new files.
Signed-off-by: Christopher Baines <address@hidden>
---
doc/guix.texi | 54 +++++++++++++++++++++++++++++++
gnu/local.mk | 2 ++
gnu/services/audio.scm | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++
gnu/tests/audio.scm | 78 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 220 insertions(+)
diff --git a/doc/guix.texi b/doc/guix.texi
index 02933c8..94277ba 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,58 @@ Package object of thermald.
@end table
@end deftp
address@hidden Audio Services
address@hidden Audio Services
+
+The @code{(gnu services audio)} module provides a service to start MPD
+(the Music Player Daemon).
+
address@hidden mpd
address@hidden 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
address@hidden"bob"} on port @code{6666}. It uses pulseaudio for output.
+
address@hidden
+(service mpd-service-type
+ (mpd-configuration
+ (user "bob")
+ (port "6666")))
address@hidden example
+
address@hidden {Scheme Variable} mpd-service-type
+The service type for @command{mpd}
address@hidden defvr
+
address@hidden {Data Type} mpd-configuration
+Data type representing the configuration of @command{mpd}.
+
address@hidden @asis
address@hidden @code{user} (default: @code{"mpd"})
+The user to run mpd as.
+
address@hidden @code{music-dir} (default: @code{"~/Music"})
+The directory to scan for music files.
+
address@hidden @code{playlist-dir} (default: @code{"~/.mpd/playlists"})
+The directory to store playlists.
+
address@hidden @code{pid-file} (default: @code{"/var/run/mpd.pid"})
+The file mpd wil store its PID. This must be an absolute path.
+
address@hidden @code{port} (default: @code{"6600"})
+The port to run mpd on.
+
address@hidden @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.
+
address@hidden table
address@hidden deftp
@node Miscellaneous Services
@subsubsection Miscellaneous Services
diff --git a/gnu/local.mk b/gnu/local.mk
index cffb18d..c12fd85 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -426,6 +426,7 @@ GNU_SYSTEM_MODULES = \
\
%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 = \
\
%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 0000000..22814a6
--- /dev/null
+++ b/gnu/services/audio.scm
@@ -0,0 +1,86 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2017 Peter Mikkelsen <address@hidden>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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>
+ 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 0000000..8eadaf0
--- /dev/null
+++ b/gnu/tests/audio.scm
@@ -0,0 +1,78 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2017 Peter Mikkelsen <address@hidden>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 (= (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))))