kotatsuyaki’s site

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:

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.