2018-04-28 10:30:20 +00:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2020-01-05 17:11:01 +00:00
|
|
|
|
;;; Copyright © 2018, 2020 Oleg Pykhalov <go.wigust@gmail.com>
|
2021-09-25 07:27:02 +00:00
|
|
|
|
;;; Copyright © 2020 Liliana Marie Prikler <liliana.prikler@gmail.com>
|
2020-05-06 15:48:42 +00:00
|
|
|
|
;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
|
2018-04-28 10:30:20 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu services sound)
|
|
|
|
|
#:use-module (gnu services base)
|
|
|
|
|
#:use-module (gnu services configuration)
|
|
|
|
|
#:use-module (gnu services shepherd)
|
|
|
|
|
#:use-module (gnu services)
|
2020-01-05 17:11:01 +00:00
|
|
|
|
#:use-module (gnu system pam)
|
2018-04-28 10:30:20 +00:00
|
|
|
|
#:use-module (gnu system shadow)
|
|
|
|
|
#:use-module (guix gexp)
|
|
|
|
|
#:use-module (guix packages)
|
|
|
|
|
#:use-module (guix records)
|
|
|
|
|
#:use-module (guix store)
|
2020-01-05 17:11:01 +00:00
|
|
|
|
#:use-module (gnu packages audio)
|
2018-06-24 10:18:53 +00:00
|
|
|
|
#:use-module (gnu packages linux)
|
2018-04-28 10:30:20 +00:00
|
|
|
|
#:use-module (gnu packages pulseaudio)
|
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:export (alsa-configuration
|
2020-01-05 17:11:01 +00:00
|
|
|
|
alsa-service-type
|
|
|
|
|
|
2020-01-10 01:48:19 +00:00
|
|
|
|
pulseaudio-configuration
|
2020-01-10 01:48:22 +00:00
|
|
|
|
pulseaudio-service-type
|
|
|
|
|
|
|
|
|
|
ladspa-configuration
|
|
|
|
|
ladspa-service-type))
|
2018-04-28 10:30:20 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; Sound services.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; ALSA
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define-record-type* <alsa-configuration>
|
|
|
|
|
alsa-configuration make-alsa-configuration alsa-configuration?
|
2018-06-24 10:18:53 +00:00
|
|
|
|
(alsa-plugins alsa-configuration-alsa-plugins ;<package>
|
|
|
|
|
(default alsa-plugins))
|
2018-04-28 10:30:20 +00:00
|
|
|
|
(pulseaudio? alsa-configuration-pulseaudio? ;boolean
|
|
|
|
|
(default #t))
|
|
|
|
|
(extra-options alsa-configuration-extra-options ;string
|
|
|
|
|
(default "")))
|
|
|
|
|
|
2018-06-24 10:18:53 +00:00
|
|
|
|
(define alsa-config-file
|
|
|
|
|
;; Return the ALSA configuration file.
|
|
|
|
|
(match-lambda
|
|
|
|
|
(($ <alsa-configuration> alsa-plugins pulseaudio? extra-options)
|
|
|
|
|
(apply mixed-text-file "asound.conf"
|
|
|
|
|
`("# Generated by 'alsa-service'.\n\n"
|
|
|
|
|
,@(if pulseaudio?
|
|
|
|
|
`("# Use PulseAudio by default
|
|
|
|
|
pcm_type.pulse {
|
|
|
|
|
lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
|
|
|
|
|
"/lib/alsa-lib/libasound_module_pcm_pulse.so") "\"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctl_type.pulse {
|
|
|
|
|
lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
|
|
|
|
|
"/lib/alsa-lib/libasound_module_ctl_pulse.so") "\"
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-28 10:30:20 +00:00
|
|
|
|
pcm.!default {
|
|
|
|
|
type pulse
|
|
|
|
|
fallback \"sysdefault\"
|
|
|
|
|
hint {
|
|
|
|
|
show on
|
|
|
|
|
description \"Default ALSA Output (currently PulseAudio Sound Server)\"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctl.!default {
|
|
|
|
|
type pulse
|
|
|
|
|
fallback \"sysdefault\"
|
2018-06-24 10:18:53 +00:00
|
|
|
|
}\n\n")
|
|
|
|
|
'())
|
|
|
|
|
,extra-options)))))
|
2018-04-28 10:30:20 +00:00
|
|
|
|
|
|
|
|
|
(define (alsa-etc-service config)
|
|
|
|
|
(list `("asound.conf" ,(alsa-config-file config))))
|
|
|
|
|
|
|
|
|
|
(define alsa-service-type
|
|
|
|
|
(service-type
|
|
|
|
|
(name 'alsa)
|
|
|
|
|
(extensions
|
|
|
|
|
(list (service-extension etc-service-type alsa-etc-service)))
|
|
|
|
|
(default-value (alsa-configuration))
|
|
|
|
|
(description "Configure low-level Linux sound support, ALSA.")))
|
|
|
|
|
|
2020-01-05 17:11:01 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; PulseAudio
|
|
|
|
|
;;;
|
|
|
|
|
|
2020-01-10 01:48:19 +00:00
|
|
|
|
(define-record-type* <pulseaudio-configuration>
|
|
|
|
|
pulseaudio-configuration make-pulseaudio-configuration
|
|
|
|
|
pulseaudio-configuration?
|
|
|
|
|
(client-conf pulseaudio-client-conf
|
|
|
|
|
(default '()))
|
|
|
|
|
(daemon-conf pulseaudio-daemon-conf
|
2020-01-10 01:48:21 +00:00
|
|
|
|
;; Flat volumes may cause unpleasant experiences to users
|
|
|
|
|
;; when applications inadvertently max out the system volume
|
|
|
|
|
;; (see e.g. <https://bugs.gnu.org/38172>).
|
|
|
|
|
(default '((flat-volumes . no))))
|
2020-01-10 01:48:19 +00:00
|
|
|
|
(script-file pulseaudio-script-file
|
|
|
|
|
(default (file-append pulseaudio "/etc/pulse/default.pa")))
|
|
|
|
|
(system-script-file pulseaudio-system-script-file
|
|
|
|
|
(default
|
|
|
|
|
(file-append pulseaudio "/etc/pulse/system.pa"))))
|
|
|
|
|
|
|
|
|
|
(define (pulseaudio-conf-entry arg)
|
|
|
|
|
(match arg
|
|
|
|
|
((key . value)
|
|
|
|
|
(format #f "~a = ~s~%" key value))
|
|
|
|
|
((? string? _)
|
|
|
|
|
(string-append arg "\n"))))
|
|
|
|
|
|
2020-05-06 15:48:42 +00:00
|
|
|
|
(define pulseaudio-environment
|
|
|
|
|
(match-lambda
|
|
|
|
|
(($ <pulseaudio-configuration> client-conf daemon-conf default-script-file)
|
|
|
|
|
`(("PULSE_CONFIG" . ,(apply mixed-text-file "daemon.conf"
|
|
|
|
|
"default-script-file = " default-script-file "\n"
|
|
|
|
|
(map pulseaudio-conf-entry daemon-conf)))
|
|
|
|
|
("PULSE_CLIENTCONFIG" . ,(apply mixed-text-file "client.conf"
|
|
|
|
|
(map pulseaudio-conf-entry client-conf)))))))
|
|
|
|
|
|
2020-01-10 01:48:19 +00:00
|
|
|
|
(define pulseaudio-etc
|
|
|
|
|
(match-lambda
|
2020-05-06 15:48:42 +00:00
|
|
|
|
(($ <pulseaudio-configuration> _ _ default-script-file system-script-file)
|
2020-01-10 01:48:19 +00:00
|
|
|
|
`(("pulse"
|
|
|
|
|
,(file-union
|
|
|
|
|
"pulse"
|
2020-05-06 15:48:42 +00:00
|
|
|
|
`(("default.pa" ,default-script-file)
|
2020-01-10 01:48:19 +00:00
|
|
|
|
("system.pa" ,system-script-file))))))))
|
2020-01-05 17:11:01 +00:00
|
|
|
|
|
|
|
|
|
(define pulseaudio-service-type
|
|
|
|
|
(service-type
|
|
|
|
|
(name 'pulseaudio)
|
|
|
|
|
(extensions
|
|
|
|
|
(list (service-extension session-environment-service-type
|
2020-01-10 01:48:19 +00:00
|
|
|
|
pulseaudio-environment)
|
|
|
|
|
(service-extension etc-service-type pulseaudio-etc)))
|
|
|
|
|
(default-value (pulseaudio-configuration))
|
2020-01-05 17:11:01 +00:00
|
|
|
|
(description "Configure PulseAudio sound support.")))
|
|
|
|
|
|
2020-01-10 01:48:22 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; LADSPA
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define-record-type* <ladspa-configuration>
|
|
|
|
|
ladspa-configuration make-ladspa-configuration
|
|
|
|
|
ladspa-configuration?
|
|
|
|
|
(plugins ladspa-plugins (default '())))
|
|
|
|
|
|
|
|
|
|
(define (ladspa-environment config)
|
|
|
|
|
;; Define this variable in the global environment such that
|
|
|
|
|
;; pulseaudio swh-plugins (and similar LADSPA plugins) work.
|
|
|
|
|
`(("LADSPA_PATH" .
|
|
|
|
|
(string-join
|
|
|
|
|
',(map (lambda (package) (file-append package "/lib/ladspa"))
|
|
|
|
|
(ladspa-plugins config))
|
|
|
|
|
":"))))
|
|
|
|
|
|
|
|
|
|
(define ladspa-service-type
|
|
|
|
|
(service-type
|
|
|
|
|
(name 'ladspa)
|
|
|
|
|
(extensions
|
|
|
|
|
(list (service-extension session-environment-service-type
|
|
|
|
|
ladspa-environment)))
|
|
|
|
|
(default-value (ladspa-configuration))
|
|
|
|
|
(description "Configure LADSPA plugins.")))
|
|
|
|
|
|
2018-04-28 10:30:20 +00:00
|
|
|
|
;;; sound.scm ends here
|