1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018, 2020 Oleg Pykhalov <go.wigust@gmail.com>
3 ;;; Copyright © 2020 Leo Prikler <leo.prikler@student.tugraz.at>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu services sound)
21 #:use-module (gnu services base)
22 #:use-module (gnu services configuration)
23 #:use-module (gnu services shepherd)
24 #:use-module (gnu services)
25 #:use-module (gnu system pam)
26 #:use-module (gnu system shadow)
27 #:use-module (guix gexp)
28 #:use-module (guix packages)
29 #:use-module (guix records)
30 #:use-module (guix store)
31 #:use-module (gnu packages audio)
32 #:use-module (gnu packages linux)
33 #:use-module (gnu packages pulseaudio)
34 #:use-module (ice-9 match)
35 #:export (alsa-configuration
38 pulseaudio-configuration
39 pulseaudio-service-type
55 (define-record-type* <alsa-configuration>
56 alsa-configuration make-alsa-configuration alsa-configuration?
57 (alsa-plugins alsa-configuration-alsa-plugins ;<package>
58 (default alsa-plugins))
59 (pulseaudio? alsa-configuration-pulseaudio? ;boolean
61 (extra-options alsa-configuration-extra-options ;string
64 (define alsa-config-file
65 ;; Return the ALSA configuration file.
67 (($ <alsa-configuration> alsa-plugins pulseaudio? extra-options)
68 (apply mixed-text-file "asound.conf"
69 `("# Generated by 'alsa-service'.\n\n"
71 `("# Use PulseAudio by default
73 lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
74 "/lib/alsa-lib/libasound_module_pcm_pulse.so") "\"
78 lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
79 "/lib/alsa-lib/libasound_module_ctl_pulse.so") "\"
84 fallback \"sysdefault\"
87 description \"Default ALSA Output (currently PulseAudio Sound Server)\"
93 fallback \"sysdefault\"
98 (define (alsa-etc-service config)
99 (list `("asound.conf" ,(alsa-config-file config))))
101 (define alsa-service-type
105 (list (service-extension etc-service-type alsa-etc-service)))
106 (default-value (alsa-configuration))
107 (description "Configure low-level Linux sound support, ALSA.")))
114 (define-record-type* <pulseaudio-configuration>
115 pulseaudio-configuration make-pulseaudio-configuration
116 pulseaudio-configuration?
117 (client-conf pulseaudio-client-conf
119 (daemon-conf pulseaudio-daemon-conf
120 ;; Flat volumes may cause unpleasant experiences to users
121 ;; when applications inadvertently max out the system volume
122 ;; (see e.g. <https://bugs.gnu.org/38172>).
123 (default '((flat-volumes . no))))
124 (script-file pulseaudio-script-file
125 (default (file-append pulseaudio "/etc/pulse/default.pa")))
126 (system-script-file pulseaudio-system-script-file
128 (file-append pulseaudio "/etc/pulse/system.pa"))))
130 (define (pulseaudio-environment config)
131 `(;; Define these variables, so that pulseaudio honors /etc.
132 ("PULSE_CONFIG" . "/etc/pulse/daemon.conf")
133 ("PULSE_CLIENTCONFIG" . "/etc/pulse/client.conf")))
135 (define (pulseaudio-conf-entry arg)
138 (format #f "~a = ~s~%" key value))
140 (string-append arg "\n"))))
142 (define pulseaudio-etc
144 (($ <pulseaudio-configuration> client-conf daemon-conf
145 default-script-file system-script-file)
150 ,(apply mixed-text-file "client.conf"
151 (map pulseaudio-conf-entry client-conf)))
153 ,(apply mixed-text-file "daemon.conf"
154 "default-script-file = " default-script-file "\n"
155 (map pulseaudio-conf-entry daemon-conf)))
156 ("default.pa" ,default-script-file)
157 ("system.pa" ,system-script-file))))))))
159 (define pulseaudio-service-type
163 (list (service-extension session-environment-service-type
164 pulseaudio-environment)
165 (service-extension etc-service-type pulseaudio-etc)))
166 (default-value (pulseaudio-configuration))
167 (description "Configure PulseAudio sound support.")))
174 (define-record-type* <ladspa-configuration>
175 ladspa-configuration make-ladspa-configuration
176 ladspa-configuration?
177 (plugins ladspa-plugins (default '())))
179 (define (ladspa-environment config)
180 ;; Define this variable in the global environment such that
181 ;; pulseaudio swh-plugins (and similar LADSPA plugins) work.
184 ',(map (lambda (package) (file-append package "/lib/ladspa"))
185 (ladspa-plugins config))
188 (define ladspa-service-type
192 (list (service-extension session-environment-service-type
193 ladspa-environment)))
194 (default-value (ladspa-configuration))
195 (description "Configure LADSPA plugins.")))
197 ;;; sound.scm ends here