nixfiles/modules/ezpw.nix

95 lines
2.4 KiB
Nix

{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.ezpw;
in {
options.services.ezpw = {
enable = mkEnableOption "Enable pipewire";
lowLatency = mkOption {
type = types.bool;
description = "Enable low latency configuration";
default = true;
};
usbSoundcard = mkOption {
type = types.bool;
description = "Doubles the audio rate for alsa outputs in low latency mode";
default = false;
};
periodSize = mkOption {
type = types.int;
description = ''
Pipewire period size in low latency mode ("tweak by trial-and-error")'';
default = 32;
};
rate = mkOption {
type = types.int;
description = "Pipewire rate in low latency mode";
default = 48000;
};
quantum = mkOption {
type = types.int;
description = "Pipewire quantum in low latency mode";
default = 64;
};
};
config = let
qr = "${toString cfg.quantum}/${toString cfg.rate}";
in
mkIf cfg.enable {
hardware.pulseaudio.enable = lib.mkDefault false;
sound.enable = lib.mkDefault false;
services.pipewire = {
enable = lib.mkDefault true;
jack.enable = lib.mkDefault true;
alsa.enable = lib.mkDefault true;
alsa.support32Bit = lib.mkDefault true;
pulse.enable = lib.mkDefault true;
wireplumber.enable = lib.mkDefault true;
};
environment.systemPackages = with pkgs; [
# pactl is required for pipewire-pulse
pulseaudio
];
environment.etc."wireplumber/main.lua.d/51-alsa-config.lua" = mkIf cfg.lowLatency {
text = ''
alsa_monitor.properties = {
["audio.rate"] = ${
toString (cfg.rate
* (
if cfg.usbSoundcard
then 2
else 1
))
},
["audio.format"] = "S32LE",
["api.alsa.headroom"] = 512,
["api.alsa.period-size"] = ${toString cfg.periodSize}
}
'';
};
environment.etc."wireplumber/bluetooth.lua.d/51-bluez-config.lua".text = ''
bluez_monitor.properties = {
["bluez5.enable-sbc-xq"] = true,
["bluez5.enable-msbc"] = true,
["bluez5.enable-hw-volume"] = true,
["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]"
}
'';
};
}