The bluetooth is unable to activate

hi it seems that Nixos isn’t detecting my Bluetooth USB adapter so I’m unable to activate Bluetooth (no Bluetooth found) when I try to turn my Bluetooth on

I’m new to nixos

I have this in my configuration.nix

hardware.bluetooth.package = pkgs.bluez;
  hardware.bluetooth = {
    enable = true;
    powerOnBoot = true;
    settings = {
      General = {
        Name = "Hello";
        ControllerMode = "dual";
        FastConnectable = "true";
        Experimental = "true";
      };
      Policy = {
        AutoEnable = "true";
      };
    };
  };
  services.blueman.enable = true;

and this when I run

❯ dmesg | grep -i bluetooth

[   53.565342] Bluetooth: Core ver 2.22
[   53.565363] NET: Registered PF_BLUETOOTH protocol family
[   53.565364] Bluetooth: HCI device and connection manager initialized
[   53.565367] Bluetooth: HCI socket layer initialized
[   53.565369] Bluetooth: L2CAP socket layer initialized
[   53.565373] Bluetooth: SCO socket layer initialized
[  130.799529] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[  130.799537] Bluetooth: BNEP socket layer initialized

lsusb | grep -i bluetooth

Bus 005 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

systemctl status bluetooth

 bluetooth.service - Bluetooth service
     Loaded: loaded (/etc/systemd/system/bluetooth.service; enabled; preset: enabled)
    Drop-In: /nix/store/gl0i377q27vhnjj46z2z84xcwxhfcqrp-system-units/bluetooth.service.d
             └─overrides.conf
     Active: active (running) since Tue 2024-12-03 17:20:39 CET; 21min ago
       Docs: man:bluetoothd(8)
   Main PID: 4015 (bluetoothd)
     Status: "Running"
         IP: 0B in, 0B out
         IO: 1.4M read, 0B written
      Tasks: 1 (limit: 18309)
     Memory: 2.2M (peak: 2.5M)
        CPU: 23ms
     CGroup: /system.slice/bluetooth.service
             └─4015 /nix/store/4jk7imhlawwja56kdvqwiiznjv19zv91-bluez-5.75/libexec/bluetooth/bluetoothd -f /etc/bluetooth/main.conf

Dec 03 17:20:39 nixos systemd[1]: Starting Bluetooth service...
Dec 03 17:20:39 nixos bluetoothd[4015]: Bluetooth daemon 5.75
Dec 03 17:20:39 nixos systemd[1]: Started Bluetooth service.
Dec 03 17:20:39 nixos bluetoothd[4015]: Starting SDP server
Dec 03 17:20:39 nixos bluetoothd[4015]: Bluetooth management interface 1.22 initialized

rfkill list all

0: phy0: Wireless LAN
        Soft blocked: yes
        Hard blocked: no

nix-shell -p nix-info --run “nix-info -m”

- system: `"x86_64-linux"`
 - host os: `Linux 6.6.56, NixOS, 24.05 (Uakari), 24.05.20241016.dc2e002`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - nixpkgs: `/nix/store/808lp63z6yiraikjpzcfk3xg1frpd2s0-source`

The output of rfkill from your system shows that the 0th interface is “soft blocked.” You can unblock it using rfkill unblock 0 and then restart the Bluetooth service with systemctl restart bluetooth.service.

1 Like

I tried that before didn’t work

❯ rfkill unblock 0
~
❯ systemctl restart bluetooth.service
~ took 2s
❯ bluetoothctl

Waiting to connect to bluetoothd…[bluetooth]# Agent registered
[bluetooth]# power on
No default controller available
[bluetooth]#

What does rfkill list 0 show now?

Might also want to run bluetoothctl with root privilege (sudo bluetoothctl) just to be sure.

❯ rfkill list 0
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no

same with sudo
❯ sudo bluetoothctl

[sudo] password for tig:
Waiting to connect to bluetoothd...[bluetooth]# Agent registered
[bluetooth]# power on
No default controller available
[bluetooth]#

Can you try this? usb - How do I get my bluetooth device working? - Ask Ubuntu

thank you for this i found this drivers - Error to load module btusb with kernel 4.10.0-20-generic - Ask Ubuntu
as linked but I still need to manually activate the Bluetooth with this

make -C /lib/modules/$(uname -r)/build M=$(pwd) clean
cp /usr/src/linux-headers-$(uname -r)/.config ./
cp /usr/src/linux-headers-$(uname -r)/Module.symvers Module.symvers
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
sudo cp btusb.ko /lib/modules/$(uname -r)/kernel/drivers/bluetooth
sudo modprobe -r btusb
sudo modprobe -v btusb

NixOS ships with the btusb kernel module. No need to compile it manually. (FYI, I don’t think your compilation was successful given that the directories /lib/modules and /usr/src don’t not exist on NixOS. Might want to check the output of those make commands.)

All you need to do now is to add the following to your configuration.nix and do a nixos-rebuild, you should be good to go:

boot.kernelModules = [ "btusb" ];

What’s surprising is that the btusb module wasn’t loaded automatically. That’s for another day though.

After I fixed it, I still had to executesudo modprobe -r btusb sudo modprobe -v btusb each reboot so i added this

 systemd.services.bluetooth-modprobe = {
  description = "Reload btusb module at boot";
  wantedBy = [ "multi-user.target" ];
  serviceConfig = {
    ExecStartPre = "/run/current-system/sw/bin/bash -c '/run/current-system/sw/bin/modprobe -r btusb'";  # Correct path to modprobe
    ExecStart = "/run/current-system/sw/bin/bash -c '/run/current-system/sw/bin/modprobe -v btusb'";  # Correct path to modprobe
  };
};

to my configuration.nix
It worked now, however boot.kernelModules = [ "btusb" ]; didn’t