summaryrefslogtreecommitdiffstats
path: root/systems
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-26 13:18:51 +0000
committertv <tv@krebsco.de>2026-11-26 13:18:51 +0000
commit3c072813ea3602e2eb22a96389c80665f31190ae (patch)
treef7ad225fe1f6e5c4e1918a52379032426ff38815 /systems
parent4e9d18fcf80146871b4460858e5c51712d91bb72 (diff)
qi: enable bluetooth
The adapter comes up without a public address; bluetooth-fix-public-address sets it, and bluetooth-reset rebinds the driver when the adapter hangs.
Diffstat (limited to 'systems')
-rw-r--r--systems/qi/config.nix68
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";