modules: hardware: sound: refactor options

Do not enable ALSA when using pipewire. Ensure that both pulseaudio and
pipewire are not configured at the same time.
This commit is contained in:
Bruno BELANYI 2021-06-26 23:35:31 +02:00
parent a5d3f7f861
commit 4b6f6423db
2 changed files with 17 additions and 7 deletions

View file

@ -1,8 +1,6 @@
{ ... }: { ... }:
{ {
my.hardware.sound = { my.hardware.sound = {
enable = true;
pipewire = { pipewire = {
enable = true; enable = true;
}; };

View file

@ -4,8 +4,6 @@ let
in in
{ {
options.my.hardware.sound = with lib; { options.my.hardware.sound = with lib; {
enable = mkEnableOption "sound configuration";
pipewire = { pipewire = {
enable = mkEnableOption "pipewire configuration"; enable = mkEnableOption "pipewire configuration";
}; };
@ -15,10 +13,21 @@ in
}; };
}; };
config = lib.mkIf cfg.enable (lib.mkMerge [ config = (lib.mkMerge [
# Basic configuration # Sanity check
{ {
sound.enable = true; assertions = [
{
assertion = builtins.all (lib.id) [
(cfg.pipewire.enable -> !cfg.pulse.enable)
(cfg.pulse.enable -> !cfg.pipewire.enable)
];
message = ''
`config.my.hardware.sound.pipewire.enable` and
`config.my.hardware.sound.pulse.enable` are incompatible.
'';
}
];
} }
(lib.mkIf cfg.pipewire.enable { (lib.mkIf cfg.pipewire.enable {
@ -49,6 +58,9 @@ in
# Pulseaudio setup # Pulseaudio setup
(lib.mkIf cfg.pulse.enable { (lib.mkIf cfg.pulse.enable {
# ALSA
sound.enable = true;
hardware.pulseaudio.enable = true; hardware.pulseaudio.enable = true;
}) })
]); ]);