2018-04-28 06:30:20 -04:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2020-01-05 12:11:01 -05:00
|
|
|
|
;;; Copyright © 2018, 2020 Oleg Pykhalov <go.wigust@gmail.com>
|
2021-09-25 03:27:02 -04:00
|
|
|
|
;;; Copyright © 2020 Liliana Marie Prikler <liliana.prikler@gmail.com>
|
2020-05-06 11:48:42 -04:00
|
|
|
|
;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
|
2022-01-31 13:16:01 -05:00
|
|
|
|
;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
2018-04-28 06:30:20 -04: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 12:11:01 -05:00
|
|
|
|
#:use-module (gnu system pam)
|
2018-04-28 06:30:20 -04:00
|
|
|
|
#:use-module (gnu system shadow)
|
2022-01-31 14:17:51 -05:00
|
|
|
|
#:use-module (guix diagnostics)
|
2018-04-28 06:30:20 -04:00
|
|
|
|
#:use-module (guix gexp)
|
|
|
|
|
#:use-module (guix packages)
|
|
|
|
|
#:use-module (guix records)
|
|
|
|
|
#:use-module (guix store)
|
2022-01-31 14:17:51 -05:00
|
|
|
|
#:use-module (guix ui)
|
2020-01-05 12:11:01 -05:00
|
|
|
|
#:use-module (gnu packages audio)
|
2018-06-24 06:18:53 -04:00
|
|
|
|
#:use-module (gnu packages linux)
|
2018-04-28 06:30:20 -04:00
|
|
|
|
#:use-module (gnu packages pulseaudio)
|
|
|
|
|
#:use-module (ice-9 match)
|
2022-01-31 14:17:51 -05:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2018-04-28 06:30:20 -04:00
|
|
|
|
#:export (alsa-configuration
|
2020-01-05 12:11:01 -05:00
|
|
|
|
alsa-service-type
|
|
|
|
|
|
2020-01-09 20:48:19 -05:00
|
|
|
|
pulseaudio-configuration
|
2020-01-09 20:48:22 -05:00
|
|
|
|
pulseaudio-service-type
|
|
|
|
|
|
|
|
|
|
ladspa-configuration
|
|
|
|
|
ladspa-service-type))
|
2018-04-28 06:30:20 -04:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; Sound services.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; ALSA
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define-record-type* <alsa-configuration>
|
|
|
|
|
alsa-configuration make-alsa-configuration alsa-configuration?
|
2021-11-18 16:44:26 -05:00
|
|
|
|
(alsa-plugins alsa-configuration-alsa-plugins ;file-like
|
2018-06-24 06:18:53 -04:00
|
|
|
|
(default alsa-plugins))
|
2018-04-28 06:30:20 -04:00
|
|
|
|
(pulseaudio? alsa-configuration-pulseaudio? ;boolean
|
|
|
|
|
(default #t))
|
|
|
|
|
(extra-options alsa-configuration-extra-options ;string
|
|
|
|
|
(default "")))
|
|
|
|
|
|
2018-06-24 06:18:53 -04: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 06:30:20 -04: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 06:18:53 -04:00
|
|
|
|
}\n\n")
|
|
|
|
|
'())
|
|
|
|
|
,extra-options)))))
|
2018-04-28 06:30:20 -04: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 12:11:01 -05:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; PulseAudio
|
|
|
|
|
;;;
|
|
|
|
|
|
2020-01-09 20:48:19 -05:00
|
|
|
|
(define-record-type* <pulseaudio-configuration>
|
|
|
|
|
pulseaudio-configuration make-pulseaudio-configuration
|
|
|
|
|
pulseaudio-configuration?
|
2022-01-31 13:16:01 -05:00
|
|
|
|
(client-conf pulseaudio-configuration-client-conf
|
2020-01-09 20:48:19 -05:00
|
|
|
|
(default '()))
|
2022-01-31 13:16:01 -05:00
|
|
|
|
(daemon-conf pulseaudio-configuration-daemon-conf
|
2020-01-09 20:48:21 -05: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))))
|
2022-01-31 13:16:01 -05:00
|
|
|
|
(script-file pulseaudio-configuration-script-file
|
2020-01-09 20:48:19 -05:00
|
|
|
|
(default (file-append pulseaudio "/etc/pulse/default.pa")))
|
2022-01-31 14:17:51 -05:00
|
|
|
|
(extra-script-files pulseaudio-configuration-extra-script-files
|
|
|
|
|
(default '()))
|
2022-01-31 13:16:01 -05:00
|
|
|
|
(system-script-file pulseaudio-configuration-system-script-file
|
2020-01-09 20:48:19 -05:00
|
|
|
|
(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 11:48:42 -04:00
|
|
|
|
(define pulseaudio-environment
|
|
|
|
|
(match-lambda
|
|
|
|
|
(($ <pulseaudio-configuration> client-conf daemon-conf default-script-file)
|
2022-01-31 15:49:31 -05:00
|
|
|
|
;; These config files kept at a fixed location, so that the following
|
|
|
|
|
;; environment values are stable and do not require the user to reboot to
|
|
|
|
|
;; effect their PulseAudio configuration changes.
|
|
|
|
|
'(("PULSE_CONFIG" . "/etc/pulse/daemon.conf")
|
|
|
|
|
("PULSE_CLIENTCONFIG" . "/etc/pulse/client.conf")))))
|
2020-05-06 11:48:42 -04:00
|
|
|
|
|
2022-01-31 14:17:51 -05:00
|
|
|
|
(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~%")))))))
|
|
|
|
|
|
2020-01-09 20:48:19 -05:00
|
|
|
|
(define pulseaudio-etc
|
|
|
|
|
(match-lambda
|
2022-01-31 15:49:31 -05:00
|
|
|
|
(($ <pulseaudio-configuration> client-conf daemon-conf default-script-file
|
|
|
|
|
extra-script-files system-script-file)
|
2020-01-09 20:48:19 -05:00
|
|
|
|
`(("pulse"
|
|
|
|
|
,(file-union
|
|
|
|
|
"pulse"
|
2022-01-31 14:17:51 -05:00
|
|
|
|
`(("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
|
2022-01-31 15:49:31 -05:00
|
|
|
|
extra-script-files))))
|
|
|
|
|
,@(if (null? daemon-conf)
|
|
|
|
|
'()
|
|
|
|
|
`(("daemon.conf"
|
|
|
|
|
,(apply mixed-text-file "daemon.conf"
|
|
|
|
|
"default-script-file = " default-script-file "\n"
|
|
|
|
|
(map pulseaudio-conf-entry daemon-conf)))))
|
|
|
|
|
,@(if (null? client-conf)
|
|
|
|
|
'()
|
|
|
|
|
`(("client.conf"
|
|
|
|
|
,(apply mixed-text-file "client.conf"
|
|
|
|
|
(map pulseaudio-conf-entry client-conf))))))))))))
|
2020-01-05 12:11:01 -05:00
|
|
|
|
|
|
|
|
|
(define pulseaudio-service-type
|
|
|
|
|
(service-type
|
|
|
|
|
(name 'pulseaudio)
|
|
|
|
|
(extensions
|
|
|
|
|
(list (service-extension session-environment-service-type
|
2020-01-09 20:48:19 -05:00
|
|
|
|
pulseaudio-environment)
|
2022-01-30 22:24:02 -05:00
|
|
|
|
(service-extension etc-service-type pulseaudio-etc)
|
|
|
|
|
(service-extension udev-service-type (const (list pulseaudio)))))
|
2020-01-09 20:48:19 -05:00
|
|
|
|
(default-value (pulseaudio-configuration))
|
2020-01-05 12:11:01 -05:00
|
|
|
|
(description "Configure PulseAudio sound support.")))
|
|
|
|
|
|
2020-01-09 20:48:22 -05: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 06:30:20 -04:00
|
|
|
|
;;; sound.scm ends here
|