Commit | Line | Data |
---|---|---|
8cd1e8e8 | 1 | ;;; GNU Guix --- Functional package management for GNU |
a66ee82a | 2 | ;;; Copyright © 2018, 2020 Oleg Pykhalov <go.wigust@gmail.com> |
f5474262 | 3 | ;;; Copyright © 2020 Leo Prikler <leo.prikler@student.tugraz.at> |
3ed94ed8 | 4 | ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com> |
8cd1e8e8 OP |
5 | ;;; |
6 | ;;; This file is part of GNU Guix. | |
7 | ;;; | |
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. | |
12 | ;;; | |
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. | |
17 | ;;; | |
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/>. | |
20 | ||
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) | |
a66ee82a | 26 | #:use-module (gnu system pam) |
8cd1e8e8 OP |
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) | |
a66ee82a | 32 | #:use-module (gnu packages audio) |
1e3861eb | 33 | #:use-module (gnu packages linux) |
8cd1e8e8 OP |
34 | #:use-module (gnu packages pulseaudio) |
35 | #:use-module (ice-9 match) | |
36 | #:export (alsa-configuration | |
a66ee82a OP |
37 | alsa-service-type |
38 | ||
f5474262 | 39 | pulseaudio-configuration |
f1022fbf LP |
40 | pulseaudio-service-type |
41 | ||
42 | ladspa-configuration | |
43 | ladspa-service-type)) | |
8cd1e8e8 OP |
44 | |
45 | ;;; Commentary: | |
46 | ;;; | |
47 | ;;; Sound services. | |
48 | ;;; | |
49 | ;;; Code: | |
50 | ||
51 | \f | |
52 | ;;; | |
53 | ;;; ALSA | |
54 | ;;; | |
55 | ||
56 | (define-record-type* <alsa-configuration> | |
57 | alsa-configuration make-alsa-configuration alsa-configuration? | |
1e3861eb OP |
58 | (alsa-plugins alsa-configuration-alsa-plugins ;<package> |
59 | (default alsa-plugins)) | |
8cd1e8e8 OP |
60 | (pulseaudio? alsa-configuration-pulseaudio? ;boolean |
61 | (default #t)) | |
62 | (extra-options alsa-configuration-extra-options ;string | |
63 | (default ""))) | |
64 | ||
1e3861eb OP |
65 | (define alsa-config-file |
66 | ;; Return the ALSA configuration file. | |
67 | (match-lambda | |
68 | (($ <alsa-configuration> alsa-plugins pulseaudio? extra-options) | |
69 | (apply mixed-text-file "asound.conf" | |
70 | `("# Generated by 'alsa-service'.\n\n" | |
71 | ,@(if pulseaudio? | |
72 | `("# Use PulseAudio by default | |
73 | pcm_type.pulse { | |
74 | lib \"" ,#~(string-append #$alsa-plugins:pulseaudio | |
75 | "/lib/alsa-lib/libasound_module_pcm_pulse.so") "\" | |
76 | } | |
77 | ||
78 | ctl_type.pulse { | |
79 | lib \"" ,#~(string-append #$alsa-plugins:pulseaudio | |
80 | "/lib/alsa-lib/libasound_module_ctl_pulse.so") "\" | |
81 | } | |
82 | ||
8cd1e8e8 OP |
83 | pcm.!default { |
84 | type pulse | |
85 | fallback \"sysdefault\" | |
86 | hint { | |
87 | show on | |
88 | description \"Default ALSA Output (currently PulseAudio Sound Server)\" | |
89 | } | |
90 | } | |
91 | ||
92 | ctl.!default { | |
93 | type pulse | |
94 | fallback \"sysdefault\" | |
1e3861eb OP |
95 | }\n\n") |
96 | '()) | |
97 | ,extra-options))))) | |
8cd1e8e8 OP |
98 | |
99 | (define (alsa-etc-service config) | |
100 | (list `("asound.conf" ,(alsa-config-file config)))) | |
101 | ||
102 | (define alsa-service-type | |
103 | (service-type | |
104 | (name 'alsa) | |
105 | (extensions | |
106 | (list (service-extension etc-service-type alsa-etc-service))) | |
107 | (default-value (alsa-configuration)) | |
108 | (description "Configure low-level Linux sound support, ALSA."))) | |
109 | ||
a66ee82a OP |
110 | \f |
111 | ;;; | |
112 | ;;; PulseAudio | |
113 | ;;; | |
114 | ||
f5474262 LP |
115 | (define-record-type* <pulseaudio-configuration> |
116 | pulseaudio-configuration make-pulseaudio-configuration | |
117 | pulseaudio-configuration? | |
118 | (client-conf pulseaudio-client-conf | |
119 | (default '())) | |
120 | (daemon-conf pulseaudio-daemon-conf | |
f6f91811 LP |
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)))) | |
f5474262 LP |
125 | (script-file pulseaudio-script-file |
126 | (default (file-append pulseaudio "/etc/pulse/default.pa"))) | |
127 | (system-script-file pulseaudio-system-script-file | |
128 | (default | |
129 | (file-append pulseaudio "/etc/pulse/system.pa")))) | |
130 | ||
f5474262 LP |
131 | (define (pulseaudio-conf-entry arg) |
132 | (match arg | |
133 | ((key . value) | |
134 | (format #f "~a = ~s~%" key value)) | |
135 | ((? string? _) | |
136 | (string-append arg "\n")))) | |
137 | ||
3ed94ed8 MB |
138 | (define pulseaudio-environment |
139 | (match-lambda | |
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))))))) | |
146 | ||
f5474262 LP |
147 | (define pulseaudio-etc |
148 | (match-lambda | |
3ed94ed8 | 149 | (($ <pulseaudio-configuration> _ _ default-script-file system-script-file) |
f5474262 LP |
150 | `(("pulse" |
151 | ,(file-union | |
152 | "pulse" | |
3ed94ed8 | 153 | `(("default.pa" ,default-script-file) |
f5474262 | 154 | ("system.pa" ,system-script-file)))))))) |
a66ee82a OP |
155 | |
156 | (define pulseaudio-service-type | |
157 | (service-type | |
158 | (name 'pulseaudio) | |
159 | (extensions | |
160 | (list (service-extension session-environment-service-type | |
f5474262 LP |
161 | pulseaudio-environment) |
162 | (service-extension etc-service-type pulseaudio-etc))) | |
163 | (default-value (pulseaudio-configuration)) | |
a66ee82a OP |
164 | (description "Configure PulseAudio sound support."))) |
165 | ||
f1022fbf LP |
166 | \f |
167 | ;;; | |
168 | ;;; LADSPA | |
169 | ;;; | |
170 | ||
171 | (define-record-type* <ladspa-configuration> | |
172 | ladspa-configuration make-ladspa-configuration | |
173 | ladspa-configuration? | |
174 | (plugins ladspa-plugins (default '()))) | |
175 | ||
176 | (define (ladspa-environment config) | |
177 | ;; Define this variable in the global environment such that | |
178 | ;; pulseaudio swh-plugins (and similar LADSPA plugins) work. | |
179 | `(("LADSPA_PATH" . | |
180 | (string-join | |
181 | ',(map (lambda (package) (file-append package "/lib/ladspa")) | |
182 | (ladspa-plugins config)) | |
183 | ":")))) | |
184 | ||
185 | (define ladspa-service-type | |
186 | (service-type | |
187 | (name 'ladspa) | |
188 | (extensions | |
189 | (list (service-extension session-environment-service-type | |
190 | ladspa-environment))) | |
191 | (default-value (ladspa-configuration)) | |
192 | (description "Configure LADSPA plugins."))) | |
193 | ||
8cd1e8e8 | 194 | ;;; sound.scm ends here |