This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / muchsync / flake-module.nix
3.1 kB 90 lines
1{ self, ... }: 2{ 3 perSystem = 4 { 5 pkgs, 6 lib, 7 system, 8 ... 9 }: 10 { 11 packages.muchsync = self.libWithPkgs.${system}.makeWrapper pkgs.muchsync { 12 runtimeInputs = [ pkgs.notmuch ] ++ lib.optionals pkgs.stdenv.isLinux [ pkgs.iputils ]; 13 env = { 14 NOTMUCH_CONFIG = 15 pkgs.writeText "notmuch-config" 16 self.packages.${pkgs.system}.mutt.passthru.notmuchConfig; 17 }; 18 wrapper = 19 { exePath, envString, ... }: 20 '' 21 ${envString} 22 # Create Maildir structure if it doesn't exist 23 mkdir -p "$HOME/Maildir"/{cur,new,tmp} 24 25 # Check if a host is reachable 26 check_host() { 27 local host=$1 28 ping -W2 -c1 "$host" >/dev/null 2>&1 29 } 30 31 # Smart host selection - try spora, nether, retiolum, then tor 32 find_green_host() { 33 if check_host green.s; then 34 echo "green.s" 35 elif check_host green.n; then 36 echo "green.n" 37 elif check_host green.r; then 38 echo "green.r" 39 else 40 echo "tor" 41 fi 42 } 43 44 # Check if we should do auto-sync 45 # Auto-sync if no args or only verbose/config flags 46 auto_sync=false 47 if [ $# -eq 0 ]; then 48 auto_sync=true 49 else 50 # Check if all args are sync-compatible flags 51 all_sync_flags=true 52 for arg in "$@"; do 53 case "$arg" in 54 -v|-vv|-vvv|--verbose) ;; # Verbose flags 55 --config|--config=*) ;; # Config flags 56 -*) all_sync_flags=false; break ;; # Unknown flag, don't auto-sync 57 *) all_sync_flags=false; break ;; # Non-flag argument, don't auto-sync 58 esac 59 done 60 if [ "$all_sync_flags" = true ]; then 61 auto_sync=true 62 fi 63 fi 64 65 if [ "$auto_sync" = true ]; then 66 host=$(find_green_host) 67 echo "Syncing with $host..." >&2 68 69 if [ "$host" = "tor" ]; then 70 # Build dependencies lazily 71 echo "Building tornade..." >&2 72 tornade_path=$(nix build --no-link --print-out-paths "${self}#tornade") 73 clan_path=$(nix build --no-link --print-out-paths "${self}#clan-cli") 74 75 # Get tor hostname using clan CLI 76 tor_hostname=$(CLAN_DIR="${self}" "$clan_path/bin/clan" vars get green tor-ssh/tor-hostname) 77 78 # Use muchsync with custom ssh command via tornade 79 exec ${exePath} "$@" -s "$tornade_path/bin/tornade ssh" lass@"$tor_hostname" 80 else 81 exec ${exePath} "$@" lass@"$host" 82 fi 83 else 84 # Pass through arguments to muchsync 85 exec ${exePath} "$@" 86 fi 87 ''; 88 }; 89 }; 90}