Update spotify config handling
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
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."
|
@@ -1,2 +1 @@
|
||||
app.autostart-mode="off"
|
||||
storage.last-location="/home/nick/.cache/spotify/Storage"
|
||||
|
@@ -9,6 +9,9 @@
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
hmConfig = config.home-manager.users.${user};
|
||||
in
|
||||
{
|
||||
networking.firewall = {
|
||||
allowedTCPPorts = [ 57621 ];
|
||||
@@ -59,84 +62,22 @@
|
||||
];
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
sops.secrets."spotify/username" = { };
|
||||
|
||||
Service = {
|
||||
ExecStart = "${merge} ${./config/prefs} ${home}/.config/spotify/prefs";
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
};
|
||||
xdg.configFile = {
|
||||
"spotify/prefs.init" = {
|
||||
source = ./config/prefs;
|
||||
onChange = ''
|
||||
${config.lib.runtime.merge.keyValue} "${home}/.config/spotify/prefs.init" "${home}/.config/spotify/prefs"
|
||||
'';
|
||||
};
|
||||
|
||||
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" ];
|
||||
};
|
||||
"spotify/prefs-user.init" = {
|
||||
source = ./config/prefs-user;
|
||||
onChange = ''
|
||||
user = $(cat "${hmConfig.sops.secrets."spotify/username".path}")
|
||||
${config.lib.runtime.merge.keyValue} "${home}/.config/spotify/prefs-user.init" "${home}/.config/spotify/Users/''${user}-user/prefs"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user