6.5 KiB
6.5 KiB
name, description, version, author, license, metadata
| name | description | version | author | license | metadata | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| termux-go-builds | Build Go software from source on Termux. | 1 | hermes | MIT |
|
Building Go software from source on Termux (Android)
When to Use
- User asks to install software on an Android/Termux box and
pkghas no package (pkg searchmisses, or the package is glibc-only like most network daemons). - The target is a Go program (Tailscale, most CLI tooling, local LLM proxies, etc.). Go compiles cleanly for
android/arm64inside Termux — this is the reliable path where a.debinstall isn't.
Skip when: pkg install <name> works (always try that first — it's a minute vs. ten).
Verified workflow (Tailscale v1.104.2, 2026-10-23)
- Check the package manager first, then set up the toolchain:
pkg search tailscale # -> "Unable to locate package" is normal for these pkg install -y golang # Go 1.27.3, targets `android/arm64` out of the box - Shallow-clone the exact release tag (full repo is huge; use latest from GitHub API):
curl -s https://api.github.com/repos/tailscale/tailscale/releases/latest | grep -m1 tag_name git clone --depth 1 --branch v1.104.2 https://github.com/tailscale/tailscale.git src - Build with CGO OFF — Termux links against bionic, not glibc; static builds are the only sane target:
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -o tailscale ./cmd/tailscale
Build-tag pitfalls (the part you will not guess)
Go projects pin desktop-only deps behind platform tags; Android trips them both ways:
- Desktop systray deps (
fyne.io/systray) fail withundefined: nativeLoopetc. because the native files are linux/darwin-only. Tailscale's official escape hatch:-tags ts_omit_systray(seecmd/tailscale/cli/systray_omit.go: build tag!linux || ts_omit_systray). - Android-excluded features:
tailscale.com/feature/sshislinux && !androidand is imported bycmd/tailscaled/ssh.go— fails with "build constraints exclude all Go files". Official hatch:-tags ts_omit_ssh. - Taildrop extension:
-tags ts_omit_taildropexists (condregistermaybe_taildrop.go) and is also part of the verified daemon build; drop Taildrop if profiles are not needed, or if the daemon SIGSEGVs insidetaildrop.(*Extension).onChangeProfileon profile changes. - General rule: when a build dies on "undefined: X" from a desktop dep, or on
"build constraints exclude all Go files", grep the project for its
ts_omit_*/*_omitbuild tags andgo:buildconstraints around the failing import — projects ship first-class omit tags for exactly these cross-OS gaps. Don't fork code or edit build tags by hand; use the project's own.
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_systray -o tailscale ./cmd/tailscale
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_ssh,ts_omit_taildrop -o tailscaled ./cmd/tailscaled
Note: ts_omit_taildrop is optional but recommended — the daemon SIGSEGV'd inside
taildrop.(*Extension).onChangeProfile on profile change (see pitfalls); omitting
Taildrop removes that crash path.
Install into Termux's PATH
Termux's real prefix bin is $PREFIX/bin (/data/data/com.termux/files/usr/bin):
ln -sf $HOME/ts-build/tailscale $PREFIX/bin/tailscale
ln -sf $HOME/ts-build/tailscaled $PREFIX/bin/tailscaled
Verify with tailscale --version and tailscale --help (daemon binaries run --version fine standalone).
Android runtime caveats for network daemons
- No TUN without root: run userspace networking (
--tun=userspace-networkingon tailscaled) and expose traffic via local SOCKS5/HTTP proxy + SSH; it is NOT a system-wide VPN — other apps only see the mesh if routed through those local listeners. Say so to the user, don't let them believe a TUN is up. - How to actually REACH 100.x peers from this box (verified): direct
/dev/tcp/100.x.y.z/PORTand plain HTTP to 100.x addresses time out — without TUN there is no local route into the mesh. The way in is tailscaled's local listener:curl --socks5 127.0.0.1:1055 http://100.64.0.x:PORT/…✅ (verified reaching a peer's Hermes A2A server on :9900, HTTP 200)- SSH:
-o ProxyCommand='ncat --proxy 127.0.0.1:1055 --proxy-type socks5 %h %p'— notencat(Go nmap), NOTnc: the classicnc -X 5 -x host:portsyntax errors out on Termux's ncat. tailscale ping <100.x>works as a first reachability check (verified: pong in 9–56ms).- Tailnet host names (
macbook-robert) don't resolve from local curl — use the 100.x CNI IP (or enable Magic DNS at the control server). - What's open on a peer is up to that peer: a closed port times out either way. A2A (:9900) may be the only open service on a Hermes-agent box.
- Process lifetime = Termux lifetime: a
nohup-ed daemon dies when the user kills Termux. Recommend Termux wake-lock + keeping the session. - Custom socket paths: when tailscaled runs with
--socket <path>, the CLI needsTAILSCALE_SOCKET=<path>exported before CLI calls (or--socket <path>on the CLI), ortailscale statussays "it doesn't appear to be running". --stateis a FILE,--statediris a DIRECTORY. Starting the daemon with--state=<dir>(a directory) makes the CLI'supfail with500 … state store is unhealthy. Use--statedir=<dir>(it creates<dir>/tailscaled.state) or--state=<absolute-file>. Verified both ways in-session.- No
--logdirflag in the Android/user tailscaled build — running it with--logdir=…hard-exits withflag provided but not defined: -logdir(then dumps usage). Logs go to stdout. - Launching the daemon from Hermes: the terminal tool rejects shell-level
nohup … &wrappers. Starttailscaledvia the tool'sbackground=true(read its stdout withprocesspoll/log), then runtailscale upin a separate foreground call. (nohup … &is only for a raw human shell.) - Custom login server + hostname:
tailscale up --login-server=https://<host> --hostname=<name>prints a…/register/hskey-authreq-…URL for browser auth (verified reached the control server).
References & templates
references/tailscale-android.md— the complete verified Tailscale recipe: exact commands, flag list, state-dir layout, what is verified vs best-effort.templates/ts-up.sh— daemon start + connect helper (copy, adjust paths, feed the user's auth key).