nixos/wireplumber: inherit lib functions

This commit is contained in:
éclairevoyant 2024-03-26 16:23:39 -04:00
parent d2843640cb
commit 3aa01f7f13
No known key found for this signature in database
GPG Key ID: E3813AEAA02DB54B

View File

@ -1,31 +1,40 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
inherit (builtins) attrNames concatMap length;
inherit (lib) maintainers;
inherit (lib.attrsets) attrByPath filterAttrs;
inherit (lib.lists) flatten optional;
inherit (lib.modules) mkIf;
inherit (lib.options) literalExpression mkOption;
inherit (lib.strings) hasPrefix;
inherit (lib.types) bool listOf package;
pwCfg = config.services.pipewire; pwCfg = config.services.pipewire;
cfg = pwCfg.wireplumber; cfg = pwCfg.wireplumber;
pwUsedForAudio = pwCfg.audio.enable; pwUsedForAudio = pwCfg.audio.enable;
in in
{ {
meta.maintainers = [ lib.maintainers.k900 ]; meta.maintainers = [ maintainers.k900 ];
options = { options = {
services.pipewire.wireplumber = { services.pipewire.wireplumber = {
enable = lib.mkOption { enable = mkOption {
type = lib.types.bool; type = bool;
default = config.services.pipewire.enable; default = config.services.pipewire.enable;
defaultText = lib.literalExpression "config.services.pipewire.enable"; defaultText = literalExpression "config.services.pipewire.enable";
description = "Whether to enable WirePlumber, a modular session / policy manager for PipeWire"; description = "Whether to enable WirePlumber, a modular session / policy manager for PipeWire";
}; };
package = lib.mkOption { package = mkOption {
type = lib.types.package; type = package;
default = pkgs.wireplumber; default = pkgs.wireplumber;
defaultText = lib.literalExpression "pkgs.wireplumber"; defaultText = literalExpression "pkgs.wireplumber";
description = "The WirePlumber derivation to use."; description = "The WirePlumber derivation to use.";
}; };
configPackages = lib.mkOption { configPackages = mkOption {
type = lib.types.listOf lib.types.package; type = listOf package;
default = [ ]; default = [ ];
description = '' description = ''
List of packages that provide WirePlumber configuration, in the form of List of packages that provide WirePlumber configuration, in the form of
@ -36,10 +45,10 @@ in
''; '';
}; };
extraLv2Packages = lib.mkOption { extraLv2Packages = mkOption {
type = lib.types.listOf lib.types.package; type = listOf package;
default = []; default = [];
example = lib.literalExpression "[ pkgs.lsp-plugins ]"; example = literalExpression "[ pkgs.lsp-plugins ]";
description = '' description = ''
List of packages that provide LV2 plugins in `lib/lv2` that should List of packages that provide LV2 plugins in `lib/lv2` that should
be made available to WirePlumber for [filter chains][wiki-filter-chain]. be made available to WirePlumber for [filter chains][wiki-filter-chain].
@ -78,8 +87,8 @@ in
''; '';
configPackages = cfg.configPackages configPackages = cfg.configPackages
++ lib.optional (!pwUsedForAudio) pwNotForAudioConfigPkg ++ optional (!pwUsedForAudio) pwNotForAudioConfigPkg
++ lib.optional config.services.pipewire.systemWide systemwideConfigPkg; ++ optional config.services.pipewire.systemWide systemwideConfigPkg;
configs = pkgs.buildEnv { configs = pkgs.buildEnv {
name = "wireplumber-configs"; name = "wireplumber-configs";
@ -87,11 +96,11 @@ in
pathsToLink = [ "/share/wireplumber" ]; pathsToLink = [ "/share/wireplumber" ];
}; };
requiredLv2Packages = lib.flatten requiredLv2Packages = flatten
( (
lib.concatMap concatMap
(p: (p:
lib.attrByPath ["passthru" "requiredLv2Packages"] [] p attrByPath ["passthru" "requiredLv2Packages"] [] p
) )
configPackages configPackages
); );
@ -102,19 +111,19 @@ in
pathsToLink = [ "/lib/lv2" ]; pathsToLink = [ "/lib/lv2" ];
}; };
in in
lib.mkIf cfg.enable { mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = !config.hardware.bluetooth.hsphfpd.enable; assertion = !config.hardware.bluetooth.hsphfpd.enable;
message = "Using WirePlumber conflicts with hsphfpd, as it provides the same functionality. `hardware.bluetooth.hsphfpd.enable` needs be set to false"; message = "Using WirePlumber conflicts with hsphfpd, as it provides the same functionality. `hardware.bluetooth.hsphfpd.enable` needs be set to false";
} }
{ {
assertion = builtins.length assertion = length
(builtins.attrNames (attrNames
( (
lib.filterAttrs filterAttrs
(name: value: (name: value:
lib.hasPrefix "wireplumber/" name || name == "wireplumber" hasPrefix "wireplumber/" name || name == "wireplumber"
) )
config.environment.etc config.environment.etc
)) == 1; )) == 1;
@ -134,13 +143,13 @@ in
systemd.services.wireplumber.wantedBy = [ "pipewire.service" ]; systemd.services.wireplumber.wantedBy = [ "pipewire.service" ];
systemd.user.services.wireplumber.wantedBy = [ "pipewire.service" ]; systemd.user.services.wireplumber.wantedBy = [ "pipewire.service" ];
systemd.services.wireplumber.environment = lib.mkIf config.services.pipewire.systemWide { systemd.services.wireplumber.environment = mkIf config.services.pipewire.systemWide {
# Force WirePlumber to use system dbus. # Force WirePlumber to use system dbus.
DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket"; DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/dbus/system_bus_socket";
LV2_PATH = "${lv2Plugins}/lib/lv2"; LV2_PATH = "${lv2Plugins}/lib/lv2";
}; };
systemd.user.services.wireplumber.environment.LV2_PATH = systemd.user.services.wireplumber.environment.LV2_PATH =
lib.mkIf (!config.services.pipewire.systemWide) "${lv2Plugins}/lib/lv2"; mkIf (!config.services.pipewire.systemWide) "${lv2Plugins}/lib/lv2";
}; };
} }