mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-11 13:49:23 -05:00
services: pulseaudio: Add an extra-script-files configuration field.
* gnu/services/sound.scm (<pulseaudio-configuration>) [extra-script-files]: Add field. (extra-script-files->file-union): New procedure. (append-include-directive): Likewise. (pulseaudio-etc): Use them. * doc/guix.texi: Document the new 'extra-script-files- configuration field.
This commit is contained in:
parent
1cc9060ca3
commit
60cb647a28
2 changed files with 88 additions and 4 deletions
|
@ -21511,11 +21511,44 @@ List of settings to set in @file{daemon.conf}, formatted just like
|
|||
@var{client-conf}.
|
||||
|
||||
@item @code{script-file} (default: @code{(file-append pulseaudio "/etc/pulse/default.pa")})
|
||||
Script file to use as @file{default.pa}.
|
||||
Script file to use as @file{default.pa}. In case the
|
||||
@code{extra-script-files} field below is used, an @code{.include}
|
||||
directive pointing to @file{/etc/pulse/default.pa.d} is appended to the
|
||||
provided script.
|
||||
|
||||
@item @code{extra-script-files} (default: @code{'())})
|
||||
A list of file-like objects defining extra PulseAudio scripts to run at
|
||||
the initialization of the @command{pulseaudio} daemon, after the main
|
||||
@code{script-file}. The scripts are deployed to the
|
||||
@file{/etc/pulse/default.pa.d} directory; they should have the
|
||||
@samp{.pa} file name extension. For a reference of the available
|
||||
commands, refer to @command{man pulse-cli-syntax}.
|
||||
|
||||
@item @code{system-script-file} (default: @code{(file-append pulseaudio "/etc/pulse/system.pa")})
|
||||
Script file to use as @file{system.pa}.
|
||||
@end table
|
||||
|
||||
The example below sets the default PulseAudio card profile, the default
|
||||
sink and the default source to use for a old SoundBlaster Audigy sound
|
||||
card:
|
||||
@lisp
|
||||
(pulseaudio-configuration
|
||||
(extra-script-files
|
||||
(list (plain-file "audigy.pa"
|
||||
(string-append "\
|
||||
set-card-profile alsa_card.pci-0000_01_01.0 \
|
||||
output:analog-surround-40+input:analog-mono
|
||||
set-default-source alsa_input.pci-0000_01_01.0.analog-mono
|
||||
set-default-sink alsa_output.pci-0000_01_01.0.analog-surround-40\n")))))
|
||||
@end lisp
|
||||
|
||||
Note that @code{pulseaudio-service-type} is part of
|
||||
@code{%desktop-services}; if your operating system declaration was
|
||||
derived from one of the desktop templates, you'll want to adjust the
|
||||
above example to modify the existing @code{pulseaudio-service-type} via
|
||||
@code{modify-services} (@pxref{Service Reference,
|
||||
@code{modify-services}}), instead of defining a new one.
|
||||
|
||||
@end deftp
|
||||
|
||||
@deffn {Scheme Variable} ladspa-service-type
|
||||
|
|
|
@ -26,14 +26,17 @@ (define-module (gnu services sound)
|
|||
#:use-module (gnu services)
|
||||
#:use-module (gnu system pam)
|
||||
#:use-module (gnu system shadow)
|
||||
#:use-module (guix diagnostics)
|
||||
#:use-module (guix gexp)
|
||||
#:use-module (guix packages)
|
||||
#:use-module (guix records)
|
||||
#:use-module (guix store)
|
||||
#:use-module (guix ui)
|
||||
#:use-module (gnu packages audio)
|
||||
#:use-module (gnu packages linux)
|
||||
#:use-module (gnu packages pulseaudio)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:export (alsa-configuration
|
||||
alsa-service-type
|
||||
|
||||
|
@ -125,6 +128,8 @@ (define-record-type* <pulseaudio-configuration>
|
|||
(default '((flat-volumes . no))))
|
||||
(script-file pulseaudio-configuration-script-file
|
||||
(default (file-append pulseaudio "/etc/pulse/default.pa")))
|
||||
(extra-script-files pulseaudio-configuration-extra-script-files
|
||||
(default '()))
|
||||
(system-script-file pulseaudio-configuration-system-script-file
|
||||
(default
|
||||
(file-append pulseaudio "/etc/pulse/system.pa"))))
|
||||
|
@ -145,14 +150,60 @@ (define pulseaudio-environment
|
|||
("PULSE_CLIENTCONFIG" . ,(apply mixed-text-file "client.conf"
|
||||
(map pulseaudio-conf-entry client-conf)))))))
|
||||
|
||||
(define (extra-script-files->file-union extra-script-files)
|
||||
"Return a G-exp obtained by processing EXTRA-SCRIPT-FILES with FILE-UNION."
|
||||
|
||||
(define (file-like->name file)
|
||||
(match file
|
||||
((? local-file?)
|
||||
(local-file-name file))
|
||||
((? plain-file?)
|
||||
(plain-file-name file))
|
||||
((? computed-file?)
|
||||
(computed-file-name file))
|
||||
(_ (leave (G_ "~a is not a local-file, plain-file or \
|
||||
computed-file object~%") file))))
|
||||
|
||||
(define (assert-pulseaudio-script-file-name name)
|
||||
(unless (string-suffix? ".pa" name)
|
||||
(leave (G_ "`~a' lacks the required `.pa' file name extension~%") name))
|
||||
name)
|
||||
|
||||
(let ((labels (map (compose assert-pulseaudio-script-file-name
|
||||
file-like->name)
|
||||
extra-script-files)))
|
||||
(file-union "default.pa.d" (zip labels extra-script-files))))
|
||||
|
||||
(define (append-include-directive script-file)
|
||||
"Append an include directive to source scripts under /etc/pulse/default.pa.d."
|
||||
(computed-file "default.pa"
|
||||
#~(begin
|
||||
(use-modules (ice-9 textual-ports))
|
||||
(define script-text
|
||||
(call-with-input-file #$script-file get-string-all))
|
||||
(call-with-output-file #$output
|
||||
(lambda (port)
|
||||
(format port (string-append script-text "
|
||||
### Added by Guix to include scripts specified in extra-script-files.
|
||||
.nofail
|
||||
.include /etc/pulse/default.pa.d~%")))))))
|
||||
|
||||
(define pulseaudio-etc
|
||||
(match-lambda
|
||||
(($ <pulseaudio-configuration> _ _ default-script-file system-script-file)
|
||||
(($ <pulseaudio-configuration> _ _ default-script-file extra-script-files
|
||||
system-script-file)
|
||||
`(("pulse"
|
||||
,(file-union
|
||||
"pulse"
|
||||
`(("default.pa" ,default-script-file)
|
||||
("system.pa" ,system-script-file))))))))
|
||||
`(("default.pa"
|
||||
,(if (null? extra-script-files)
|
||||
default-script-file
|
||||
(append-include-directive default-script-file)))
|
||||
("system.pa" ,system-script-file)
|
||||
,@(if (null? extra-script-files)
|
||||
'()
|
||||
`(("default.pa.d" ,(extra-script-files->file-union
|
||||
extra-script-files)))))))))))
|
||||
|
||||
(define pulseaudio-service-type
|
||||
(service-type
|
||||
|
|
Loading…
Reference in a new issue