Skip to content

Instantly share code, notes, and snippets.

@trickybestia
Last active March 15, 2025 11:58
Show Gist options
  • Save trickybestia/b3c3acfeab9204dd58ce677f9d6730ad to your computer and use it in GitHub Desktop.
Save trickybestia/b3c3acfeab9204dd58ce677f9d6730ad to your computer and use it in GitHub Desktop.
Installation of Unison file synchronizer in Termux on Android

I couldn't install OCaml in Termux, so there is workaround which uses x86-64 binaries and QEMU:

pkg install qemu-user-x86-64
curl -LO https://github.com/bcpierce00/unison/releases/download/v2.53.7/unison-2.53.7-ubuntu-x86_64-static.tar.gz
mkdir unison-unpacked
tar xvzf unison-2.53.7-ubuntu-x86_64-static.tar.gz -C unison-unpacked
cp unison-unpacked/bin/unison unison
cp unison-unpacked/bin/unison-fsmonitor unison-fsmonitor-bin
cat << EOF > unison-fsmonitor
#!/data/data/com.termux/files/usr/bin/bash
qemu-x86_64 /data/data/com.termux/files/home/unison-fsmonitor-bin
EOF
chmod +x unison-fsmonitor

To start continuous synchronization, run:

qemu-x86_64 unison -repeat watch -ignorelocks -fat -times "your_profile_name"

IDK if it's possible to create profile using Unison CLI, I just copied existing profile from PC and edited it like so:

~/.unison/profile.prf

# Unison preferences
root = /storage/emulated/0/Documents/my_synced_data
root = ssh://unison@serverhostname//home/unison/Sync/my_synced_data
sshargs = -C

If you don't want to enter ssh key password every time, you can create passwordless ssh key and use it on your serverhostname. Do not forget to update ~/.ssh/config in Termux!

~/.ssh/config

# place passwordless key first!
IdentityFile ~/.ssh/unison
# other keys (if you have any)

To start multiple profiles simultaneously:

bash -c "qemu-x86_64 unison -repeat watch -ignorelocks -fat -times 'profile1' & qemu-x86_64 unison -repeat watch -ignorelocks -fat -times 'profile2'"

You also can add following alias to ~/.profile to launch synchronization faster:

~/.profile

alias uuu="bash -c \"qemu-x86_64 unison -repeat watch -ignorelocks -fat -times 'profile1' & qemu-x86_64 unison -repeat watch -ignorelocks -fat -times 'profile'\""

Check out Termux:Widget if you want to create desktop shortcut!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment