Compare commits

...

2 commits

Author SHA1 Message Date
de4f965a98
Add FreeTube syncing via Nextcloud
This part was "vibe coded" using Claude 3.7 Sonnet agent.
I figured this is a good low-impact thing to try it out with.
Was it worth it? I don't know.
2025-05-24 12:57:36 -05:00
622a054140
Document more dnf packages 2025-05-24 11:45:26 -05:00
3 changed files with 179 additions and 0 deletions

View file

@ -39,6 +39,91 @@
}; };
}; };
}; };
freetube-sync = {
enable = true;
config = {
Label = "local.home-manager.freetube-sync";
ProgramArguments = [
"/bin/sh"
"-c"
''
FREETUBE_CONFIG_DIR="$HOME/Library/Application Support/FreeTube"
NEXTCLOUD_DIR="$HOME/Nextcloud/Settings/FreeTube"
# Create directories if they don't exist
mkdir -p "$FREETUBE_CONFIG_DIR"
mkdir -p "$NEXTCLOUD_DIR"
# List of database files to sync
DB_FILES=("settings.db" "history.db" "playlists.db" "subscriptions.db")
# Initial sync if Nextcloud has db files but FreeTube doesn't
if [ -n "$(ls ''$NEXTCLOUD_DIR/*.db 2>/dev/null)" ] && [ ! -n "$(ls ''$FREETUBE_CONFIG_DIR/*.db 2>/dev/null)" ]; then
echo "Performing initial sync from Nextcloud to FreeTube"
for DB_FILE in "''${DB_FILES[@]}"; do
if [ -f "''$NEXTCLOUD_DIR/''$DB_FILE" ]; then
rsync -av --checksum "''$NEXTCLOUD_DIR/''$DB_FILE" "''$FREETUBE_CONFIG_DIR/''$DB_FILE"
fi
done
# If Nextcloud is empty but FreeTube has db files, copy to Nextcloud
elif [ ! -n "$(ls ''$NEXTCLOUD_DIR/*.db 2>/dev/null)" ] && [ -n "$(ls ''$FREETUBE_CONFIG_DIR/*.db 2>/dev/null)" ]; then
echo "Performing initial sync from FreeTube to Nextcloud"
for DB_FILE in "''${DB_FILES[@]}"; do
if [ -f "''$FREETUBE_CONFIG_DIR/''$DB_FILE" ]; then
rsync -av --checksum "''$FREETUBE_CONFIG_DIR/''$DB_FILE" "''$NEXTCLOUD_DIR/''$DB_FILE"
fi
done
else
# Process each database file individually
for DB_FILE in "''${DB_FILES[@]}"; do
FT_PATH="''$FREETUBE_CONFIG_DIR/''$DB_FILE"
NC_PATH="''$NEXTCLOUD_DIR/''$DB_FILE"
# Skip if neither file exists
if [ ! -f "''$FT_PATH" ] && [ ! -f "''$NC_PATH" ]; then
continue
fi
# If only one exists, copy it
if [ -f "''$FT_PATH" ] && [ ! -f "''$NC_PATH" ]; then
echo "Copying ''$DB_FILE from FreeTube to Nextcloud"
rsync -av "''$FT_PATH" "''$NC_PATH"
continue
fi
if [ ! -f "''$FT_PATH" ] && [ -f "''$NC_PATH" ]; then
echo "Copying ''$DB_FILE from Nextcloud to FreeTube"
rsync -av "''$NC_PATH" "''$FT_PATH"
continue
fi
# Both files exist, check which is newer
if [ "''$FT_PATH" -nt "''$NC_PATH" ]; then
echo "Syncing newer ''$DB_FILE from FreeTube to Nextcloud"
rsync -av --update "''$FT_PATH" "''$NC_PATH"
elif [ "''$NC_PATH" -nt "''$FT_PATH" ]; then
echo "Syncing newer ''$DB_FILE from Nextcloud to FreeTube"
rsync -av --update "''$NC_PATH" "''$FT_PATH"
else
# Same modification time, compare checksums
echo "Verifying ''$DB_FILE with checksum comparison"
rsync -av --checksum "''$NC_PATH" "''$FT_PATH"
rsync -av --checksum "''$FT_PATH" "''$NC_PATH"
fi
done
fi
''
];
RunAtLoad = true;
StartInterval = 300; # Run every 5 minutes (300 seconds)
StandardOutPath = "${config.home.homeDirectory}/Library/Logs/freetube-sync.log";
StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/freetube-sync-error.log";
EnvironmentVariables = {
PATH = "${lib.makeBinPath [ pkgs.rsync pkgs.findutils ]}:$PATH";
};
};
};
}; };
}; };
programs = { programs = {

View file

@ -16,20 +16,26 @@
# iucar/rstudio # iucar/rstudio
# dnf packages: # dnf packages:
# apptainer
# chromium # chromium
# firefoxpwa - The nix version installs an "immutable" runtime, which simply launches extra browser windows on non-NixOS # firefoxpwa - The nix version installs an "immutable" runtime, which simply launches extra browser windows on non-NixOS
# inkscape # inkscape
# kate # kate
# kdiff3
# krita # krita
# lutris
# musescore # musescore
# nextcloud-client # nextcloud-client
# nextcloud-client-dolphin # nextcloud-client-dolphin
# obs-studio # obs-studio
# podman-compose
# podman-docker
# qownnotes # qownnotes
# qt # qt
# rssguard # rssguard
# rstudio-desktop # rstudio-desktop
# steam # steam
# supertuxkart
# tailscale # tailscale
# thunderbird # thunderbird
# vlc # vlc

View file

@ -41,6 +41,94 @@ in {
}; };
Install = { WantedBy = [ "default.target" ]; }; Install = { WantedBy = [ "default.target" ]; };
}; };
freetube-sync = {
Unit = {
Description = "Sync FreeTube settings with Nextcloud";
After = [ "network.target" ];
};
Service = {
Type = "oneshot";
ExecStart = "${pkgs.writeShellScript "freetube-sync.sh" ''
FREETUBE_CONFIG_DIR="$HOME/.var/app/io.freetubeapp.FreeTube/config/FreeTube"
NEXTCLOUD_DIR="$HOME/Nextcloud/Settings/FreeTube"
# Create directories if they don't exist
mkdir -p "$FREETUBE_CONFIG_DIR"
mkdir -p "$NEXTCLOUD_DIR"
# List of database files to sync
DB_FILES=("settings.db" "history.db" "playlists.db" "subscriptions.db")
# Initial sync if Nextcloud has db files but FreeTube doesn't
if [ -n "$(ls -A $NEXTCLOUD_DIR/*.db 2>/dev/null)" ] && [ ! -n "$(ls -A $FREETUBE_CONFIG_DIR/*.db 2>/dev/null)" ]; then
echo "Performing initial sync from Nextcloud to FreeTube"
for DB_FILE in "''${DB_FILES[@]}"; do
if [ -f "$NEXTCLOUD_DIR/$DB_FILE" ]; then
rsync -av --checksum "$NEXTCLOUD_DIR/$DB_FILE" "$FREETUBE_CONFIG_DIR/$DB_FILE"
fi
done
# If Nextcloud is empty but FreeTube has db files, copy to Nextcloud
elif [ ! -n "$(ls -A $NEXTCLOUD_DIR/*.db 2>/dev/null)" ] && [ -n "$(ls -A $FREETUBE_CONFIG_DIR/*.db 2>/dev/null)" ]; then
echo "Performing initial sync from FreeTube to Nextcloud"
for DB_FILE in "''${DB_FILES[@]}"; do
if [ -f "$FREETUBE_CONFIG_DIR/$DB_FILE" ]; then
rsync -av --checksum "$FREETUBE_CONFIG_DIR/$DB_FILE" "$NEXTCLOUD_DIR/$DB_FILE"
fi
done
else
# Process each database file individually
for DB_FILE in "''${DB_FILES[@]}"; do
FT_PATH="$FREETUBE_CONFIG_DIR/$DB_FILE"
NC_PATH="$NEXTCLOUD_DIR/$DB_FILE"
# Skip if neither file exists
if [ ! -f "$FT_PATH" ] && [ ! -f "$NC_PATH" ]; then
continue
fi
# If only one exists, copy it
if [ -f "$FT_PATH" ] && [ ! -f "$NC_PATH" ]; then
echo "Copying $DB_FILE from FreeTube to Nextcloud"
rsync -av "$FT_PATH" "$NC_PATH"
continue
fi
if [ ! -f "$FT_PATH" ] && [ -f "$NC_PATH" ]; then
echo "Copying $DB_FILE from Nextcloud to FreeTube"
rsync -av "$NC_PATH" "$FT_PATH"
continue
fi
# Both files exist, check which is newer
if [ "$FT_PATH" -nt "$NC_PATH" ]; then
echo "Syncing newer $DB_FILE from FreeTube to Nextcloud"
rsync -av --update "$FT_PATH" "$NC_PATH"
elif [ "$NC_PATH" -nt "$FT_PATH" ]; then
echo "Syncing newer $DB_FILE from Nextcloud to FreeTube"
rsync -av --update "$NC_PATH" "$FT_PATH"
else
# Same modification time, compare checksums
echo "Verifying $DB_FILE with checksum comparison"
rsync -av --checksum "$NC_PATH" "$FT_PATH"
rsync -av --checksum "$FT_PATH" "$NC_PATH"
fi
done
fi
''}";
};
};
};
timers = {
freetube-sync = {
Unit = { Description = "Timer for FreeTube settings sync"; };
Timer = {
OnBootSec = "1m";
OnUnitActiveSec = "5m";
};
Install = { WantedBy = [ "timers.target" ]; };
};
}; };
}; };
xdg = { xdg = {