diff --git a/hosts/common/user/configs/gui/spicetify/config/merge.sh b/hosts/common/user/configs/gui/spicetify/config/merge.sh new file mode 100644 index 0000000..39eadb1 --- /dev/null +++ b/hosts/common/user/configs/gui/spicetify/config/merge.sh @@ -0,0 +1,19 @@ +SOURCE_FILE=$(realpath -m "$1") +TARGET_FILE=$(realpath -m "$2") + +mkdir -p "$(dirname "$TARGET_FILE")" + +TEMP_FILE=$(mktemp) +cat "$SOURCE_FILE" > "$TEMP_FILE" + +if [ -f "$TARGET_FILE" ]; then + while IFS='=' read -r key value; do + if ! grep -q "^${key}=" "$TEMP_FILE"; then + echo "${key}=${value}" >> "$TEMP_FILE" + fi + done < "$TARGET_FILE" +fi + +mv "$TEMP_FILE" "$TARGET_FILE" + +echo "Configuration file $TARGET_FILE has been updated." diff --git a/hosts/common/user/configs/gui/spicetify/config/prefs b/hosts/common/user/configs/gui/spicetify/config/prefs new file mode 100644 index 0000000..374b94b --- /dev/null +++ b/hosts/common/user/configs/gui/spicetify/config/prefs @@ -0,0 +1,2 @@ +app.autostart-mode="off" +storage.last-location="/home/nick/.cache/spotify/Storage" diff --git a/hosts/common/user/configs/gui/spicetify/config/user-prefs b/hosts/common/user/configs/gui/spicetify/config/user-prefs new file mode 100644 index 0000000..e5aef78 --- /dev/null +++ b/hosts/common/user/configs/gui/spicetify/config/user-prefs @@ -0,0 +1,7 @@ +audio.crossfade_v2=true +audio.allow_downgrade=false +audio.sync_bitrate_enumeration=4 +audio.play_bitrate_enumeration=4 +audio.play_bitrate_non_metered_migrated=true +audio.play_bitrate_non_metered_enumeration=4 +ui.track_notifications_enabled=false diff --git a/hosts/common/user/configs/gui/spicetify/default.nix b/hosts/common/user/configs/gui/spicetify/default.nix index 727a48e..2a0936a 100644 --- a/hosts/common/user/configs/gui/spicetify/default.nix +++ b/hosts/common/user/configs/gui/spicetify/default.nix @@ -5,6 +5,7 @@ { config, inputs, + lib, pkgs, ... }: @@ -58,6 +59,87 @@ ]; }; + systemd.user = { + services = + let + merge = lib.meta.getExe ( + pkgs.writeShellApplication { + name = "merge"; + runtimeInputs = with pkgs; [ + gnugrep + coreutils + ]; + text = builtins.readFile ./config/merge.sh; + } + ); + in + { + spotify-init = { + Unit = { + Description = "Populate Spotify preferences from template"; + After = config.environment.persistence."/persist"."${home}/.config/spotify".mount; + DefaultDependencies = false; + }; + + Service = { + ExecStart = "${merge} ${./config/prefs} ${home}/.config/spotify/prefs"; + Type = "oneshot"; + RemainAfterExit = true; + }; + }; + + spotify-init-user = { + Unit = { + Description = "Populate Spotify user preferences from template"; + After = config.environment.persistence."/persist"."${home}/.config/spotify".mount; + DefaultDependencies = false; + }; + + Service = { + ExecStart = lib.meta.getExe ( + pkgs.writeShellApplication { + name = "merge-user"; + text = '' + for USER_DIR in ${home}/.config/spotify/Users/*/; do + ${merge} ${./config/user-prefs} "$USER_DIR/prefs" + done + ''; + } + ); + Type = "oneshot"; + RemainAfterExit = true; + }; + }; + }; + + paths = { + spotify-init = { + Unit = { + Description = "Monitor Spotify directory"; + After = config.environment.persistence."/persist"."${home}/.config/spotify".mount; + }; + + Path.PathExists = "${home}/.config/spotify"; + + Install.WantedBy = [ "graphical-session.target" ]; + }; + + spotify-init-user = { + Unit = { + Description = "Monitor Spotify user directory"; + After = config.environment.persistence."/persist"."${home}/.config/spotify".mount; + }; + + Path = { + PathExists = "${home}/.config/spotify/Users"; + PathModified = "${home}/.config/spotify/Users"; + }; + + Install.WantedBy = [ "graphical-session.target" ]; + }; + }; + }; + theme.templates."${home}/.config/spotify/colors.css".source = ./colors.css; }; }