This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

machines.coaxmetal: drop strom-pair, use bluetuith for pairing

The bespoke pairing script was fighting Xbox BT quirks (stale bonds,
pairing-mode timing) more than it helped. Remove it; bluetuith (already
installed via 2configs/pipewire.nix) is a cleaner TUI for pairing/managing
controllers.

+1 -114
+1 -114
machines/coaxmetal/strom.nix
··· 61 61 done' 62 62 ''; 63 63 64 - # Bluetooth pairing helper for Xbox Wireless Controllers. Run `strom-pair` 65 - # once per controller (as root / on the console, e.g. 66 - # `ssh root@coaxmetal.r strom-pair`): put the pad in pairing mode (hold the 67 - # Xbox button to power on, then hold the small round sync button on the top 68 - # edge until the light flashes rapidly) and the script blocks until it pairs 69 - # that one pad, then exits. A pad currently paired to another device is 70 - # re-paired here (its stale bond is cleared); a pad already connected and 71 - # working is left alone. Run once per controller. Bonded+trusted pads 72 - # reconnect on their own on every later boot. Pass a MAC to pair just one. 73 - strom-pair = pkgs.writeShellApplication { 74 - name = "strom-pair"; 75 - runtimeInputs = [ pkgs.bluez ]; 76 - text = '' 77 - # Find one Xbox pad that is here right now (advertising in pairing mode) 78 - # and not already connected; echo its MAC (empty if none). We key off what 79 - # actually shows up in THIS scan, not the bonded-device list: a pad that 80 - # was since re-paired to another host still lingers as "bonded" here but 81 - # only appears in a scan when it is genuinely present and pairable. 82 - find_target() { 83 - local sl m 84 - local -a bonded present 85 - sl=$(mktemp) 86 - bluetoothctl --timeout 12 scan on > "$sl" 2>&1 || true 87 - mapfile -t bonded < <(bluetoothctl devices 2>/dev/null | grep -i xbox | awk '{print $2}') 88 - # MACs of xbox pads that showed up in this scan (present + advertising). 89 - mapfile -t present < <( 90 - { 91 - # freshly discovered pads announce their name 92 - grep -i xbox "$sl" | grep -oiE '([0-9a-f]{2}:){5}[0-9a-f]{2}' 93 - # known/bonded pads emit nameless RSSI lines; match their MAC in-scan 94 - for m in "''${bonded[@]:-}"; do 95 - [ -n "$m" ] && grep -qiF "$m" "$sl" && printf '%s\n' "$m" 96 - done 97 - } | sort -uf 98 - ) 99 - rm -f "$sl" 100 - for m in "''${present[@]:-}"; do 101 - [ -n "$m" ] || continue 102 - bluetoothctl info "$m" 2>/dev/null | grep -q "Connected: yes" && continue 103 - printf '%s\n' "$m" 104 - return 0 105 - done 106 - return 0 107 - } 108 - 109 - # Pair one pad. Xbox controllers use JustWorks pairing, which needs a 110 - # NoInputNoOutput agent held in the SAME bluetoothctl session as `pair` 111 - # (plus disable_ertm, set system-wide below). Remove any existing bond 112 - # first: a pad re-paired to another host still shows bonded here but never 113 - # reconnects, and bluez refuses a fresh pair while that stale bond exists. 114 - # `connect` succeeds even when pairing fails, so success is judged by 115 - # "Bonded: yes", not by connect. 116 - pair_one() { 117 - local mac="$1" 118 - bluetoothctl remove "$mac" >/dev/null 2>&1 || true 119 - { 120 - echo "power on" 121 - echo "agent NoInputNoOutput" 122 - echo "default-agent" 123 - echo "scan on" 124 - sleep 14 125 - echo "pair $mac" 126 - sleep 12 127 - echo "trust $mac" 128 - echo "connect $mac" 129 - sleep 4 130 - echo "quit" 131 - } | bluetoothctl >/dev/null 2>&1 || true 132 - # Bonding can finalize a moment after the session exits; poll a few 133 - # seconds before deciding it failed. 134 - for _ in 1 2 3 4 5; do 135 - bluetoothctl info "$mac" 2>/dev/null | grep -q "Bonded: yes" && return 0 136 - sleep 1 137 - done 138 - return 1 139 - } 140 - 141 - bluetoothctl power on >/dev/null 2>&1 || true 142 - 143 - # Single-pad mode: (re)pair exactly the given MAC and exit. 144 - if [ -n "''${1:-}" ]; then 145 - if pair_one "$1"; then 146 - echo ">> paired, trusted, connected: $1" 147 - exit 0 148 - fi 149 - echo "!! could not pair $1." >&2 150 - exit 1 151 - fi 152 - 153 - # Default: wait for a pad that is present and in pairing mode, (re)pair it, 154 - # then exit. Run once per controller. A pad that was paired to another 155 - # device in the meantime is re-paired here (its stale bond is cleared) 156 - # rather than skipped; a pad already connected and working is left alone. 157 - echo ">> put a controller in pairing mode: hold the Xbox button to power" 158 - echo " on, then hold the small round sync button on the top edge until" 159 - echo " the light flashes rapidly. Waiting... (Ctrl-C to abort)" 160 - while true; do 161 - echo ">> scanning..." 162 - mac=$(find_target) 163 - if [ -n "$mac" ]; then 164 - printf '>> pairing %s ... ' "$mac" 165 - if pair_one "$mac"; then 166 - echo "OK" 167 - echo ">> paired, trusted, connected: $mac" 168 - exit 0 169 - fi 170 - echo "failed, retrying (keep it in pairing mode)" 171 - fi 172 - sleep 1 173 - done 174 - ''; 175 - }; 176 64 in 177 65 { 178 66 # Dedicated, unprivileged kiosk user. Gamepad input comes through evdev ··· 216 104 # `brightnessctl set 100%` / `brightnessctl set 50%`. 217 105 environment.systemPackages = [ 218 106 pkgs.brightnessctl 219 - strom-pair 220 107 ]; 221 108 services.udev.packages = [ pkgs.brightnessctl ]; 222 109 ··· 235 122 # mapping; the two bluez tweaks + disable_ertm are what make Xbox pads 236 123 # actually bond (without disable_ertm they fail with AuthenticationFailed). 237 124 # Bluetooth itself (adapter + powerOnBoot) already comes from 238 - # 2configs/pipewire.nix. Pair each pad once with `strom-pair` (see above). 125 + # 2configs/pipewire.nix. Pair pads with bluetuith (also from pipewire.nix). 239 126 hardware.xpadneo.enable = true; 240 127 # Xbox One/Series controllers pair over Bluetooth only with L2CAP ERTM off. 241 128 boot.extraModprobeConfig = "options bluetooth disable_ertm=1";