about summary refs log tree commit diff
path: root/modules/hardware/bluetooth/default.nix
blob: cfb9a25f3372649940eaace7d2f98714c477ca58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ config, lib, pkgs, ... }:
let cfg = config.my.hardware.bluetooth;
in {
  options.my.hardware.bluetooth = with lib; {
    enable = mkEnableOption "bluetooth configuration";
  };

  config = lib.mkIf cfg.enable {
    hardware.bluetooth.enable = true;
    services.blueman.enable = true;

    hardware.pulseaudio = {
      extraModules = [ pkgs.pulseaudio-modules-bt ];
      package = pkgs.pulseaudioFull;
    };

    environment.etc = {
      "wireplumber/bluetooth.lua.d/50-bluez-config.lua".text = ''
        bluez_monitor.properties = {
          ["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]"
          -- mSBC provides better audio + microphone
          ["bluez5.enable-msbc"] = true,
          -- SBC XQ provides better audio
          ["bluez5.enable-sbc-xq"] = true,
          -- Hardware volume control
          ["bluez5.enable-hw-volume"] = true,
        }
      '';
    };

    services.pipewire = {
      media-session.config.bluez-monitor.rules = [
        {
          # Matches all cards
          matches = [{ "device.name" = "~bluez_card.*"; }];
          actions = {
            "update-props" = {
              "bluez5.reconnect-profiles" = [ "hfp_hf" "hsp_hs" "a2dp_sink" ];
              # mSBC provides better audio + microphone
              "bluez5.msbc-support" = true;
              # SBC XQ provides better audio
              "bluez5.sbc-xq-support" = true;
            };
          };
        }
        {
          matches = [
            # Matches all sources
            {
              "node.name" = "~bluez_input.*";
            }
            # Matches all outputs
            { "node.name" = "~bluez_output.*"; }
          ];
          actions = { "node.pause-on-idle" = false; };
        }
      ];
    };

    hardware.bluetooth.settings = {
      General = { Enable = "Source,Sink,Media,Socket"; };
    };
  };
}