mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-04-06 21:20:33 +02:00
services: Generalize alsa-configuration.
* gnu/packages/sound.scm (alsa-pcm-configuration, alsa-ctl-configuration): New configuration records. (serialize-alsa-pcm-configuration, serialize-alsa-ctl-configuration): New variables. (<alsa-configuration>): Remove alsa-plugins and pulseaudio?. Add default-pcm and default-ctl. Rename extra-options to options. (alsa-config-file): Adjust accordingly. (alsa-servcice-type): Add compose and extend. (<pulseaudio-configuration>): Add alsa-lib. (pulseaudio-alsa-configuration): New procedure. (pulseaudio-service-type): Extend alsa-servcice-type.
This commit is contained in:
@@ -27878,24 +27878,47 @@ record as in this example:
|
|||||||
See below for details about @code{alsa-configuration}.
|
See below for details about @code{alsa-configuration}.
|
||||||
@end defvar
|
@end defvar
|
||||||
|
|
||||||
|
@deftp {Data Type} alsa-pcm-configuration
|
||||||
|
Data type representing an ALSA @code{pcm} block.
|
||||||
|
|
||||||
|
@table @asis
|
||||||
|
@item @code{alsa-pcm-configuration-type} (type: symbol)
|
||||||
|
The type of the PCM (if not builtin to alsa, should be introduced via a ``pcm_type'' block).
|
||||||
|
@item @code{alsa-pcm-configuration-hint} (type: maybe-string)
|
||||||
|
A human-readable description of the PCM.
|
||||||
|
|
||||||
|
@item @code{alsa-pcm-configuration-configuration} (type: list-of-string)
|
||||||
|
Raw additional configuration.
|
||||||
|
Each item will be printed on a separate line.
|
||||||
|
@end table
|
||||||
|
@end deftp
|
||||||
|
|
||||||
|
@deftp {Data Type} alsa-ctl-configuration
|
||||||
|
Data type representing an ALSA @code{ctl} block.
|
||||||
|
|
||||||
|
@table @asis
|
||||||
|
@item @code{alsa-pcm-configuration-type} (type: symbol)
|
||||||
|
The type of the ctl (if not builtin to alsa, should be introduced via a ``ctl_type'' block).
|
||||||
|
|
||||||
|
@item @code{alsa-pcm-configuration-configuration} (type: list-of-string)
|
||||||
|
Raw additional configuration.
|
||||||
|
Each item will be printed on a separate line.
|
||||||
|
@end table
|
||||||
|
@end deftp
|
||||||
|
|
||||||
@deftp {Data Type} alsa-configuration
|
@deftp {Data Type} alsa-configuration
|
||||||
Data type representing the configuration for @code{alsa-service}.
|
Data type representing the configuration for @code{alsa-service}.
|
||||||
|
|
||||||
@table @asis
|
@table @asis
|
||||||
@item @code{alsa-plugins} (default: @var{alsa-plugins})
|
@item @code{default-pcm} (default: #f)
|
||||||
@code{alsa-plugins} package to use.
|
The configuration to use for the default @code{pcm}.
|
||||||
|
|
||||||
@item @code{pulseaudio?} (default: @var{#t})
|
@item @code{default-ctl} (default: #f)
|
||||||
Whether ALSA applications should transparently be made to use the
|
The configuration to use for the default @code{ctl}.
|
||||||
@uref{https://www.pulseaudio.org/, PulseAudio} sound server.
|
|
||||||
|
|
||||||
Using PulseAudio allows you to run several sound-producing applications
|
|
||||||
at the same time and to individual control them @i{via}
|
|
||||||
@command{pavucontrol}, among other things.
|
|
||||||
|
|
||||||
@item @code{extra-options} (default: @var{""})
|
|
||||||
String to append to the @file{/etc/asound.conf} file.
|
|
||||||
|
|
||||||
|
@item @code{options} (default: '()) (type: list-of-strings)
|
||||||
|
Additional configuration strings to
|
||||||
|
append to the @file{/etc/asound.conf} file.
|
||||||
@end table
|
@end table
|
||||||
@end deftp
|
@end deftp
|
||||||
|
|
||||||
@@ -27934,6 +27957,12 @@ pcm.!default @{
|
|||||||
See @uref{https://www.alsa-project.org/main/index.php/Asoundrc} for the
|
See @uref{https://www.alsa-project.org/main/index.php/Asoundrc} for the
|
||||||
details.
|
details.
|
||||||
|
|
||||||
|
Services can likewise extend alsa-service-type to add options and
|
||||||
|
configure the default PCM and CTL. One service, which transparently
|
||||||
|
extends alsa-service-type to make use of the
|
||||||
|
@uref{https://www.pulseaudio.org/, PulseAudio} sound server,
|
||||||
|
is the pulseaudio-service-type, shown below.
|
||||||
|
|
||||||
@defvar pulseaudio-service-type
|
@defvar pulseaudio-service-type
|
||||||
This is the type for the @uref{https://www.pulseaudio.org/, PulseAudio}
|
This is the type for the @uref{https://www.pulseaudio.org/, PulseAudio}
|
||||||
sound server. It exists to allow system overrides of the default settings
|
sound server. It exists to allow system overrides of the default settings
|
||||||
@@ -27985,6 +28014,11 @@ commands, refer to @command{man pulse-cli-syntax}.
|
|||||||
|
|
||||||
@item @code{system-script-file} (default: @code{(file-append pulseaudio "/etc/pulse/system.pa")})
|
@item @code{system-script-file} (default: @code{(file-append pulseaudio "/etc/pulse/system.pa")})
|
||||||
Script file to use as @file{system.pa}.
|
Script file to use as @file{system.pa}.
|
||||||
|
|
||||||
|
@item @code{alsa-lib}
|
||||||
|
The alsa-lib package to use for defining the “pulse” pcm_type
|
||||||
|
and ctl_type.
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
The example below sets the default PulseAudio card profile, the default
|
The example below sets the default PulseAudio card profile, the default
|
||||||
|
|||||||
@@ -41,11 +41,20 @@
|
|||||||
#:use-module (gnu packages rust-apps)
|
#:use-module (gnu packages rust-apps)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:export (alsa-configuration
|
#:export (alsa-pcm-configuration
|
||||||
|
alsa-pcm-configuration-type
|
||||||
|
alsa-pcm-configuration-hint
|
||||||
|
alsa-pcm-configuration-configuration
|
||||||
|
|
||||||
|
alsa-ctl-configuration
|
||||||
|
alsa-ctl-configuration-type
|
||||||
|
alsa-ctl-configuration-configuration
|
||||||
|
|
||||||
|
alsa-configuration
|
||||||
alsa-configuration?
|
alsa-configuration?
|
||||||
alsa-configuration-alsa-plugins
|
alsa-configuration-default-ctl
|
||||||
alsa-configuration-pulseaudio?
|
alsa-configuration-default-pcm
|
||||||
alsa-configuration-extra-options
|
alsa-configuration-options
|
||||||
alsa-service-type
|
alsa-service-type
|
||||||
|
|
||||||
pulseaudio-configuration
|
pulseaudio-configuration
|
||||||
@@ -81,48 +90,70 @@
|
|||||||
;;; ALSA
|
;;; ALSA
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
|
(define-maybe/no-serialization string)
|
||||||
|
|
||||||
|
(define-configuration/no-serialization alsa-pcm-configuration
|
||||||
|
(type symbol "The PCM type.")
|
||||||
|
(hint maybe-string "A human-readable description of the PCM.")
|
||||||
|
(configuration
|
||||||
|
list-of-strings
|
||||||
|
"Additional configuration. Each item will be printed on a separate line."))
|
||||||
|
|
||||||
|
(define-configuration/no-serialization alsa-ctl-configuration
|
||||||
|
(type symbol "The CTL type.")
|
||||||
|
(configuration
|
||||||
|
list-of-strings
|
||||||
|
"Additional configuration. Each item will be printed on a separate line."))
|
||||||
|
|
||||||
(define-record-type* <alsa-configuration>
|
(define-record-type* <alsa-configuration>
|
||||||
alsa-configuration make-alsa-configuration alsa-configuration?
|
alsa-configuration make-alsa-configuration alsa-configuration?
|
||||||
(alsa-plugins alsa-configuration-alsa-plugins ;file-like
|
(default-pcm alsa-configuration-default-pcm (default #f))
|
||||||
(default alsa-plugins))
|
(default-ctl alsa-configuration-default-ctl (default #f))
|
||||||
(pulseaudio? alsa-configuration-pulseaudio? ;boolean
|
(options alsa-configuration-options ; string
|
||||||
(default #t))
|
(default (list))))
|
||||||
(extra-options alsa-configuration-extra-options ;string
|
|
||||||
(default "")))
|
(define (serialize-alsa-pcm-configuration config name)
|
||||||
|
(match-record config <alsa-pcm-configuration>
|
||||||
|
(type hint configuration)
|
||||||
|
#~(string-append
|
||||||
|
"pcm." #$name " {\n"
|
||||||
|
" type " #$(symbol->string type) "\n"
|
||||||
|
#$(if hint
|
||||||
|
(string-append " hint { show on; description \"" hint "\" }\n")
|
||||||
|
"")
|
||||||
|
#$(if (null? configuration) "" " ")
|
||||||
|
#$(string-join configuration "\n ")
|
||||||
|
"\n}")))
|
||||||
|
|
||||||
|
(define (serialize-alsa-ctl-configuration config name)
|
||||||
|
(match-record config <alsa-ctl-configuration>
|
||||||
|
(type configuration)
|
||||||
|
#~(string-append
|
||||||
|
"ctl." #$name " {\n"
|
||||||
|
" type " #$(symbol->string type) "\n"
|
||||||
|
#$(if (null? configuration) "" " ")
|
||||||
|
#$(string-join configuration "\n ")
|
||||||
|
"\n}")))
|
||||||
|
|
||||||
(define alsa-config-file
|
(define alsa-config-file
|
||||||
;; Return the ALSA configuration file.
|
;; Return the ALSA configuration file.
|
||||||
(match-lambda
|
(match-lambda
|
||||||
(($ <alsa-configuration> alsa-plugins pulseaudio? extra-options)
|
(($ <alsa-configuration> default-pcm default-ctl options)
|
||||||
(apply mixed-text-file "asound.conf"
|
(mixed-text-file
|
||||||
`("# Generated by 'alsa-service'.\n\n"
|
"asound.conf"
|
||||||
,@(if pulseaudio?
|
#~(string-join
|
||||||
`("# Use PulseAudio by default
|
(list
|
||||||
pcm_type.pulse {
|
"# Generated by 'alsa-service'"
|
||||||
lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
|
#$@options
|
||||||
"/lib/alsa-lib/libasound_module_pcm_pulse.so") "\"
|
#$@(if default-pcm
|
||||||
}
|
(list
|
||||||
|
(serialize-alsa-pcm-configuration default-pcm "!default"))
|
||||||
ctl_type.pulse {
|
|
||||||
lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
|
|
||||||
"/lib/alsa-lib/libasound_module_ctl_pulse.so") "\"
|
|
||||||
}
|
|
||||||
|
|
||||||
pcm.!default {
|
|
||||||
type pulse
|
|
||||||
fallback \"sysdefault\"
|
|
||||||
hint {
|
|
||||||
show on
|
|
||||||
description \"Default ALSA Output (currently PulseAudio Sound Server)\"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctl.!default {
|
|
||||||
type pulse
|
|
||||||
fallback \"sysdefault\"
|
|
||||||
}\n\n")
|
|
||||||
'())
|
'())
|
||||||
,extra-options)))))
|
#$@(if default-ctl
|
||||||
|
(list
|
||||||
|
(serialize-alsa-ctl-configuration default-ctl "!default"))
|
||||||
|
'()))
|
||||||
|
"\n")))))
|
||||||
|
|
||||||
(define (alsa-etc-service config)
|
(define (alsa-etc-service config)
|
||||||
(list `("asound.conf" ,(alsa-config-file config))))
|
(list `("asound.conf" ,(alsa-config-file config))))
|
||||||
@@ -132,6 +163,22 @@ ctl.!default {
|
|||||||
(name 'alsa)
|
(name 'alsa)
|
||||||
(extensions
|
(extensions
|
||||||
(list (service-extension etc-service-type alsa-etc-service)))
|
(list (service-extension etc-service-type alsa-etc-service)))
|
||||||
|
(compose concatenate)
|
||||||
|
(extend (lambda (config extensions)
|
||||||
|
(let* ((configs (cons config extensions))
|
||||||
|
(options (append-map (lambda (cfg)
|
||||||
|
(alsa-configuration-options cfg))
|
||||||
|
configs))
|
||||||
|
(default-pcm (any (lambda (cfg)
|
||||||
|
(alsa-configuration-default-pcm cfg))
|
||||||
|
(reverse configs)))
|
||||||
|
(default-ctl (any (lambda (cfg)
|
||||||
|
(alsa-configuration-default-ctl cfg))
|
||||||
|
(reverse configs))))
|
||||||
|
(alsa-configuration
|
||||||
|
(default-pcm default-pcm)
|
||||||
|
(default-ctl default-ctl)
|
||||||
|
(options options)))))
|
||||||
(default-value (alsa-configuration))
|
(default-value (alsa-configuration))
|
||||||
(description "Configure low-level Linux sound support, ALSA.")))
|
(description "Configure low-level Linux sound support, ALSA.")))
|
||||||
|
|
||||||
@@ -156,7 +203,10 @@ ctl.!default {
|
|||||||
(default '()))
|
(default '()))
|
||||||
(system-script-file pulseaudio-configuration-system-script-file
|
(system-script-file pulseaudio-configuration-system-script-file
|
||||||
(default
|
(default
|
||||||
(file-append pulseaudio "/etc/pulse/system.pa"))))
|
(file-append pulseaudio "/etc/pulse/system.pa")))
|
||||||
|
(alsa-lib pulseaudio-alsa-lib
|
||||||
|
(default #~(string-append #$alsa-plugins:pulseaudio
|
||||||
|
"/lib/alsa-lib"))))
|
||||||
|
|
||||||
(define (pulseaudio-conf-entry arg)
|
(define (pulseaudio-conf-entry arg)
|
||||||
(match arg
|
(match arg
|
||||||
@@ -237,11 +287,36 @@ computed-file object~%") file))))
|
|||||||
,(apply mixed-text-file "client.conf"
|
,(apply mixed-text-file "client.conf"
|
||||||
(map pulseaudio-conf-entry client-conf)))))))))
|
(map pulseaudio-conf-entry client-conf)))))))))
|
||||||
|
|
||||||
|
(define pulseaudio-alsa-configuration
|
||||||
|
(match-record-lambda <pulseaudio-configuration>
|
||||||
|
(alsa-lib)
|
||||||
|
(list
|
||||||
|
(alsa-configuration
|
||||||
|
(default-pcm
|
||||||
|
(alsa-pcm-configuration
|
||||||
|
(type 'pulse)
|
||||||
|
(hint "Default ALSA Output (currently PulseAudio Sound Server)")
|
||||||
|
(configuration (list "fallback \"sysdefault\""))))
|
||||||
|
(default-ctl
|
||||||
|
(alsa-ctl-configuration
|
||||||
|
(type 'pulse)
|
||||||
|
(configuration (list "fallback \"sysdefault\""))))
|
||||||
|
(options
|
||||||
|
(list
|
||||||
|
#~(string-append "pcm_type.pulse {
|
||||||
|
lib \"" #$alsa-lib "/libasound_module_pcm_pulse.so\"
|
||||||
|
}")
|
||||||
|
#~(string-append "ctl_type.pulse {
|
||||||
|
lib \"" #$alsa-lib "/libasound_module_ctl_pulse.so\"
|
||||||
|
}")))))))
|
||||||
|
|
||||||
(define pulseaudio-service-type
|
(define pulseaudio-service-type
|
||||||
(service-type
|
(service-type
|
||||||
(name 'pulseaudio)
|
(name 'pulseaudio)
|
||||||
(extensions
|
(extensions
|
||||||
(list (service-extension session-environment-service-type
|
(list (service-extension alsa-service-type
|
||||||
|
pulseaudio-alsa-configuration)
|
||||||
|
(service-extension session-environment-service-type
|
||||||
pulseaudio-environment)
|
pulseaudio-environment)
|
||||||
(service-extension etc-service-type pulseaudio-etc)
|
(service-extension etc-service-type pulseaudio-etc)
|
||||||
(service-extension udev-service-type (const (list pulseaudio)))))
|
(service-extension udev-service-type (const (list pulseaudio)))))
|
||||||
|
|||||||
Reference in New Issue
Block a user