These instructions will help you create a systemd service that will restart the a bluetooth USB dongle, working around the need to unplug/replug the device. As always, YMMV.
First, find out the Vendor ID and Product ID of your bluetooth dongle:
$ nix-shell -p usbutils --run lsusb | grep -i bluetooth
Bus 003 Device 010: ID 1131:1004 Integrated System Solution Corp. Bluetooth Device
The Vendor ID and Product ID pair is found in the line, after ID. It is 1131:1004
for this particular device.
Then, in your configuration.nix
, create a systemd service that will run
{
# Forces a reset for specified bluetooth usb dongle.
systemd.services.fix-generic-usb-bluetooth-dongle = {
description = "Fixes for generic USB bluetooth dongle.";
wantedBy = [ "post-resume.target" ];
after = [ "post-resume.target" ];
script = builtins.readFile ./scripts/hack.usb.reset;
scriptArgs = "1131:1004"; # Vendor ID and Product ID here
serviceConfig.Type = "oneshot";
};
}
The script referenced in the script
attribute is attached to this gist.
The script IS dirty.
The script as of right now seems to work for every suspend/resume cycle I have tried.
No, I have not optimized it in full. I am probably doing dumb stuff.