68 lines
2 KiB
Nix
68 lines
2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
inherit (lib) mkEnableOption mkIf;
|
|
in
|
|
{
|
|
options.hardware.bluetooth.enhanced.enable = mkEnableOption "Enhanced Bluetooth support";
|
|
|
|
config = mkIf config.hardware.bluetooth.enhanced.enable {
|
|
# Enable Bluetooth
|
|
hardware.bluetooth = {
|
|
enable = true;
|
|
powerOnBoot = true;
|
|
settings = {
|
|
General = {
|
|
Experimental = true;
|
|
};
|
|
};
|
|
};
|
|
|
|
# Bluetooth services
|
|
services.blueman.enable = true;
|
|
|
|
# Bluetooth packages
|
|
environment.systemPackages = with pkgs; [
|
|
bluez
|
|
bluez-tools
|
|
blueman
|
|
bluetui
|
|
];
|
|
|
|
# MT7925 bluetooth workaround — the bluetooth USB endpoint on
|
|
# Strix Halo can be slow to enumerate after warm reboot. Reloading
|
|
# modules helps. A cold boot (full power off) always works.
|
|
# See: https://github.com/moolooite/mt7925e-bt-heal
|
|
systemd.services.mt7925-bt-heal = {
|
|
description = "Unblock and power on MT7925 bluetooth";
|
|
after = [ "bluetooth.service" ];
|
|
wants = [ "bluetooth.service" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
ExecStartPre = "${pkgs.coreutils}/bin/sleep 5";
|
|
ExecStart = pkgs.writeShellScript "mt7925-bt-heal" ''
|
|
# Only unblock if adapter has a valid MAC (firmware loaded)
|
|
# A warm reboot leaves the adapter with 00:00:00:00:00:00
|
|
# and rfkill unblock would kill it — skip in that case.
|
|
MAC=$(${pkgs.bluez}/bin/hciconfig hci0 2>/dev/null | grep "BD Address" | awk '{print $3}')
|
|
if [ -z "$MAC" ] || [ "$MAC" = "00:00:00:00:00:00" ]; then
|
|
echo "Bluetooth adapter not ready (MAC: $MAC) — needs cold boot"
|
|
exit 0
|
|
fi
|
|
echo "Bluetooth adapter found: $MAC"
|
|
${pkgs.util-linux}/bin/rfkill unblock bluetooth
|
|
sleep 1
|
|
${pkgs.bluez}/bin/bluetoothctl power on
|
|
echo "Bluetooth powered on"
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|