nixos-configs/devices/homie/modules/home-assistant/bluetooth.nix
matt1432 e65fdd95eb
All checks were successful
Discord / discord commits (push) Has been skipped
feat(bluetooth): add script to turn on UE Boom speaker
2024-09-10 17:04:30 -04:00

79 lines
1.7 KiB
Nix

{
config,
pkgs,
...
}: {
environment.systemPackages = [
(pkgs.writeShellApplication {
name = "turnOnUE";
runtimeInputs = [config.hardware.bluetooth.package];
text = ''
cmd=0x0003
bt_device_addr=88:C6:26:93:4B:77
# This is the MAC address on the first line of `bluetootctl show`
# without the `:` and with `01` added at the end
bt_controller_addr=E848B8C8200001
exec gatttool -b $bt_device_addr --char-write-req --handle=$cmd --value=$bt_controller_addr
'';
})
];
# Setup Bluetooth
hardware.bluetooth = {
enable = true;
powerOnBoot = true;
settings = {
General = {
DiscoverableTimeout = 0;
Experimental = true;
KernelExperimental = true;
};
Policy.AutoEnable = "true";
};
};
# Have pulseaudio.service itself start at boot but after bluetooth
# so bluetooth accepts sound connections from the start.
systemd.user.services.pulseaudio.after = ["bluetooth.service"];
systemd.user.targets.default.wants = ["pulseaudio.service"];
# Allow pulseaudio to be managed by MPD
hardware.pulseaudio = {
enable = true;
extraConfig = ''
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
'';
};
# Setup MPD
services = {
home-assistant.extraComponents = [
"mpd"
];
mpd = {
enable = true;
network = {
listenAddress = "127.0.0.1";
port = 6600;
};
extraConfig = ''
audio_output {
type "pulse"
name "UE Boom 2"
sink "bluez_sink.88_C6_26_93_4B_77.a2dp_sink"
server "127.0.0.1"
}
'';
};
};
}