diff options
| -rw-r--r-- | systems/qi/config.nix | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/systems/qi/config.nix b/systems/qi/config.nix index b8f70a0c..e7aab4d2 100644 --- a/systems/qi/config.nix +++ b/systems/qi/config.nix @@ -88,6 +88,74 @@ pkgs.modem-connect ]; } + + { + hardware.bluetooth.enable = true; + nixpkgs.overlays = [(self: super: { + bluetooth-fix-public-address = self.writeDashBin "bluetooth-fix-public-address" '' + # usage: bluetooth-fix-public-address ADAPTER + set -efu + + PATH=${lib.makeBinPath [ + pkgs.bluez + pkgs.gnugrep + pkgs.gnused + ]} + + adapter=$1 + info=$(hciconfig "$adapter") + if echo "$info" | grep -q DOWN; then + address=$(echo "$info" | sed -rn 's/.*BD Address: ([0-9a-f:]+) .*/\1/p') + bluetoothctl mgmt.public-addr "$address" + fi + ''; + bluetooth-reset = self.writeDashBin "bluetooth-reset" '' + # usage: bluetooth-reset ADAPTER + set -efu + + PATH=${lib.makeBinPath [ + self.bluez + self.coreutils + self.gnugrep + self.systemd + ]} + + adapter=$1 + device=$(readlink -f /sys/class/bluetooth/"$adapter"/device) + driver=$(readlink -f "$device"/driver) + + device_name=$(basename "$device") + echo "$device_name" > "$driver"/unbind + echo "$device_name" > "$driver"/bind + + echo -n Waiting for device... >&2 + while hciconfig "$adapter" | grep -q INIT; do + sleep 1 + echo -n . >&2 + done + echo ok >&2 + + systemctl restart bluetooth-fix-public-address@"$adapter".service + ''; + })]; + environment.systemPackages = [ + pkgs.bluetooth-reset + pkgs.bluetuith + ]; + systemd.services."bluetooth-fix-public-address@" = { + after = [ "bluetooth.service" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.bluetooth-fix-public-address}/bin/bluetooth-fix-public-address %i"; + }; + }; + systemd.targets.bluetooth-fixes = { + wantedBy = [ "bluetooth.target" ]; + wants = [ + "bluetooth-fix-public-address@hci0.service" + ]; + }; + } ]; system.stateVersion = "24.11"; |
