Bluetooth: Difference between revisions
Add warning about laptops that use combo wifi bluetooth cards. Add `powerOnBoot` option to the setup section code. |
|||
| (8 intermediate revisions by 8 users not shown) | |||
| Line 1: | Line 1: | ||
==Setup== | ==Setup== | ||
To enable support for Bluetooth devices, amend your system configuration as follows and apply changes: | To enable support for Bluetooth devices, amend your system configuration as follows and apply changes: | ||
{{file|/etc/nixos/configuration.nix|nix| | {{file|3=hardware.bluetooth = { | ||
enable = true; | |||
powerOnBoot = false; | |||
};|name=/etc/nixos/configuration.nix|lang=nix}}{{Warning|Some laptops use combo bluetooth wifi cards that might reduce wifi quality when both bluetooth and wifi are enabled. If you encounter degraded network quality after setup this might be the cause.}} | |||
==Usage== | ==Usage== | ||
In order to use Bluetooth devices, they must be paired with your NixOS machine. Heavier [[:Category:Desktop_environment|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 [[:Category:Desktop_environment|desktop environments]] will usually provide a Bluetooth management GUI which you can use to pair devices. | ||
| Line 10: | Line 12: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.blueman.enable = true; | services.blueman.enable = true; | ||
</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 | </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 overskride] | ||
Alternatively if you wish to use a TUI<ref>https://en.wikipedia.org/wiki/Text-based_user_interface</ref> then check out [https:// | Alternatively if you wish to use a TUI<ref>https://en.wikipedia.org/wiki/Text-based_user_interface</ref> then check out [https://github.com/bluetuith-org/bluetuith bluetuith] or [https://github.com/pythops/bluetui bluetui] | ||
===Pairing devices from the command line=== | ===Pairing devices from the command line=== | ||
| Line 50: | Line 52: | ||
=== Using Bluetooth headset buttons to control media player === | === Using Bluetooth headset buttons to control media player === | ||
Many bluetooth headsets have buttons for pause/play or to skip to the next track. | |||
To make these buttons usable with media players supporting the dbus-based [https://specifications.freedesktop.org/mpris-spec/latest/ MPRIS] standard, | To make these buttons usable with media players supporting the dbus-based [https://specifications.freedesktop.org/mpris-spec/latest/ MPRIS] standard, | ||
one can use <code>mpris-proxy</code> that is part of bluez package. | one can use <code>mpris-proxy</code> that is part of bluez package. | ||
It can be used as a daemon in [[Home Manager]]:<syntaxhighlight lang="nix"> | |||
services.mpris-proxy.enable = true; | |||
</syntaxhighlight>For versions preceding Home Manager 21.05, the following snippet can be used: | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 64: | Line 68: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Some headsets (such as Sony's WH-1000XM series) also support AVRCP directly and as such <code>mpris-proxy</code> is not required for this functionality, as headset button presses will register as media key presses. If you are using a WM or a desktop environment which doesn't support media keys, you will have to set up keybindigs yourself; the keys are typically called <code>XF86AudioPlay</code>, <code>XF86AudioPause</code>, <code>XF86AudioNext</code>, and <code>XF86AudioPrev</code>. However, note that some functionality, such as "take off headphones to pause" on WH-1000XM4/5 requires two-way AVRCP communication to work properly, so `mpris-proxy` is still recommended if you wish to use it. It also may or may not help with Bluetooth multipoint. | |||
==== System-Wide PulseAudio ==== | ==== System-Wide PulseAudio ==== | ||
| Line 86: | Line 90: | ||
To enable extra codecs add the following to <tt>/etc/nixos/configuration.nix</tt>: | To enable extra codecs add the following to <tt>/etc/nixos/configuration.nix</tt>: | ||
< | <syntaxhighlight lang="nix"> | ||
{ | { | ||
... | ... | ||
services.pulseaudio = { | |||
enable = true; | enable = true; | ||
package = pkgs.pulseaudioFull; | package = pkgs.pulseaudioFull; | ||
| Line 95: | Line 99: | ||
... | ... | ||
} | } | ||
</ | </syntaxhighlight> | ||
==== Enabling A2DP Sink ==== | ==== Enabling A2DP Sink ==== | ||
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.settings = { | hardware.bluetooth.settings = { | ||
General = { | General = { | ||
| Line 107: | Line 111: | ||
}; | }; | ||
}; | }; | ||
} | ... | ||
</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 138: | ||
=== Showing battery charge of bluetooth devices === | === 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: | 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">{ | <syntaxhighlight lang="nix">{ | ||
... | ... | ||
| Line 150: | Line 154: | ||
Add following to your system config and apply it: | Add following to your system config and apply it: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 178: | Line 180: | ||
Run the command <code>asha_pipewire_sink</code> and choose your hearing aids as audio sink in your sound mixer application, for example <code>pavucontrol</code>. | Run the command <code>asha_pipewire_sink</code> and choose your hearing aids as audio sink in your sound mixer application, for example <code>pavucontrol</code>. | ||
=== File Transfer from/to Mobile Device === | === File Transfer from/to Mobile Device === | ||