gnu: perl: Update home page.
[jackhill/guix/guix.git] / gnu / services / sound.scm
CommitLineData
8cd1e8e8
OP
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
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)
24 #:use-module (gnu system shadow)
25 #:use-module (guix gexp)
26 #:use-module (guix packages)
27 #:use-module (guix records)
28 #:use-module (guix store)
1e3861eb 29 #:use-module (gnu packages linux)
8cd1e8e8
OP
30 #:use-module (gnu packages pulseaudio)
31 #:use-module (ice-9 match)
32 #:export (alsa-configuration
33 alsa-service-type))
34
35;;; Commentary:
36;;;
37;;; Sound services.
38;;;
39;;; Code:
40
41\f
42;;;
43;;; ALSA
44;;;
45
46(define-record-type* <alsa-configuration>
47 alsa-configuration make-alsa-configuration alsa-configuration?
1e3861eb
OP
48 (alsa-plugins alsa-configuration-alsa-plugins ;<package>
49 (default alsa-plugins))
8cd1e8e8
OP
50 (pulseaudio? alsa-configuration-pulseaudio? ;boolean
51 (default #t))
52 (extra-options alsa-configuration-extra-options ;string
53 (default "")))
54
1e3861eb
OP
55(define alsa-config-file
56 ;; Return the ALSA configuration file.
57 (match-lambda
58 (($ <alsa-configuration> alsa-plugins pulseaudio? extra-options)
59 (apply mixed-text-file "asound.conf"
60 `("# Generated by 'alsa-service'.\n\n"
61 ,@(if pulseaudio?
62 `("# Use PulseAudio by default
63pcm_type.pulse {
64 lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
65 "/lib/alsa-lib/libasound_module_pcm_pulse.so") "\"
66}
67
68ctl_type.pulse {
69 lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
70 "/lib/alsa-lib/libasound_module_ctl_pulse.so") "\"
71}
72
8cd1e8e8
OP
73pcm.!default {
74 type pulse
75 fallback \"sysdefault\"
76 hint {
77 show on
78 description \"Default ALSA Output (currently PulseAudio Sound Server)\"
79 }
80}
81
82ctl.!default {
83 type pulse
84 fallback \"sysdefault\"
1e3861eb
OP
85}\n\n")
86 '())
87 ,extra-options)))))
8cd1e8e8
OP
88
89(define (alsa-etc-service config)
90 (list `("asound.conf" ,(alsa-config-file config))))
91
92(define alsa-service-type
93 (service-type
94 (name 'alsa)
95 (extensions
96 (list (service-extension etc-service-type alsa-etc-service)))
97 (default-value (alsa-configuration))
98 (description "Configure low-level Linux sound support, ALSA.")))
99
100;;; sound.scm ends here