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
2.9 kB 82 lines
1{ self, ... }: 2{ 3 perSystem = 4 { pkgs, lib, ... }: 5 { 6 packages.muchsync = pkgs.symlinkJoin { 7 name = "muchsync"; 8 paths = [ 9 (pkgs.writeShellApplication { 10 name = "muchsync"; 11 runtimeInputs = [ 12 pkgs.muchsync 13 pkgs.notmuch 14 ] ++ lib.optionals pkgs.stdenv.isLinux [ 15 pkgs.iputils 16 ]; 17 text = '' 18 export NOTMUCH_CONFIG=${pkgs.writeText "notmuch-config" self.packages.${pkgs.system}.mutt.passthru.notmuchConfig} 19 20 set -efu 21 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 arguments look like flags or a hostname 45 has_hostname=false 46 for arg in "$@"; do 47 case "$arg" in 48 -*) ;; # This is a flag 49 *) has_hostname=true; break ;; # Found a non-flag argument 50 esac 51 done 52 53 # If only flags provided (or no args), do a sync with green host 54 if [ "$has_hostname" = "false" ]; then 55 host=$(find_green_host) 56 echo "Syncing with $host..." >&2 57 58 if [ "$host" = "tor" ]; then 59 # Build dependencies lazily 60 echo "Building tornade..." >&2 61 tornade_path=$(nix build --no-link --print-out-paths "${self}#tornade") 62 clan_path=$(nix build --no-link --print-out-paths "${self}#clan-cli") 63 64 # Get tor hostname using clan CLI 65 tor_hostname=$(CLAN_DIR="${self}" "$clan_path/bin/clan" vars get green tor-ssh/tor-hostname) 66 67 # Use muchsync with custom ssh command via tornade 68 exec muchsync "$@" -s "$tornade_path/bin/tornade ssh" lass@"$tor_hostname" 69 else 70 exec muchsync "$@" lass@"$host" 71 fi 72 else 73 # Pass through arguments to muchsync 74 exec muchsync "$@" 75 fi 76 ''; 77 }) 78 pkgs.muchsync 79 ]; 80 }; 81 }; 82}