Notes on how to install and use Nix as a reproducible build/pkg manager without needing any special privileges on a Linux-like system. The nix store can be on any location writeable by the user and the cached derivations can still be used.

This post is inspired by with some additions/updates:

  1. The store location can be specified to any directory
  2. Use configuration file to avoid having to spell out the store location
  3. How to use nix profiles

Get a static version of nix

You can get the list of current versions form Hydra and download manually if desired. As an example to get the latest 2.18 version use following:

curl -L > nixstatic


Configure in ~/.config/nix/nix.conf:

store = ~/mynixroot
extra-experimental-features = flakes nix-command                                                                                                                                  
ssl-cert-file = /etc/pki/tls/cert.pem                                                                                                                                             

As can be seen the nix root will be in ~/mynixroot

The ssl cert file may need to be specified. To find the right one your system can for example strace and wget invocation.

Build and run

This is sufficient to build and run programs, e.g.:

~/nixstatic run nixpkgs#hello

Enter Nix environment

In order to easily use nix-installed programs can enter a shell like:

~/nixstatic shell nixpkgs#nix nixpkgs#bashInteractive --command bash

The can do commands like nix profile install etc. Note however that can not recursively enter another nix shell!