Note: this project is generated by LLM Claude
Run the Nix package manager on Android through Termux without root access. Uses a custom prefix at /data/data/com.termux/files/nix instead of /nix.
aarch64 (ARM64) devices only.
curl -fsSL https://raw.githubusercontent.com/mio-19/nix-termux/main/install-nix-termux.sh | bashRequirements: aarch64 Android device, Termux installed, 2-3 GB free space.
After installation: source ~/.bashrc (or restart Termux)
- Custom Store Prefix: Uses
/data/data/com.termux/files/nixinstead of/nix(no root required) - Native aarch64 Build: Built natively on ARM64 to ensure correct paths
- Patchelf: ELF interpreter paths are rewritten at build time to point to the custom prefix
- Complete Bootstrap: Includes Nix 2.31.2, GCC toolchain, and essential utilities
- Android device with aarch64 (ARM64) architecture
- Termux app installed
- At least 2-3 GB free storage
- Internet connection (for future package builds)
Note: Requires an aarch64-linux system (ARM64 Linux or NixOS).
# Clone this repository
git clone https://github.com/mio-19/nix-termux.git
cd nix-termux
# Build (takes several hours)
./build.shThe output will be: result/nix-termux-aarch64.tar.gz
Pre-built releases are available on the releases page.
The easiest way to install is using the automated installer script:
curl -fsSL https://raw.githubusercontent.com/mio-19/nix-termux/main/install-nix-termux.sh | bashOr with wget:
wget -qO- https://raw.githubusercontent.com/mio-19/nix-termux/main/install-nix-termux.sh | bashThe script will handle everything automatically, including downloading the latest release, verifying your system, and configuring your environment.
Download from releases page:
# Download and extract
curl -LO <release-url>
tar -xzf nix-termux-aarch64-*.tar.gz
cd tarball
# Run installer
./install.sh
# Reload shell
source ~/.bashrcSince we're using a custom store path, the official binary cache won't work. All packages must be built from source:
# Install a package (will build from source)
nix-env -iA nixpkgs.hello
# Search for packages
nix-env -qaP | grep python
# Update all packages
nix-env -u '*'Clone nixpkgs for local package builds:
cd ~
git clone https://github.com/NixOS/nixpkgs.git --depth 1
cd nixpkgs
# Install from local nixpkgs
nix-env -f . -iA helloFree up space by removing unused packages:
# List old generations
nix-env --list-generations
# Delete old generations
nix-env --delete-generations old
# Run garbage collector
nix-collect-garbage
# Aggressive cleanup (remove everything not currently in use)
nix-collect-garbage -dEdit /data/data/com.termux/files/nix/etc/nix/nix.conf to customize:
- Build settings (max-jobs, cores)
- Storage optimizations
- Custom binary caches (if you set up your own)
- Custom Prefix: Termux cannot access
/nix/storewithout root, so we use/data/data/com.termux/files/nix - ELF Patching: Interpreter paths are rewritten using
patchelfto point to the custom store - Native Build: Built on aarch64-linux to ensure all paths are correct
- No Binary Cache: Must build packages from source due to custom paths
- No Binary Cache: Must build all packages from source
- Slow Builds: Compiling on mobile hardware takes time
- Architecture: Only aarch64-linux supported
- Android Environment: Some packages may not work due to Android's unique environment
Ensure you've sourced the environment setup:
source ~/termux-nix-env.shRe-initialize the database:
nix-store --init
nix-store --load-db < /data/data/com.termux/files/nix/var/nix/db/db.sqliteCheck logs:
# View build logs
nix-store --read-log /nix/store/...-package-nameRun garbage collection:
nix-collect-garbage -dMIT License. Nix itself is licensed under LGPL 2.1.
- Nix-on-Droid: More integrated NixOS-like environment
- Termux packages: Native Termux package manager
Based on dramforever's bootstrap approach. Built with Nix.