Unverified Commit 5bf2637b authored by Hans Christian Schmitz's avatar Hans Christian Schmitz
Browse files

nixos/wireplumber: add config packages option

parent 054bba56
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -38,7 +38,9 @@ let

  configs = pkgs.buildEnv {
    name = "pipewire-configs";
    paths = configPackages ++ [ extraConfigPkg ];
    paths = configPackages
      ++ [ extraConfigPkg ]
      ++ lib.optionals cfg.wireplumber.enable cfg.wireplumber.configPackages;
    pathsToLink = [ "/share/pipewire" ];
  };
in {
+44 −27
Original line number Diff line number Diff line
@@ -23,39 +23,56 @@ in
        defaultText = lib.literalExpression "pkgs.wireplumber";
        description = lib.mdDoc "The WirePlumber derivation to use.";
      };

      configPackages = lib.mkOption {
        type = lib.types.listOf lib.types.package;
        default = [ ];
        description = lib.mdDoc ''
          List of packages that provide WirePlumber configuration, in the form of
          `share/wireplumber/*/*.lua` files.
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    assertions = [
      {
        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";
      }
    ];

    environment.systemPackages = [ cfg.package ];
  config =
    let
      configPackages = cfg.configPackages;

    environment.etc."wireplumber/main.lua.d/80-nixos.lua" = lib.mkIf (!pwUsedForAudio) {
      text = ''
      pwNotForAudioConfigPkg = pkgs.writeTextDir "share/wireplumber/main.lua.d/80-pw-not-for-audio.lua" ''
        -- PipeWire is not used for audio, so prevent it from grabbing audio devices
        alsa_monitor.enable = function() end
      '';
    };
    environment.etc."wireplumber/main.lua.d/80-systemwide.lua" = lib.mkIf config.services.pipewire.systemWide {
      text = ''
      systemwideConfigPkg = pkgs.writeTextDir "wireplumber/main.lua.d/80-systemwide.lua" ''
        -- When running system-wide, these settings need to be disabled (they
        -- use functions that aren't available on the system dbus).
        alsa_monitor.properties["alsa.reserve"] = false
        default_access.properties["enable-flatpak-portal"] = false
      '';
    };
    environment.etc."wireplumber/bluetooth.lua.d/80-systemwide.lua" = lib.mkIf config.services.pipewire.systemWide {
      text = ''
      systemwideBluetoothConfigPkg = pkgs.writeTextDir "wireplumber/bluetooth.lua.d/80-systemwide.lua" ''
        -- When running system-wide, logind-integration needs to be disabled.
        bluez_monitor.properties["with-logind"] = false
      '';

      configs = pkgs.buildEnv {
        name = "wireplumber-configs";
        paths = configPackages
          ++ lib.optional (!pwUsedForAudio) pwNotForAudioConfigPkg
          ++ lib.optionals config.services.pipewire.systemWide [ systemwideConfigPkg systemwideBluetoothConfigPkg ];
        pathsToLink = [ "/share/wireplumber" ];
      };
    in
    lib.mkIf cfg.enable {
      assertions = [
        {
          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";
        }
      ];

      environment.systemPackages = [ cfg.package ];

      environment.etc.wireplumber.source = "${configs}/share/wireplumber";

      systemd.packages = [ cfg.package ];