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>
4 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu services sound)
22 #:use-module (gnu services base)
23 #:use-module (gnu services configuration)
24 #:use-module (gnu services shepherd)
25 #:use-module (gnu services)
26 #:use-module (gnu system pam)
27 #:use-module (gnu system shadow)
28 #:use-module (guix gexp)
29 #:use-module (guix packages)
30 #:use-module (guix records)
31 #:use-module (guix store)
32 #:use-module (gnu packages audio)
33 #:use-module (gnu packages linux)
34 #:use-module (gnu packages pulseaudio)
35 #:use-module (ice-9 match)
36 #:export (alsa-configuration
39 pulseaudio-configuration
40 pulseaudio-service-type
56 (define-record-type* <alsa-configuration>
57 alsa-configuration make-alsa-configuration alsa-configuration?
58 (alsa-plugins alsa-configuration-alsa-plugins ;<package>
59 (default alsa-plugins))
60 (pulseaudio? alsa-configuration-pulseaudio? ;boolean
62 (extra-options alsa-configuration-extra-options ;string
65 (define alsa-config-file
66 ;; Return the ALSA configuration file.
68 (($ <alsa-configuration> alsa-plugins pulseaudio? extra-options)
69 (apply mixed-text-file "asound.conf"
70 `("# Generated by 'alsa-service'.\n\n"
72 `("# Use PulseAudio by default
74 lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
75 "/lib/alsa-lib/libasound_module_pcm_pulse.so") "\"
79 lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
80 "/lib/alsa-lib/libasound_module_ctl_pulse.so") "\"
85 fallback \"sysdefault\"
88 description \"Default ALSA Output (currently PulseAudio Sound Server)\"
94 fallback \"sysdefault\"
99 (define (alsa-etc-service config)
100 (list `("asound.conf" ,(alsa-config-file config))))
102 (define alsa-service-type
106 (list (service-extension etc-service-type alsa-etc-service)))
107 (default-value (alsa-configuration))
108 (description "Configure low-level Linux sound support, ALSA.")))
115 (define-record-type* <pulseaudio-configuration>
116 pulseaudio-configuration make-pulseaudio-configuration
117 pulseaudio-configuration?
118 (client-conf pulseaudio-client-conf
120 (daemon-conf pulseaudio-daemon-conf
121 ;; Flat volumes may cause unpleasant experiences to users
122 ;; when applications inadvertently max out the system volume
123 ;; (see e.g. <https://bugs.gnu.org/38172>).
124 (default '((flat-volumes . no))))
125 (script-file pulseaudio-script-file
126 (default (file-append pulseaudio "/etc/pulse/default.pa")))
127 (system-script-file pulseaudio-system-script-file
129 (file-append pulseaudio "/etc/pulse/system.pa"))))
131 (define (pulseaudio-conf-entry arg)
134 (format #f "~a = ~s~%" key value))
136 (string-append arg "\n"))))
138 (define pulseaudio-environment
140 (($ <pulseaudio-configuration> client-conf daemon-conf default-script-file)
141 `(("PULSE_CONFIG" . ,(apply mixed-text-file "daemon.conf"
142 "default-script-file = " default-script-file "\n"
143 (map pulseaudio-conf-entry daemon-conf)))
144 ("PULSE_CLIENTCONFIG" . ,(apply mixed-text-file "client.conf"
145 (map pulseaudio-conf-entry client-conf)))))))
147 (define pulseaudio-etc
149 (($ <pulseaudio-configuration> _ _ default-script-file system-script-file)
153 `(("default.pa" ,default-script-file)
154 ("system.pa" ,system-script-file))))))))
156 (define pulseaudio-service-type
160 (list (service-extension session-environment-service-type
161 pulseaudio-environment)
162 (service-extension etc-service-type pulseaudio-etc)))
163 (default-value (pulseaudio-configuration))
164 (description "Configure PulseAudio sound support.")))
171 (define-record-type* <ladspa-configuration>
172 ladspa-configuration make-ladspa-configuration
173 ladspa-configuration?
174 (plugins ladspa-plugins (default '())))
176 (define (ladspa-environment config)
177 ;; Define this variable in the global environment such that
178 ;; pulseaudio swh-plugins (and similar LADSPA plugins) work.
181 ',(map (lambda (package) (file-append package "/lib/ladspa"))
182 (ladspa-plugins config))
185 (define ladspa-service-type
189 (list (service-extension session-environment-service-type
190 ladspa-environment)))
191 (default-value (ladspa-configuration))
192 (description "Configure LADSPA plugins.")))
194 ;;; sound.scm ends here