Connection issues for Bluetooth headphones

Got some Bluetooth headphones/earbuds that work without issue on Android and Windows, but I’m not having much luck getting them working in NixOS.

I can see the device appear in Blueman, and a connection attempt can be made, but it says “Connected” for a couple of seconds at most before disconnecting, and it goes around a loop of Connecting/Disconnecting for a few times before stopping.

When trying to connect using bluetoothctl, I get the following (N.B. In the text below “” is being used to replace the real device ID value that is shown in the terminal output):

[bluetooth]# [CHG] Device <deviceid> Connected: yes
[Epic Air Sport ANC]# Failed to connect: org.bluez.Error.Failed br-connection-canceled
[Epic Air Sport ANC]# [CHG] Device <deviceid> Connected: no

I read that the issue may be with authentication, so I tried using “sudo hciconfig noauth”, but this didn’t seem to alter the behaviour.

Any advice on how best to troubleshoot this?

In case it matters, here’s the audio/bluetooth settings from my configuration.nix file, I’m not 100% sure if these settings are correct:


  # Enable sound with pipewire.
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # Bluetooth settings
  services.pipewire.wireplumber.extraConfig."10-bluez" = {
    "monitor.bluez.properties" = {
      "bluez5.enable-sbc-xq" = true;
      "bluez5.enable-msbc" = true;
      "bluez5.enable-hw-volume" = true;
      "bluez5.headset-roles" = [
        "hsp_hs"
        "hsp_ag"
        "hfp_hf"
        "hfp_ag"
      ];
    };
  };

  hardware.bluetooth = {
    enable = true;
    powerOnBoot = true;
    settings = {
      General = {
        Name = "Computer";
        ControllerMode = "dual";
        FastConnectable = "true";
        Experimental = "true";
      };
      Policy = { AutoEnable = "true"; };
      LE = { EnableAdvMonInterleaveScan = "true"; };
    };
  };

  services.blueman.enable = true;

Those settings can mess with the device’s ability to connect if it doesn’t support what you’re setting. I would avoid configuring bluez at all until you get it to work, including using hardware.bluetooth.settings.

One way to figure out what’s going wrong is to havejournalctl -f and journalctl --user -f running in terminals while you connect your device. That way you will dump any log messages that occur during this time, which might help.

Also, fwiw, these symptoms are common if you exceed the number of devices that can be simultaneously connected to the bluetooth device. Most only support one or two. Make sure you don’t have e.g. a laptop and phone already connected.

1 Like

I recently had bluetooth connection issues with similar symptoms. Although that was on Kubuntu, not NixOS. So, the root cause may not be the same. I did eventually figure out what was going wrong and managed to fix it.

I found that btmon gives very detailed output of what happens when the headphones connect via bluetooth. If you have access to another Linux PC where the headphones are working properly, try running btmon there and collect the output in a file. Then on your problematic PC run btmon as well and try connecting the headphones. Collect the output to another file and compare them with a diff tool, for example meld. Then try to spot where the connection attempt starts to differ and if there are any error codes there that would explain what goes wrong.

For example I had following lines where things started to differ:

  • Succesful case: HCI Command: Link Key Request Reply (0x01|0x000b) plen 22
  • Failed case: HCI Command: Link Key Request Negative Reply (0x01|0x000c) plen 6

Then tried searching for codes 0x000b and 0x000c and bluetooth from internet. Found this page: List of HCI Commands

And from there found those codes and their meaning:

  • 0x000b = “Reply command to a link key request event sent from controller to the host”
  • 0x000c = “Reply command to a link key request event from the controller to the host if there is no link key associated with the connection.”

So, a new search with “bluez no link key associated with connection” and found ticket Bluez 5.71 causes initial auto-connect to fail with [Failed to load link keys for hci0] - git bisect done · Issue #686 · bluez/bluez · GitHub, which had a patch that, with some changes, fixed my issue.

1 Like