Commit | Line | Data |
---|---|---|
06465d2b PM |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (gnu services audio) | |
20 | #:use-module (guix gexp) | |
21 | #:use-module (gnu services) | |
22 | #:use-module (gnu services shepherd) | |
23 | #:use-module (gnu packages mpd) | |
24 | #:use-module (guix records) | |
25 | #:use-module (ice-9 match) | |
26 | #:export (mpd-configuration | |
27 | mpd-configuration? | |
28 | mpd-service-type)) | |
29 | ||
30 | ;;; Commentary: | |
31 | ;;; | |
32 | ;;; Audio related services | |
33 | ;;; | |
34 | ;;; Code: | |
35 | ||
36 | (define-record-type* <mpd-configuration> | |
37 | mpd-configuration make-mpd-configuration | |
38 | mpd-configuration? | |
39 | (user mpd-configuration-user | |
40 | (default "mpd")) | |
41 | (music-dir mpd-configuration-music-dir | |
42 | (default "~/Music")) | |
43 | (playlist-dir mpd-configuration-playlist-dir | |
44 | (default "~/.mpd/playlists")) | |
45 | (port mpd-configuration-port | |
46 | (default "6600")) | |
47 | (address mpd-configuration-address | |
48 | (default "any")) | |
49 | (pid-file mpd-configuration-pid-file | |
50 | (default "/var/run/mpd.pid"))) | |
51 | ||
52 | (define (mpd-config->file config) | |
53 | (apply | |
54 | mixed-text-file "mpd.conf" | |
55 | "audio_output {\n" | |
56 | " type \"pulse\"\n" | |
57 | " name \"MPD\"\n" | |
58 | "}\n" | |
59 | (map (match-lambda | |
60 | ((config-name config-val) | |
61 | (string-append config-name " \"" (config-val config) "\"\n"))) | |
62 | `(("user" ,mpd-configuration-user) | |
63 | ("music_directory" ,mpd-configuration-music-dir) | |
64 | ("playlist_directory" ,mpd-configuration-playlist-dir) | |
65 | ("port" ,mpd-configuration-port) | |
66 | ("bind_to_address" ,mpd-configuration-address) | |
67 | ("pid_file" ,mpd-configuration-pid-file))))) | |
68 | ||
69 | (define (mpd-service config) | |
70 | (shepherd-service | |
71 | (documentation "Run the MPD (Music Player Daemon)") | |
72 | (provision '(mpd)) | |
73 | (start #~(make-forkexec-constructor | |
74 | (list #$(file-append mpd "/bin/mpd") | |
75 | "--no-daemon" | |
76 | #$(mpd-config->file config)) | |
77 | #:pid-file #$(mpd-configuration-pid-file config))) | |
78 | (stop #~(make-kill-destructor)))) | |
79 | ||
80 | (define mpd-service-type | |
81 | (service-type | |
82 | (name 'mpd) | |
83 | (extensions | |
84 | (list (service-extension shepherd-root-service-type | |
85 | (compose list mpd-service)))) | |
86 | (default-value (mpd-configuration)))) |