diff --git a/homes/darwin.nix b/homes/darwin.nix index 32cc0e2..9cabb63 100644 --- a/homes/darwin.nix +++ b/homes/darwin.nix @@ -31,6 +31,98 @@ tailscale = "/Applications/Tailscale.app/Contents/MacOS/Tailscale"; }; }; + launchd = { + enable = true; + agents = { + + 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" "profiles.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 = { bash = { profileExtra = '' diff --git a/homes/linux-desktop.nix b/homes/linux-desktop.nix index 8d25100..2516d48 100644 --- a/homes/linux-desktop.nix +++ b/homes/linux-desktop.nix @@ -18,6 +18,97 @@ in { ''; }; }; + systemd.user = { + services = { + 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" "profiles.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 = { configFile = { "plasma-workspace/env/ZED_WINDOW_DECORATIONS.sh".text = diff --git a/playbooks/packages.yaml b/playbooks/packages.yaml index f293815..f13c01b 100644 --- a/playbooks/packages.yaml +++ b/playbooks/packages.yaml @@ -83,6 +83,7 @@ - com.logseq.Logseq - com.slack.Slack - dev.deedles.Trayscale + - io.freetubeapp.FreeTube - io.github.alainm23.planify - io.github.dweymouth.supersonic - io.openrct2.OpenRCT2 diff --git a/programs/firefox.nix b/programs/firefox.nix index dcf0553..ed6705f 100644 --- a/programs/firefox.nix +++ b/programs/firefox.nix @@ -35,6 +35,7 @@ [ bitwarden multi-account-containers + libredirect old-reddit-redirect ublock-origin user-agent-string-switcher diff --git a/systems/darwin/corianne.nix b/systems/darwin/corianne.nix index a029992..c83a9a1 100644 --- a/systems/darwin/corianne.nix +++ b/systems/darwin/corianne.nix @@ -208,7 +208,9 @@ in { casks = [ "alt-tab" "db-browser-for-sqlite" + "dolphin" "firefox" + "freetube" "inkscape" "iterm2" "logseq"