Bluetooth: Difference between revisions
imported>Mic92 fix grammar; add link |
Added overskirde as an option for Bluetooth GUI management and a couple of TUI options as well |
||
(19 intermediate revisions by 14 users not shown) | |||
Line 1: | Line 1: | ||
==Enabling Bluetooth support== | ==Enabling Bluetooth support== | ||
To enable support for Bluetooth devices, | To enable support for Bluetooth devices, amend your system configuration as follows: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ | |||
... | ... | ||
hardware.bluetooth.enable = true; | hardware.bluetooth.enable = true; # enables support for Bluetooth | ||
hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot | |||
... | ... | ||
}</ | } | ||
</nowiki>}} | |||
{{evaluate}} | {{evaluate}} | ||
==Pairing Bluetooth devices== | ==Pairing Bluetooth devices== | ||
In order to use Bluetooth devices, they must be paired with your NixOS machine. Heavier desktop environments will usually provide a Bluetooth management GUI which you can use to pair devices. | In order to use Bluetooth devices, they must be paired with your NixOS machine. Heavier desktop environments will usually provide a Bluetooth management GUI which you can use to pair devices. | ||
Line 17: | Line 16: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.blueman.enable = true; | services.blueman.enable = true; | ||
</syntaxhighlight> | </syntaxhighlight>Another option for a GUI based Bluetooth management GUI can be [https://search.nixos.org/packages?channel=unstable&show=overskride&from=0&size=50&sort=relevance&type=packages&query=overskride overskirde] | ||
Alternatively if you wish to use a TUI<ref>https://en.wikipedia.org/wiki/Text-based_user_interface</ref> then check out [https://search.nixos.org/packages?channel=unstable&show=bluetuith&from=0&size=50&sort=relevance&type=packages&query=bluetui bluetuith] or [https://github.com/pythops/bluetui bluetui] | |||
===Pairing devices from the command line=== | ===Pairing devices from the command line=== | ||
Line 33: | Line 34: | ||
Bluetooth devices automatically connect with <tt>bluetoothctl</tt> as well: | Bluetooth devices automatically connect with <tt>bluetoothctl</tt> as well: | ||
<syntaxhighlight lang="console">$ bluetoothctl | <syntaxhighlight lang="console"> | ||
[bluetooth] # trust [hex-address]</syntaxhighlight> | $ bluetoothctl | ||
[bluetooth] # trust [hex-address] | |||
</syntaxhighlight> | |||
==Using Bluetooth headsets with PulseAudio== | ==Using Bluetooth headsets with PulseAudio== | ||
Line 41: | Line 44: | ||
<syntaxhighlight lang="nix">{ | <syntaxhighlight lang="nix">{ | ||
hardware.pulseaudio.enable = true; | |||
hardware.pulseaudio | |||
hardware.bluetooth.enable = true; | hardware.bluetooth.enable = true; | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
Line 69: | Line 63: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
systemd.user.services.mpris-proxy = { | systemd.user.services.mpris-proxy = { | ||
description = "Mpris proxy"; | |||
after = [ "network.target" "sound.target" ]; | |||
wantedBy = [ "default.target" ]; | |||
serviceConfig.ExecStart = "${pkgs.bluez}/bin/mpris-proxy"; | |||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Or, starting with Home Manager 21.05, enable the <code>mpris-proxy</code> service. | |||
===System-Wide PulseAudio === | ===System-Wide PulseAudio === | ||
Line 93: | Line 89: | ||
===Enabling extra codecs=== | ===Enabling extra codecs=== | ||
While pulseaudio itself only has support for the SBC bluetooth codec there is out-of-tree support for AAC, APTX, APTX-HD and LDAC. | While pulseaudio itself only has support for the SBC bluetooth codec there is out-of-tree support for AAC, APTX, APTX-HD and LDAC. | ||
Line 104: | Line 97: | ||
hardware.pulseaudio = { | hardware.pulseaudio = { | ||
enable = true; | enable = true; | ||
package = pkgs.pulseaudioFull; | package = pkgs.pulseaudioFull; | ||
}; | }; | ||
Line 114: | Line 106: | ||
Modern headsets will generally try to connect using the A2DP profile. To enable this for your bluetooth connection, add the following to <tt>/etc/nixos/configuration.nix</tt> | Modern headsets will generally try to connect using the A2DP profile. To enable this for your bluetooth connection, add the following to <tt>/etc/nixos/configuration.nix</tt> | ||
<syntaxhighlight lang="nix">{ | <syntaxhighlight lang="nix"> | ||
{ | |||
hardware.bluetooth. | hardware.bluetooth.settings = { | ||
General = { | |||
Enable = "Source,Sink,Media,Socket"; | |||
}; | |||
}; | |||
}</syntaxhighlight> | } | ||
</syntaxhighlight> | |||
This configuration may be unnecessary and does not work with bluez5 (<tt>Unknown key Enable for group General</tt> ). | This configuration may be unnecessary and does not work with bluez5 (<tt>Unknown key Enable for group General</tt> ). | ||
Line 134: | Line 127: | ||
* To enable A2DP, run: <syntaxhighlight lang="console">$ pacmd set-card-profile "$(pactl list cards short | egrep -o bluez_card[[:alnum:]._]+)" a2dp_sink</syntaxhighlight> | * To enable A2DP, run: <syntaxhighlight lang="console">$ pacmd set-card-profile "$(pactl list cards short | egrep -o bluez_card[[:alnum:]._]+)" a2dp_sink</syntaxhighlight> | ||
* To set the device as the default audio output, run: <syntaxhighlight lang="console">$ pacmd set-default-sink "$(pactl list sinks short | egrep -o bluez_sink[[:alnum:]._]+)"</syntaxhighlight> | * To set the device as the default audio output, run: <syntaxhighlight lang="console">$ pacmd set-default-sink "$(pactl list sinks short | egrep -o bluez_sink[[:alnum:]._]+)"</syntaxhighlight> | ||
You can also set pulseaudio to automatically switch audio to the connected bluetooth device when it connects, in order to do this add the following entry into the pulseaudio config | |||
<syntaxhighlight lang="nix">{ | |||
... | |||
hardware.pulseaudio.extraConfig = " | |||
load-module module-switch-on-connect | |||
"; | |||
... | |||
}</syntaxhighlight> | |||
Note that you may need to clear the pulseaudio config located at ~/.config/pulse to get this to work. Also you may have to unset and then set the default audio device to the bluetooth device, see https://github.com/NixOS/nixpkgs/issues/86441 for more info | |||
==Showing battery charge of bluetooth devices== | |||
If you want to see what charge your bluetooth devices have you have to enable experimental features, which might lead to bugs (according to [https://wiki.archlinux.org/title/Bluetooth_headset#Battery_level_reporting Arch Wiki). You can add the following to your config to enable experimental feature for bluetooth: | |||
<syntaxhighlight lang="nix">{ | |||
... | |||
hardware.bluetooth.settings = { | |||
General = { | |||
Experimental = true; | |||
}; | |||
}; | |||
... | |||
}</syntaxhighlight> | |||
Afterwards rebuild your system and then restart your bluetooth service by executing <syntaxhighlight lang="console">$ systemctl restart bluetooth</syntaxhighlight>. | |||
==Troubleshooting== | ==Troubleshooting== | ||
Line 173: | Line 191: | ||
This possibly can be fixed by restarting the display-manager session. The session management may have had an issue with registering your current session and doesn't allow you to control bluetooth. | This possibly can be fixed by restarting the display-manager session. The session management may have had an issue with registering your current session and doesn't allow you to control bluetooth. | ||
<syntaxhighlight> | <syntaxhighlight lang="console"> | ||
sudo systemctl restart display-manager.service | $ sudo systemctl restart display-manager.service | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== No audio when using headset in HSP/HFP mode === | |||
If the output of <code>dmesg | grep Bluetooth</code> shows a line similar to <code>Bluetooth: hci0: BCM: Patch brcm/BCM-0a5c-6410.hcd not found</code> then your machine uses a Broadcom chipset without the required firmware installed. | |||
To fix this, add <code>hardware.enableAllFirmware = true;</code> to your <tt>/etc/nixos/configuration.nix</tt> then reboot. | |||
==See also== | ==See also== | ||
* [http://anderspapitto.com/posts/2016-11-07-scripting_pulseaudio_bluetooth_jack.html Scripting PulseAudio, Bluetooth, JACK] | * [http://anderspapitto.com/posts/2016-11-07-scripting_pulseaudio_bluetooth_jack.html Scripting PulseAudio, Bluetooth, JACK] | ||
* [https://wiki.gentoo.org/wiki/Bluetooth Bluetooth (Gentoo Wiki)] | |||
* [https://wiki.archlinux.org/index.php/Bluetooth Bluetooth (Arch Linux Wiki)] | * [https://wiki.archlinux.org/index.php/Bluetooth Bluetooth (Arch Linux Wiki)] | ||
[[Category: | [[Category:Audio]][[Category:Configuration]][[Category:Hardware]] |