-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules/pipewireLowLatency: use modular config files
Fixes breakage caused by NixOS/nixpkgs#220332.
- Loading branch information
Showing
1 changed file
with
54 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,85 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
# low-latency PipeWire configuration | ||
# extends the nixpkgs module | ||
let | ||
cfg = config.services.pipewire.lowLatency; | ||
qr = "${toString cfg.quantum}/${toString cfg.rate}"; | ||
json = pkgs.formats.json {}; | ||
in { | ||
options = { | ||
services.pipewire.lowLatency = { | ||
enable = lib.mkEnableOption "Enable low latency"; | ||
enable = lib.mkEnableOption (lib.mdDoc "Enable low latency"); | ||
|
||
quantum = lib.mkOption { | ||
description = "Minimum quantum to set"; | ||
description = lib.mdDoc "Minimum quantum to set"; | ||
type = lib.types.int; | ||
default = 64; | ||
example = 32; | ||
}; | ||
|
||
rate = lib.mkOption { | ||
description = "Rate to set"; | ||
description = lib.mdDoc "Rate to set"; | ||
type = lib.types.int; | ||
default = 48000; | ||
example = 96000; | ||
}; | ||
}; | ||
}; | ||
|
||
config = let | ||
qr = "${toString cfg.quantum}/${toString cfg.rate}"; | ||
in | ||
lib.mkIf cfg.enable { | ||
services.pipewire = { | ||
config = { | ||
# pipewire native config | ||
pipewire = { | ||
"context.properties" = {"default.clock.min-quantum" = cfg.quantum;}; | ||
}; | ||
|
||
# pulse clients config | ||
pipewire-pulse = { | ||
"context.properties" = {}; | ||
"context.modules" = [ | ||
{ | ||
name = "libpipewire-module-rtkit"; | ||
args = { | ||
"nice.level" = -15; | ||
"rt.prio" = 88; | ||
"rt.time.soft" = 200000; | ||
"rt.time.hard" = 200000; | ||
}; | ||
flags = ["ifexists" "nofail"]; | ||
} | ||
{name = "libpipewire-module-protocol-native";} | ||
{name = "libpipewire-module-client-node";} | ||
{name = "libpipewire-module-adapter";} | ||
{name = "libpipewire-module-metadata";} | ||
{ | ||
name = "libpipewire-module-protocol-pulse"; | ||
args = { | ||
"pulse.min.req" = qr; | ||
"pulse.min.quantum" = qr; | ||
"pulse.min.frag" = qr; | ||
"server.address" = ["unix:native"]; | ||
}; | ||
} | ||
]; | ||
config = lib.mkIf cfg.enable { | ||
# pipewire native config | ||
environment.etc = { | ||
"pipewire/pipewire.d/99-lowlatency.conf".source = json.generate "99-lowlatency.conf" { | ||
context.properties.default.clock.min-quantum = cfg.quantum; | ||
}; | ||
|
||
"stream.properties" = { | ||
"node.latency" = qr; | ||
"resample.quality" = 1; | ||
# pulse clients config | ||
"pipewire/pipewire-pulse.d/99-lowlatency.conf".source = json.generate "99-lowlatency.conf" { | ||
context.modules = [ | ||
{ | ||
name = "libpipewire-module-rtkit"; | ||
args = { | ||
nice.level = -15; | ||
rt.prio = 88; | ||
rt.time.soft = 200000; | ||
rt.time.hard = 200000; | ||
}; | ||
}; | ||
}; | ||
# lower latency alsa format | ||
media-session.config.alsa-monitor = { | ||
rules = [ | ||
{ | ||
matches = [{node.name = "alsa_output.*";}]; | ||
actions = { | ||
update-props = { | ||
"audio.format" = "S32LE"; | ||
"audio.rate" = cfg.rate * 2; | ||
"api.alsa.period-size" = 2; | ||
}; | ||
}; | ||
} | ||
]; | ||
flags = ["ifexists" "nofail"]; | ||
} | ||
{ | ||
name = "libpipewire-module-protocol-pulse"; | ||
args = { | ||
pulse.min.req = qr; | ||
pulse.min.quantum = qr; | ||
pulse.min.frag = qr; | ||
server.address = ["unix:native"]; | ||
}; | ||
} | ||
]; | ||
|
||
stream.properties = { | ||
node.latency = qr; | ||
resample.quality = 1; | ||
}; | ||
}; | ||
|
||
"wireplumber/main.lua.d/99-alsa-lowlatency.lua".text = '' | ||
alsa_monitor.rules = { | ||
{ | ||
matches = {{{ "node.name", "matches", "alsa_output.*" }}}; | ||
apply_properties = { | ||
["audio.format"] = "S32LE", | ||
["audio.rate"] = ${toString (cfg.rate * 2)}, | ||
["api.alsa.period-size"] = 2, | ||
}, | ||
}, | ||
} | ||
''; | ||
}; | ||
}; | ||
} |