From b3f2dab52bd3a8f88e1bfea75dc27f99d3d24dec Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 28 Sep 2024 21:33:11 -0400 Subject: [PATCH] feat(hass): setup a working SpotifyPlus --- .../modules/home-assistant/bluetooth.nix | 1 + .../homie/modules/home-assistant/default.nix | 2 + devices/homie/modules/music/default.nix | 74 ++++++++++-------- flake.lock | Bin 58057 -> 58057 bytes 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/devices/homie/modules/home-assistant/bluetooth.nix b/devices/homie/modules/home-assistant/bluetooth.nix index f87c6910..e9f227fe 100644 --- a/devices/homie/modules/home-assistant/bluetooth.nix +++ b/devices/homie/modules/home-assistant/bluetooth.nix @@ -36,6 +36,7 @@ in { extraComponents = [ "mpd" + "sonos" # BT components "ibeacon" diff --git a/devices/homie/modules/home-assistant/default.nix b/devices/homie/modules/home-assistant/default.nix index 86e37e6e..251836d4 100644 --- a/devices/homie/modules/home-assistant/default.nix +++ b/devices/homie/modules/home-assistant/default.nix @@ -48,7 +48,9 @@ enable = true; extraComponents = [ + "androidtv_remote" "caldav" + "cast" "holiday" "isal" "met" diff --git a/devices/homie/modules/music/default.nix b/devices/homie/modules/music/default.nix index fcabdcad..1cb05350 100644 --- a/devices/homie/modules/music/default.nix +++ b/devices/homie/modules/music/default.nix @@ -3,7 +3,10 @@ lib, pkgs, ... -}: { +}: let + inherit (lib) getExe; + inherit (config.vars) mainUser; +in { hardware.bluetooth = { enable = true; powerOnBoot = true; @@ -19,10 +22,17 @@ }; }; - # Have pulseaudio.service itself start at boot but after bluetooth + # Have pulseaudio and spotifyd 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"]; + users.users.${mainUser}.linger = true; + systemd.user.services = { + pulseaudio.after = ["bluetooth.service"]; + spotifyd.after = ["pulseaudio.service"]; + }; + systemd.user.targets.default.wants = [ + "pulseaudio.service" + "spotifyd.service" + ]; # Allow pulseaudio to be managed by MPD hardware.pulseaudio = { @@ -58,40 +68,38 @@ } ''; }; + }; - spotifyd = { - enable = true; + home-manager.users.${mainUser}.services.spotifyd = { + enable = true; - settings.global = let - cacheDir = "/etc/spotifyd"; - in { - device_name = config.networking.hostName + " connect"; - device_type = "speaker"; + package = pkgs.spotifyd.override { + withMpris = false; + withKeyring = false; + }; - zeroconf_port = 33798; - cache_path = cacheDir; - username_cmd = "${lib.getExe pkgs.jq} -r .username ${cacheDir}/credentials.json"; + settings.global = { + device_name = config.networking.hostName + " connect"; + device_type = "speaker"; - autoplay = false; - backend = "pulseaudio"; - bitrate = 320; - no_audio_cache = true; - volume_normalisation = false; - }; + zeroconf_port = 33798; + + autoplay = false; + backend = "pulseaudio"; + bitrate = 320; + no_audio_cache = true; + volume_normalisation = false; }; }; - environment.etc."spotifyd/credentials.json" = { - source = config.sops.secrets.spotifyd.path; - }; - - nixpkgs.overlays = [ - (final: prev: { - # FIXME: remove this if https://github.com/NixOS/nixpkgs/pull/342913 is merged - spotifyd = prev.spotifyd.override { - withMpris = false; - withKeyring = false; - }; - }) - ]; + systemd.services.home-assistant.preStart = let + WorkingDirectory = "/var/lib/hass"; + creds = config.sops.secrets.spotifyd.path; + in + getExe (pkgs.writeShellApplication { + name = "spotify-plus-creds"; + text = '' + cp -f ${creds} ${WorkingDirectory}/.storage/SpotifyWebApiPython_librespot_credentials.json + ''; + }); } diff --git a/flake.lock b/flake.lock index fe0146d1dd68764bb11da7a36ed075a32ae772f5..b4eeee55a369a98f86de5be8bf2a4c6675079d41 100644 GIT binary patch delta 258 zcmX?kl=d~9r*Pt@_*s&;}?S^K?lQ-JRX}e@uCI{+AT6pRCmZ{eSC%_Edin;GSwwmJXBV0KLT#6w9Cku(^8VxO>XvDysforZ w$%!e+rpAUTX(>r*W=UpgmZ{09iKZ5*#!1EomL?{alLPO8Tp+tS>_o8?0O4&}ng9R* delta 259 zcmXZUO)djb902e{Q}z}lqFqUdNqFzgysw4Cq>I*=$p}(v_dd%+Gi@n}l@r+fPv8a> z2VgVRF5L);1N?rAsx3L35Y+Y?9DEI@6ueKt#S*=93fhl(2on$7$SR zxA(*LDRFrRzL(aa{M>|TMYpXsgiCM3h%rr-(?$^MRA?gUrLve)BSI-a9j52q_d|g-~