Commit | Line | Data |
---|---|---|
8cd1e8e8 | 1 | ;;; GNU Guix --- Functional package management for GNU |
a66ee82a | 2 | ;;; Copyright © 2018, 2020 Oleg Pykhalov <go.wigust@gmail.com> |
8cd1e8e8 OP |
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 sound) | |
20 | #:use-module (gnu services base) | |
21 | #:use-module (gnu services configuration) | |
22 | #:use-module (gnu services shepherd) | |
23 | #:use-module (gnu services) | |
a66ee82a | 24 | #:use-module (gnu system pam) |
8cd1e8e8 OP |
25 | #:use-module (gnu system shadow) |
26 | #:use-module (guix gexp) | |
27 | #:use-module (guix packages) | |
28 | #:use-module (guix records) | |
29 | #:use-module (guix store) | |
a66ee82a | 30 | #:use-module (gnu packages audio) |
1e3861eb | 31 | #:use-module (gnu packages linux) |
8cd1e8e8 OP |
32 | #:use-module (gnu packages pulseaudio) |
33 | #:use-module (ice-9 match) | |
34 | #:export (alsa-configuration | |
a66ee82a OP |
35 | alsa-service-type |
36 | ||
37 | pulseaudio-service-type)) | |
8cd1e8e8 OP |
38 | |
39 | ;;; Commentary: | |
40 | ;;; | |
41 | ;;; Sound services. | |
42 | ;;; | |
43 | ;;; Code: | |
44 | ||
45 | \f | |
46 | ;;; | |
47 | ;;; ALSA | |
48 | ;;; | |
49 | ||
50 | (define-record-type* <alsa-configuration> | |
51 | alsa-configuration make-alsa-configuration alsa-configuration? | |
1e3861eb OP |
52 | (alsa-plugins alsa-configuration-alsa-plugins ;<package> |
53 | (default alsa-plugins)) | |
8cd1e8e8 OP |
54 | (pulseaudio? alsa-configuration-pulseaudio? ;boolean |
55 | (default #t)) | |
56 | (extra-options alsa-configuration-extra-options ;string | |
57 | (default ""))) | |
58 | ||
1e3861eb OP |
59 | (define alsa-config-file |
60 | ;; Return the ALSA configuration file. | |
61 | (match-lambda | |
62 | (($ <alsa-configuration> alsa-plugins pulseaudio? extra-options) | |
63 | (apply mixed-text-file "asound.conf" | |
64 | `("# Generated by 'alsa-service'.\n\n" | |
65 | ,@(if pulseaudio? | |
66 | `("# Use PulseAudio by default | |
67 | pcm_type.pulse { | |
68 | lib \"" ,#~(string-append #$alsa-plugins:pulseaudio | |
69 | "/lib/alsa-lib/libasound_module_pcm_pulse.so") "\" | |
70 | } | |
71 | ||
72 | ctl_type.pulse { | |
73 | lib \"" ,#~(string-append #$alsa-plugins:pulseaudio | |
74 | "/lib/alsa-lib/libasound_module_ctl_pulse.so") "\" | |
75 | } | |
76 | ||
8cd1e8e8 OP |
77 | pcm.!default { |
78 | type pulse | |
79 | fallback \"sysdefault\" | |
80 | hint { | |
81 | show on | |
82 | description \"Default ALSA Output (currently PulseAudio Sound Server)\" | |
83 | } | |
84 | } | |
85 | ||
86 | ctl.!default { | |
87 | type pulse | |
88 | fallback \"sysdefault\" | |
1e3861eb OP |
89 | }\n\n") |
90 | '()) | |
91 | ,extra-options))))) | |
8cd1e8e8 OP |
92 | |
93 | (define (alsa-etc-service config) | |
94 | (list `("asound.conf" ,(alsa-config-file config)))) | |
95 | ||
96 | (define alsa-service-type | |
97 | (service-type | |
98 | (name 'alsa) | |
99 | (extensions | |
100 | (list (service-extension etc-service-type alsa-etc-service))) | |
101 | (default-value (alsa-configuration)) | |
102 | (description "Configure low-level Linux sound support, ALSA."))) | |
103 | ||
a66ee82a OP |
104 | \f |
105 | ;;; | |
106 | ;;; PulseAudio | |
107 | ;;; | |
108 | ||
109 | (define (pulseaudio-environment config) | |
110 | ;; Define this variable in the global environment such that | |
111 | ;; pulseaudio swh-plugins works. | |
112 | `(("LADSPA_PATH" | |
113 | . ,(file-append swh-plugins "/lib/ladspa")))) | |
114 | ||
115 | (define pulseaudio-service-type | |
116 | (service-type | |
117 | (name 'pulseaudio) | |
118 | (extensions | |
119 | (list (service-extension session-environment-service-type | |
120 | pulseaudio-environment))) | |
121 | (default-value #f) | |
122 | (description "Configure PulseAudio sound support."))) | |
123 | ||
8cd1e8e8 | 124 | ;;; sound.scm ends here |