Bluetooth

From NixOS Wiki
Revision as of 20:37, 14 October 2017 by imported>Samueldr (Adds a troubleshooting section for bad bluetooth usb dongles.)

Enabling

Enabling bluetooth support is as simple as adding hardware.bluetooth.enable to configuration.nix

{
  hardware.bluetooth.enable = true;
}

Pairing

Bigger desktop environments will usually provide a bluetooth management system.

Alternatively, using pkgs.blueman, it is possible to get a tray icon blueman-applet or use the manager directly using blueman-manager.

Pairing without GUI tools

When not using a desktop-manager, configuring the device from the command line can be done following the ArchWiki instructions, as follows.

$ bluetoothctl
[bluetooth] # power on
[bluetooth] # agent on
[bluetooth] # default-agent
[bluetooth] # scan on
...put device in pairing mode and wait [hex-address] to appear here...
[bluetooth] # pair [hex-address]
[bluetooth] # connect [hex-address]

Bluetooth headsets with PulseAudio

The package used for PulseAudio has to be pkgs.pulseaudioFull, which includes bluetooth support.

{
  hardware.pulseaudio = {
    enable = true;
    package = pkgs.pulseaudioFull;
  };
  hardware.bluetooth.enable = true;
}

Either restart the system for PulseAudio to load the bluetooth module, or restart your local instance of PulseAudio by running pkill ^pulseaudio$.

Ensure PulseAudio has loaded bluetooth modules by using pactl list | grep -i Name.*module.*blue. Bluetooth modules should be present in the list.

Managing the audio interface

Using pavucontrol, the headset profile can be changed to "High Fidelity Playback (A2DP Sink)" in the Configuration tab.

The default sink can be changed in the Output Devices tab. clicking on the right most button, which it title Set as fallback.

Managing the audio interface using pacmd

Setting the card to A2DP

$ pacmd set-card-profile "$(pactl list cards short | egrep -o bluez_card[[:alnum:]._]+)" a2dp_sink

Setting the bluetooth sink as default

$ pacmd set-default-sink "$(pactl list sinks short | egrep -o bluez_sink[[:alnum:]._]+)"

Troubleshooting

USB device needs to be unplugged/re-plugged after suspend

Some USB devices/hosts combinations don't play well with the suspend/resume cycle, and needs to be unplugged and then re-plugged to work again.

It is possible to simulate a unplug/re-plug cycle using the /sys/ filesystem.

This gist provides a script and instructions to set-up a workaround for these devices.

External resources