Making MA530 Bluetooth USB adapter work on NixOS
Published on
Recently I purchased a brand-new, dirt-cheap (well, at least cheaper than products from their competitors) Bluetooth USB adapter. It’s a MA530 (V1) from Mercusys, and it was the “Last Status: works” on its corresponding page on linux-hardware.org that made me thought that the dongle works on Linux distributions out of the box. Unfortunately, it does not.
A quick search led me to [PATCH] Bluetooth: btusb: Add Mercusys MA530 HWID 0x2c4e/0x0115 for Realtek 8761BUV, a patch that adds an entry to the quirks_table in btusb.c:
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index f5609110f..0fc1dde8f 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -739,6 +739,8 @@ static const struct usb_device_id quirks_table[] = {
{ USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK },
/* Additional Realtek 8761BUV Bluetooth devices */
+ { USB_DEVICE(0x2c4e, 0x0115), .driver_info = BTUSB_REALTEK |
+ BTUSB_WIDEBAND_SPEECH },
{ USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK |
BTUSB_WIDEBAND_SPEECH },
{ USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK |A naïve way to apply this would be to add this patch to the boot.kernelPatches NixOS option, but I think doing so makes me build the kernel locally for every nixpkgs update, which is less than ideal. Instead, I hacked it as an out-of-tree kernel module:
- Copy
btusb.cfrom the kernel source and changed its name tobtusb_ma530in both the file name and thenamefield instruct usb_driver. - Apply the patch to
btusb.c. - Copy some headers that it needs from the kernel source:
btbcm.h,btintel.h,btmtk.h, andbtrtl.h. - Add a minimal
Makefileto build it. - Add a package in Nix.
The package can then be used in a NixOS configuration:
# Blacklist the original btusb module.
boot.blacklistedKernelModules = [ "btusb" ];
# Load our own btusb module.
boot.kernelModules = [ "btusb_ma530" ];The Bluetooth dongle worked after a rebuild and a reboot.
Links
- Kernel Hacking + Device Bringup on NixOS on uninsane.org
- GitHub - jeremyb31/bluetooth-6.8: bluetooth for ubuntu 6.8 kernel, a DKMS module for the same purpose for Ubuntu
- [SOLVED] bluetooth problems Mint 21 XFCE - Linux Mint Forums, some discussion that led to the above DKMS module