From 8174bf56f8e9628d4d6c06d764cea82c1aff6113 Mon Sep 17 00:00:00 2001 From: elwrcl Date: Sat, 31 Oct 2026 15:15:30 +0300 Subject: [PATCH] obsidian --- hosts/copland.ulu.nix | 1 + .../home/home-obsidian-icloud-sync.ulu.nix | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 modules/home/home-obsidian-icloud-sync.ulu.nix diff --git a/hosts/copland.ulu.nix b/hosts/copland.ulu.nix index 93b617e..6c5e264 100644 --- a/hosts/copland.ulu.nix +++ b/hosts/copland.ulu.nix @@ -100,6 +100,7 @@ in config.flake.homeModules.home-discord-plugins config.flake.homeModules.home-thunderbird config.flake.homeModules.home-obsidian + config.flake.homeModules.home-obsidian-icloud-sync config.flake.homeModules.home-mpv config.flake.homeModules.home-mpv-intel-hard config.flake.homeModules.home-mpv-svp diff --git a/modules/home/home-obsidian-icloud-sync.ulu.nix b/modules/home/home-obsidian-icloud-sync.ulu.nix new file mode 100644 index 0000000..6d1285c --- /dev/null +++ b/modules/home/home-obsidian-icloud-sync.ulu.nix @@ -0,0 +1,59 @@ +{ ... }: +{ + flake.homeModules.home-obsidian-icloud-sync = + { config, pkgs, ... }: + let + vault = "${config.home.homeDirectory}/${config.programs.obsidian.vaults.notes.target}"; + remote = "icloud:Obsidian/elars"; + filters = pkgs.writeText "obsidian-icloud-filters.txt" '' + - .obsidian/** + - .trash/** + - .DS_Store + ''; + + sync = pkgs.writeShellScript "obsidian-icloud-sync" '' + workdir="${config.xdg.stateHome}/obsidian-icloud-sync" + ${pkgs.coreutils}/bin/mkdir -p "$workdir" + + resync=() + shopt -s nullglob + listings=("$workdir"/*.lst) + if [ ''${#listings[@]} -eq 0 ]; then + resync=(--resync) + fi + + if ! ${pkgs.diffutils}/bin/cmp -s ${filters} "$workdir/filters.txt"; then + ${pkgs.coreutils}/bin/install -m644 ${filters} "$workdir/filters.txt" + resync=(--resync) + fi + + exec ${pkgs.rclone}/bin/rclone bisync "${vault}" "${remote}" \ + --filters-file "$workdir/filters.txt" \ + --workdir "$workdir" \ + --resilient --recover --max-lock 2m \ + --conflict-resolve newer \ + "''${resync[@]}" + ''; + in + { + systemd.user.services.obsidian-icloud-sync = { + Unit = { + Description = "Obsidian vault <-> iCloud (rclone bisync)"; + After = [ "network-online.target" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${sync}"; + }; + }; + + systemd.user.timers.obsidian-icloud-sync = { + Unit.Description = "Periodic Obsidian iCloud sync"; + Timer = { + OnStartupSec = "1min"; + OnUnitInactiveSec = "3min"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; +}