unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 2351db8a4a0d68fa700c3df4362a010e738612e3 8709 bytes (raw)
name: gnu/services/audio.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; 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 configuration)
  #:use-module (gnu services shepherd)
  #:use-module (gnu system shadow)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages mpd)
  #:use-module (guix records)
  #:use-module (ice-9 match)
  #:use-module (ice-9 format)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:export (mpd-output
            mpd-output?
            mpd-configuration
            mpd-configuration?
            mpd-service-type))

;;; Commentary:
;;;
;;; Audio related services
;;;
;;; Code:

(define (uglify-field-name field-name)
  (let ((str (symbol->string field-name)))
    (string-join (string-split (if (string-suffix? "?" str)
                                   (string-drop-right str 1)
                                   str)
                               #\-)
                 "_")))

(define (free-form-args? val)
  (match val
    (() #t)
    ((((? symbol?) . (? string?)) . val) (free-form-args? val))
    (_ #f)))

(define* (mpd-serialize-field field-name value #:optional (indent-level 0))
  #~(begin
      (use-modules ((ice-9 format)))
      (format #f "~v/~a \"~a\"~%" #$indent-level #$(if (string? field-name)
                                                       field-name
                                                       (uglify-field-name field-name)) #$value)))

(define* (mpd-serialize-free-form-args field-name value #:optional (indent-level 0))
  (generic-serialize-alist string-append (cut mpd-serialize-field <> <> indent-level) value))

(define mpd-serialize-number mpd-serialize-field)

(define mpd-serialize-string mpd-serialize-field)

(define* (mpd-serialize-boolean field-name value #:optional (indent-level 0))
  (mpd-serialize-field field-name (if value "yes" "no") indent-level))

(define (mpd-serialize-list-of-mpd-output field-name value)
  #~(string-append "\naudio_output {\n"
                   #$@(map (cut serialize-configuration <>
                                mpd-output-fields)
                           value)
                   "}\n"))

(define (mpd-serialize-configuration configuration)
  (mixed-text-file
   "mpd.conf"
   (serialize-configuration configuration mpd-configuration-fields)))

(define mpd-subsystem-serialize-field (cut mpd-serialize-field <> <> 1))
(define mpd-subsystem-serialize-string (cut mpd-serialize-string <> <> 1))
(define mpd-subsystem-serialize-number (cut mpd-serialize-number <> <> 1))
(define mpd-subsystem-serialize-boolean (cut mpd-serialize-boolean <> <> 1))
(define mpd-subsystem-serialize-free-form-args (cut mpd-serialize-free-form-args <> <> 1))

(define-configuration mpd-output
  (name
   (string "MPD")
   "The name of the audio output.")
  (type
   (string "pulse")
   "The type of audio output.")
  (enabled?
   (boolean #t)
   "Specifies whether this audio output is enabled when MPD is started. By
default, all audio outputs are enabled. This is just the default
setting when there is no state file; with a state file, the previous
state is restored.")
  (tags?
   (boolean #t)
   "If set to @code{#f}, then MPD will not send tags to this output. This
is only useful for output plugins that can receive tags, for example the
@code{httpd} output plugin.")
  (always-on?
   (boolean #f)
   "If set to @code{#t}, then MPD attempts to keep this audio output always
open. This may be useful for streaming servers, when you don’t want to
disconnect all listeners even when playback is accidentally stopped.")
  (mixer-type
   (string "none")
   "This field accepts a symbol that specifies which mixer should be used
for this audio output: the @code{hardware} mixer, the @code{software}
mixer, the @code{null} mixer (allows setting the volume, but with no
effect; this can be used as a trick to implement an external mixer
External Mixer) or no mixer (@code{none}).")
  (extra-options
   (free-form-args '())
   "An association list of option symbols to string values to be appended to
the audio output configuration.")
  (prefix mpd-subsystem-))

(define list-of-mpd-output?
  (list-of mpd-output?))

(define-configuration mpd-configuration
  (user
   (string "mpd")
   "The user to run mpd as.")
  (music-dir
   (string "~/Music")
   "The directory to scan for music files."
   (lambda (_ x)
     (mpd-serialize-field "music_directory" x)))
  (playlist-dir
   (string "~/.mpd/playlists")
   "The directory to store playlists."
   (lambda (_ x)
     (mpd-serialize-field "playlist_directory" x)))
  (db-file
   (string "~/.mpd/tag_cache")
   "The location of the music database.")
  (state-file
   (string "~/.mpd/state")
   "The location of the file that stores current MPD's state.")
  (sticker-file
   (string "~/.mpd/sticker.sql")
   "The location of the sticker database.")
  (port
   (string "6600")
   "The port to run mpd on.")
  (address
   (string "any")
   "The address that mpd will bind to.
To use a Unix domain socket, an absolute path can be specified here."
   (lambda (_ x)
     (mpd-serialize-field "bind_to_address" x)))
  (outputs
   (list-of-mpd-output (list (mpd-output)))
   "The audio outputs that MPD can use.
By default this is a single output using pulseaudio.")
  (prefix mpd-))

(define (mpd-file-name config file)
  "Return a path in /var/run/mpd/ that is writable
   by @code{user} from @code{config}."
  (string-append "/var/run/mpd/"
                 (mpd-configuration-user config)
                 "/" file))

(define (mpd-shepherd-service config)
  (shepherd-service
   (documentation "Run the MPD (Music Player Daemon)")
   (requirement '(user-processes))
   (provision '(mpd))
   (start #~(make-forkexec-constructor
             (list #$(file-append mpd "/bin/mpd")
                   "--no-daemon"
                   #$(mpd-serialize-configuration config))
             #:environment-variables
             ;; Required to detect PulseAudio when run under a user account.
             (list (string-append
                    "XDG_RUNTIME_DIR=/run/user/"
                    (number->string
                     (passwd:uid
                      (getpwnam #$(mpd-configuration-user config))))))
             #:log-file #$(mpd-file-name config "log")))
   (stop  #~(make-kill-destructor))))

(define (mpd-service-activation config)
  (with-imported-modules '((guix build utils))
    #~(begin
        (use-modules (guix build utils))
        (define %user
          (getpw #$(mpd-configuration-user config)))

        (let ((directory #$(mpd-file-name config ".mpd")))
          (mkdir-p directory)
          (chown directory (passwd:uid %user) (passwd:gid %user))

          ;; Make /var/run/mpd/USER user-owned as well.
          (chown (dirname directory)
                 (passwd:uid %user) (passwd:gid %user))))))


(define %mpd-accounts
  ;; Default account and group for MPD.
  (list (user-group (name "mpd") (system? #t))
        (user-account
         (name "mpd")
         (group "mpd")
         (system? #t)
         (comment "Music Player Daemon (MPD) user")

         ;; Note: /var/run/mpd hosts one sub-directory per user, of which
         ;; /var/run/mpd/mpd corresponds to the "mpd" user.
         (home-directory "/var/run/mpd/mpd")

         (shell (file-append shadow "/sbin/nologin")))))

(define mpd-service-type
  (service-type
   (name 'mpd)
   (description "Run the Music Player Daemon (MPD).")
   (extensions
    (list (service-extension shepherd-root-service-type
                             (compose list mpd-shepherd-service))
          (service-extension account-service-type
                             (const %mpd-accounts))
          (service-extension activation-service-type
                             mpd-service-activation)))
   (default-value (mpd-configuration))))

debug log:

solving 2351db8a4a ...
found 2351db8a4a in https://yhetil.org/guix-patches/bd3ba0e684224d42c4a56b427ec3022a8c50fe38.1670368385.git.mirai@makinata.eu/ ||
	https://yhetil.org/guix-patches/248f6adc7d434e3d8df791311744a38e0d965744.1671632111.git.mirai@makinata.eu/
found c60053f33c in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 c60053f33cdbd5f186aac9900499d10c3d087fbf	gnu/services/audio.scm

applying [1/1] https://yhetil.org/guix-patches/bd3ba0e684224d42c4a56b427ec3022a8c50fe38.1670368385.git.mirai@makinata.eu/
diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm
index c60053f33c..2351db8a4a 100644

Checking patch gnu/services/audio.scm...
Applied patch gnu/services/audio.scm cleanly.

skipping https://yhetil.org/guix-patches/248f6adc7d434e3d8df791311744a38e0d965744.1671632111.git.mirai@makinata.eu/ for 2351db8a4a
index at:
100644 2351db8a4a0d68fa700c3df4362a010e738612e3	gnu/services/audio.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).