This repository has no description
2.6 kB
79 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 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 ${exePath} "$@" -s "$tornade_path/bin/tornade ssh" lass@"$tor_hostname"
69 else
70 exec ${exePath} "$@" lass@"$host"
71 fi
72 else
73 # Pass through arguments to muchsync
74 exec ${exePath} "$@"
75 fi
76 '';
77 };
78 };
79}