Skills von pixel: autonomous-ai-agents/hermes-a2a software-development/android-debugging-from-termux software-development/termux-go-builds
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
---
|
||||
name: termux-go-builds
|
||||
description: "Build Go software from source on Termux."
|
||||
version: 1
|
||||
author: hermes
|
||||
license: MIT
|
||||
metadata:
|
||||
hermes:
|
||||
tags: [termux, android, go, build, tailscale, network, from-source]
|
||||
related_skills: [android-debugging-from-termux]
|
||||
---
|
||||
|
||||
# Building Go software from source on Termux (Android)
|
||||
|
||||
## When to Use
|
||||
- User asks to install software on an Android/Termux box and `pkg` has no package (`pkg search` misses, 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/arm64` inside Termux — this is the reliable path where a `.deb` install 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)
|
||||
|
||||
1. **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
|
||||
```
|
||||
2. **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
|
||||
```
|
||||
3. **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 with `undefined: nativeLoop` etc.
|
||||
because the native files are linux/darwin-only. Tailscale's official escape hatch:
|
||||
`-tags ts_omit_systray` (see `cmd/tailscale/cli/systray_omit.go`: build tag `!linux || ts_omit_systray`).
|
||||
- **Android-excluded features**: `tailscale.com/feature/ssh` is `linux && !android` and is
|
||||
imported by `cmd/tailscaled/ssh.go` — fails with "build constraints exclude all Go files".
|
||||
Official hatch: `-tags ts_omit_ssh`.
|
||||
- **Taildrop extension**: `-tags ts_omit_taildrop` exists (condregister `maybe_taildrop.go`)
|
||||
and is also part of the verified daemon build; drop Taildrop if profiles are not needed, or
|
||||
if the daemon SIGSEGVs inside `taildrop.(*Extension).onChangeProfile` on 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_*` / `*_omit`
|
||||
build tags and `go:build` constraints 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-networking` on 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/PORT` and 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'` — note
|
||||
**`ncat` (Go nmap), NOT `nc`**: the classic `nc -X 5 -x host:port` syntax 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 needs
|
||||
`TAILSCALE_SOCKET=<path>` exported before CLI calls (or `--socket <path>` on the CLI), or
|
||||
`tailscale status` says "it doesn't appear to be running".
|
||||
- **`--state` is a FILE, `--statedir` is a DIRECTORY.** Starting the daemon with
|
||||
`--state=<dir>` (a directory) makes the CLI's `up` fail with
|
||||
`500 … state store is unhealthy`. Use `--statedir=<dir>` (it creates `<dir>/tailscaled.state`)
|
||||
or `--state=<absolute-file>`. Verified both ways in-session.
|
||||
- **No `--logdir` flag** in the Android/user tailscaled build — running it with `--logdir=…`
|
||||
hard-exits with `flag 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.
|
||||
Start `tailscaled` via the tool's `background=true` (read its stdout with `process` poll/log), then
|
||||
run `tailscale up` in 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).
|
||||
@@ -0,0 +1,70 @@
|
||||
# Tailscale on Android/Termux — verified recipe (v1.104.2, 2026-10-23)
|
||||
|
||||
## Status legend
|
||||
✅ verified in an actual session | ⚠️ best-effort, not exercised end-to-end
|
||||
|
||||
## Build (all ✅)
|
||||
|
||||
```bash
|
||||
# 1. toolchain (pkg has NO tailscale package — verified "Unable to locate package")
|
||||
pkg install -y golang # Go 1.27.3 -> go1.27.3 android/arm64
|
||||
|
||||
# 2. source (shallow, exact tag from the releases 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
|
||||
cd src/cmd/tailscale
|
||||
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_systray -o ../../ts-out/tailscale .
|
||||
cd ../../cmd/tailscaled
|
||||
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_ssh,ts_omit_taildrop -o ../../../ts-out/tailscaled .
|
||||
```
|
||||
|
||||
Failure → fix table (all hit in-session):
|
||||
| Symptom | Cause | Fix |
|
||||
|---|---|---|
|
||||
| `fyne.io/systray@…/systray.go: undefined: nativeLoop` etc. | desktop systray deps, native files missing on android | `-tags ts_omit_systray` (official: `cli/systray_omit.go` build tag `!linux || ts_omit_systray`) |
|
||||
| `imports tailscale.com/feature/ssh: build constraints exclude all Go files` | `feature/ssh` is `(linux && !android)`, but `cmd/tailscaled/ssh.go` imports it unconditionally (guarded only by `!ts_omit_ssh`) | `-tags ts_omit_ssh` (drops tailnet SSH server — fine for a client that dials out) |
|
||||
| daemon SIGSEGV `[signal SIGSEGV …]` in `tailscale.com/feature/taildrop.(*Extension).onChangeProfile (ext.go:181)` while handling a profile/login change | Taildrop extension hits a nil profile on Android | drop Taildrop from the daemon build: `-tags ts_omit_taildrop` (official condregister tag; condregister/`maybe_taildrop.go`) — verified: daemon rebuilt with it stayed up across login churn |
|
||||
|
||||
Verify: `tailscale version` (prints 1.104.2-dev…), `tailscaled --version` (works — daemon binary runs standalone).
|
||||
Install: `ln -sf <outdir>/tailscale{,d} $PREFIX/bin/`.
|
||||
|
||||
## Run (✅ verified end-to-end: daemon start, browser tap-to-auth against a self-hosted control server `vpn.robbis.space`, node `Running` with `100.64.0.5`, direct peer ping 9 ms; peer discovery: `tailscale status` lists the whole tailnet)
|
||||
|
||||
```bash
|
||||
TS=$HOME/ts-build; mkdir -p $TS/state
|
||||
# --statedir takes a DIRECTORY (creates <dir>/tailscaled.state). Do NOT pass a directory to --state.
|
||||
# There is NO --logdir flag in the Android build; daemon logs go to stdout.
|
||||
$TS/tailscaled --statedir=$TS/state --socket=$TS/tailscaled.sock \
|
||||
--tun=userspace-networking --verbose=1 # + redirect stdout to a log in a raw shell
|
||||
TAILSCALE_SOCKET=$TS/tailscaled.sock $TS/tailscale up --auth-key=tskey-…
|
||||
# or browser: tailscale up --login-server=https://host --hostname=NAME -> prints register/... URL
|
||||
TAILSCALE_SOCKET=$TS/tailscaled.sock $TS/tailscale status
|
||||
```
|
||||
|
||||
Run-stage failure → fix (all hit in-session, 2026-10-23):
|
||||
| Symptom | Cause | Fix |
|
||||
|---|---|---|
|
||||
| `flag provided but not defined: -logdir` (daemon exits, dumps usage) | this Android/user build of tailscaled has no `-logdir` | drop `--logdir`; daemon logs to stdout — capture it where the process runs |
|
||||
| CLI `up` → `500 Internal Server Error: cannot start backend when state store is unhealthy` | daemon started with `--state=<directory>`; `--state` expects a **file**, `--statedir` expects a **directory** | start with `--statedir=<dir>` (creates `<dir>/tailscaled.state`); confirm the `.state` file appears under it |
|
||||
| `tailscale up --socks5-server=… --outbound-http-proxy=…` instantly dumps usage, exit 2 | those are **daemon** flags (tailscaled), not `up` flags | pass them on the tailscaled command line only; `up` accepts `--login-server`, `--hostname`, `--auth-key`, `--socks5-server`?? — no: keep proxy/listen flags on the daemon |
|
||||
| user approves the login URL but node stays `Logged out` | the confirmed URL belongs to a `tailscale up` process that already died (e.g. `unexpected EOF` during WaitLoginURL); auth links are per-process and silently stale | only hand the user a URL for a `up` process that is still running, and re-derive the URL from that process's output right before sharing; if login keeps failing over mobile, switch to `up --auth-key=tskey-…` (single request, no long-lived browser handshake). CONFIRMED WORKING (2026-10-23): with the `up` process alive, a plain tap of the register URL in the user's phone browser completed the join — EOF flapping is normal retry noise, not a login failure |
|
||||
| running `pkill -f tailscaled` from a Hermes terminal call kills the call's own shell (SIGTERM mid-command) | the wrapping shell's command line contains the pattern string, so `pkill -f` self-matches | kill by PID from `pgrep tailscaled`, or `pkill -f '^/.*tailscaled '` — never bare `pkill -f <substring>` inside the very command that manages the daemon |
|
||||
|
||||
- **Run the daemon in its own tmux session** (survives Hermes session/terminal-tool churn,
|
||||
and `pgrep tailscaled || tailscaled …` stays idempotent):
|
||||
```bash
|
||||
pkg install -y tmux
|
||||
tmux new-session -d -s tsd 'tailscaled --tun=userspace-networking \
|
||||
--socket=$PREFIX/var/run/tailscaled.sock --statedir=$HOME/.tailscale \
|
||||
--socks5-server=localhost:1055 --outbound-http-proxy-listen=localhost:1055'
|
||||
```
|
||||
Watch it with `tmux capture-pane -t tsd -p | tail`; kill+restart with
|
||||
`tmux kill-session -t tsd` then re-create.
|
||||
|
||||
- `--tun=userspace-networking`: required on non-root Android; emulates TUN in-process.
|
||||
Expose traffic via local SOCKS5/HTTP proxy / SSH — NOT a system VPN.
|
||||
- `TAILSCALE_SOCKET` env (or `--socket` on the CLI) must match the daemon's `--socket`,
|
||||
or the CLI says "tailscaled … not running".
|
||||
- **From Hermes:** the terminal tool refuses `nohup … &`. Launch the daemon with the tool's
|
||||
`background=true` (logs → `process` poll/log), then `tailscale up` in a separate foreground call.
|
||||
- Helper with the corrected flags baked in: `templates/ts-up.sh`.
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/data/data/com.termux/files/usr/bin/bash
|
||||
# Tailscale start helper for Termux (Android, userspace networking)
|
||||
# Usage:
|
||||
# ./ts-up.sh <authkey> -> start tailscaled + tailscale up with your key
|
||||
# ./ts-up.sh -> if no key, prints the login URL from tailscaled log
|
||||
|
||||
TS=${TS_DIR:-$HOME/ts-build}
|
||||
DAEMON="$TS/tailscaled"
|
||||
LOG="$TS/tailscaled.log"
|
||||
SOCK="$TS/tailscaled.sock"
|
||||
STATE="$TS/state"
|
||||
mkdir -p "$STATE"
|
||||
|
||||
# If authkey was provided via env or arg, use it
|
||||
AUTHKEY="${1:-$TS_AUTHKEY}"
|
||||
|
||||
# Start tailscaled if not already running
|
||||
if ! TAILSCALE_SOCKET="$SOCK" "$TS/tailscale" status >/dev/null 2>&1; then
|
||||
echo "[ts-up] starting tailscaled (userspace)…"
|
||||
# --statedir takes a DIRECTORY (-> <dir>/tailscaled.state); a directory under --state breaks
|
||||
# the CLI with "state store is unhealthy". No --logdir flag exists in the Android build.
|
||||
# (In-Hermes: start this daemon with the terminal tool's background=true instead of nohup.)
|
||||
nohup "$DAEMON" \
|
||||
--statedir="$STATE" \
|
||||
--socket="$SOCK" \
|
||||
--tun=userspace-networking \
|
||||
--verbose=1 \
|
||||
>>"$LOG" 2>&1 &
|
||||
TSPID=$!
|
||||
disown
|
||||
echo "[ts-up] tailscaled pid=$TSPID, log=$LOG"
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
# Point the CLI at our socket
|
||||
export TAILSCALE_SOCKET="$SOCK"
|
||||
|
||||
if [ -n "$AUTHKEY" ]; then
|
||||
echo "[ts-up] running: tailscale up --auth-key=… (masked)"
|
||||
"$TS/tailscale" up --auth-key="$AUTHKEY"
|
||||
else
|
||||
echo "[ts-up] no auth key given; running 'tailscale up' to print login URL"
|
||||
"$TS/tailscale" up
|
||||
fi
|
||||
|
||||
"$TS/tailscale" status
|
||||
Reference in New Issue
Block a user