A nix not requiring root, proot, user namespace. Just like conda.
README.md

A house with the Nix snowflake inside

nix-rootless

Nix without root, user namespaces, or proot.
Install Nix in your home directory and use packages from the official binary cache.

English · 简体中文

Install and use #

  1. Download the latest installer for your operating system and CPU architecture from the releases page, save it as nix-rootless-install.sh.

  2. Run:

sh nix-rootless-install.sh
. ~/.nix-rootless/activate
  1. Add . ~/.nix-rootless/activate to your shell profile.

Upgrading to new version #

Download the new installer and run:

sh nix-rootless-install.sh --upgrade
. ~/.nix-rootless/activate

Comparing with other solutions #

Feature nix-portable nix-user-chroot Nix built-in chroot store Changing Nix store path nix-rootless
Reuse Nix binary cache ✅ ✅ ✅ 🚫 ✅
No user namespace required ✅ 🚫 🚫 ✅ ✅
High performance without user namespaces 🚫 Uses proot 🚫 Cannot run 🚫 ✅ ✅
Run downloaded binaries directly from the host shell 🚫 Requires namespace or proot environment 🚫 Requires namespace environment 🚫 Requires namespace environment ✅ ✅

How it works #

The idea is similar to conda: download prebuilt packages, then patch their paths.

Conda builds its packages with a very long (255 character) installation prefix, e.g. /conda-prefix-xxxxxxx/lib/libfoo.so. When you run conda install, it downloads those binaries and replaces recorded occurrences of the prefix with something like /home/username/.conda/envs/myenv. The conda prefix is long enough to contain almost any user name. It then adds a \0 at the end of the short path, so that programs don't read beyond that.

The problem with nix is that the default prefix /nix/store is not long enough. /home/user/.nix-rootless is probably longer than that. However, there's actually plenty of space for us to use at the hash part: it's 32 characters. Can we somehow make use of that?

Turns out you can. Just replace the long hash with a short number, then point it to the real thing. For example, we patch fish like this:

ldd $(which fish)
  linux-vdso.so.1 (0x00007ffe52316000)
  libpcre2-8.so.0 => /home/username/.nix-rootless/s///////////98-pcre2-10.49/lib/libpcre2-8.so.0 (0x000070472f17a000)
  libpcre2-32.so.0 => /home/username/.nix-rootless/s///////////98-pcre2-10.49/lib/libpcre2-32.so.0 (0x000070472e563000)

Note the absense of hash. Here, the ////s are paddings to make new path as long as the original one.

Then we create symlinks like this:

0-aws-c-common-0.12.4 -> /home/username/.nix-rootless/long_store/0a0y1r2nhq7gxg00s9hm6h9ncv8qb38f-aws-c-common-0.12.4
1-gcc-14.3.0-lib     -> /home/username/.nix-rootless/long_store/0p8b2lqk47fvxm9hc6c8mnln5l8x51q1-gcc-14.3.0-lib
2-attr-2.5.2         -> /home/username/.nix-rootless/long_store/0y221n4x5cwrig34sq4i40n3lls0m2ac-attr-2.5.2
98-pcre2-10.49 -> /home/username/.nix-rootless/long_store/m9y00qgmfbzvlffgbx0hi5hc38dps46q-pcre2-10.49

And it works.

Support #

Supports Linux and macOS; see the releases page for available installers. This is still experimental: some packages with hardcoded paths or privilege requirements may not work. Do not move the installation directory after installing. Build sandboxing is outside the scope of this project.

Based on Nix 2.34.7. See COPYING for the license.