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.
Supports multiple architectures: aarch64 (ARM64), armv7l (ARM 32-bit), x86_64 (Intel/AMD 64-bit), i686 (Intel/AMD 32-bit)
curl -fsSL https://raw.githubusercontent.com/mio-19/nix-termux/main/install-nix-termux.sh | bashRequirements: Android device with 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) - Multi-architecture Support: Pre-built packages for aarch64, armv7l, x86_64, and i686
- 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 Termux installed
- At least 2-3 GB free storage
- Internet connection (for future package builds)
- Supported architecture: aarch64, armv7l, x86_64, or i686
Note: Requires a Linux system with Nix installed.
# Clone this repository
git clone https://github.com/mio-19/nix-termux.git
cd nix-termux
# Build for specific architecture (takes several hours)
./build.sh -a aarch64
# Build for all architectures
./build.sh -A
# See all options
./build.sh --helpThe output will be in: result/nix-termux-<arch>.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 automatically detect your architecture and download the appropriate package.
Download from releases page for your architecture:
# Download and extract (example for aarch64)
curl -LO https://github.com/mio-19/nix-termux/releases/latest/download/nix-termux-aarch64-*.tar.gz
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 - Cross Compilation: Built using Nix's cross-compilation support for all architectures
- 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 Support: Limited to architectures supported by Termux
- 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.