feat(hass): init spotifyd config
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
7fa5032311
commit
a58ff9e47a
4 changed files with 123 additions and 87 deletions
|
@ -1,5 +1,6 @@
|
||||||
{...}: {
|
{...}: {
|
||||||
imports = [
|
imports = [
|
||||||
./home-assistant
|
./home-assistant
|
||||||
|
./music
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,101 +4,56 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
# 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"];
|
|
||||||
|
|
||||||
# Turn On the speaker automatically when openwakeword is used
|
# Turn On the speaker automatically when openwakeword is used
|
||||||
services.home-assistant.config = {
|
services.home-assistant = {
|
||||||
shell_command.turn_on_ue = lib.getExe (pkgs.writeShellApplication {
|
extraComponents = [
|
||||||
name = "turnOnUE";
|
"mpd"
|
||||||
|
|
||||||
runtimeInputs = [config.hardware.bluetooth.package];
|
# BT components
|
||||||
|
"ibeacon"
|
||||||
text = ''
|
"led_ble"
|
||||||
cmd=0x0003
|
"kegtron"
|
||||||
bt_device_addr=88:C6:26:93:4B:77
|
"xiaomi_ble"
|
||||||
|
|
||||||
# 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
|
|
||||||
'';
|
|
||||||
});
|
|
||||||
automation = [
|
|
||||||
{
|
|
||||||
alias = "Turn On UE";
|
|
||||||
mode = "single";
|
|
||||||
trigger = [
|
|
||||||
{
|
|
||||||
platform = "state";
|
|
||||||
entity_id = "wake_word.openwakeword";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
condition = [];
|
|
||||||
action = [
|
|
||||||
{
|
|
||||||
action = "shell_command.turn_on_ue";
|
|
||||||
metadata = {};
|
|
||||||
data = {};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
};
|
|
||||||
|
|
||||||
# Allow pulseaudio to be managed by MPD
|
config = {
|
||||||
hardware.pulseaudio = {
|
shell_command.turn_on_ue = lib.getExe (pkgs.writeShellApplication {
|
||||||
enable = true;
|
name = "turnOnUE";
|
||||||
|
|
||||||
extraConfig = ''
|
runtimeInputs = [config.hardware.bluetooth.package];
|
||||||
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
# Setup MPD
|
text = ''
|
||||||
services.home-assistant.extraComponents = [
|
cmd=0x0003
|
||||||
"mpd"
|
bt_device_addr=88:C6:26:93:4B:77
|
||||||
|
|
||||||
# BT components
|
# This is the MAC address on the first line of `bluetootctl show`
|
||||||
"ibeacon"
|
# without the `:` and with `01` added at the end
|
||||||
"led_ble"
|
bt_controller_addr=E848B8C8200001
|
||||||
"kegtron"
|
|
||||||
"xiaomi_ble"
|
|
||||||
];
|
|
||||||
services.mpd = {
|
|
||||||
enable = true;
|
|
||||||
|
|
||||||
network = {
|
exec gatttool -b $bt_device_addr --char-write-req --handle=$cmd --value=$bt_controller_addr
|
||||||
listenAddress = "127.0.0.1";
|
'';
|
||||||
port = 6600;
|
});
|
||||||
|
|
||||||
|
automation = [
|
||||||
|
{
|
||||||
|
alias = "Turn On UE";
|
||||||
|
mode = "single";
|
||||||
|
trigger = [
|
||||||
|
{
|
||||||
|
platform = "state";
|
||||||
|
entity_id = "wake_word.openwakeword";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
condition = [];
|
||||||
|
action = [
|
||||||
|
{
|
||||||
|
action = "shell_command.turn_on_ue";
|
||||||
|
metadata = {};
|
||||||
|
data = {};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
80
devices/homie/modules/music/default.nix
Normal file
80
devices/homie/modules/music/default.nix
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
services = {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
spotifyd = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
settings.global = let
|
||||||
|
cacheDir = "/etc/spotifyd";
|
||||||
|
in {
|
||||||
|
device_name = config.networking.hostName;
|
||||||
|
device_type = "speaker";
|
||||||
|
|
||||||
|
zeroconf_port = 33797;
|
||||||
|
cache_path = cacheDir;
|
||||||
|
username_cmd = "${lib.getExe pkgs.jq} -r .username ${cacheDir}/credentials.json";
|
||||||
|
|
||||||
|
autoplay = false;
|
||||||
|
backend = "pulseaudio";
|
||||||
|
bitrate = 320;
|
||||||
|
no_audio_cache = true;
|
||||||
|
volume_normalisation = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.etc."spotifyd/credentials.json" = {
|
||||||
|
source = config.sops.secrets.spotifyd.path;
|
||||||
|
};
|
||||||
|
}
|
BIN
flake.lock
BIN
flake.lock
Binary file not shown.
Loading…
Reference in a new issue