Susan Potter
snippets: Created / Updated

Nix in your home directory


  • wget is installed
  • tar is installed


If you really don't want to install Nix under /nix (or you can't) then you can install Nix in your home directory like in the script included in this Gist.

Now whenever you want to run a command under Nix's control, you should prefix with nixrun.

Good luck.

function install_nix() {
  local -r bindir="${HOME}/opt/bin"
  local -r proot_url=""
  local -r nixdir="${HOME}/mnt/nix"
  local -r nixver="1.11.2"
  local -r arch="x86_64"
  local -r os="linux"
  local -r nixbz2_url="${nixver}/nix-${nixver}-${arch}-${os}.tar.bz2"

  mkdir -p "${bindir}"
  wget -O "${bindir}/proot" "${proot_url}"
  chmod u+x "${bindir}/proot"

  mkdir -p "${nixdir}"
  pushd "${nixdir}"
  wget "${nixbz2_url}"
  tar xjf nix-*bz2

  local -r nixbin="$(dirname "$(find "${nixdir}" -name "nix-shell" | head -1)")"
  export PATH="${bindir}:${nixbin}:${PATH}"
    echo "#!/usr/bin/env bash"
    echo "proot -b \"${nixdir}/nix-${nixver}-${arch}-${os}/:/nix\" \$@"
  } > "${bindir}/nixrun"
  chmod u+x "${bindir}/nixrun"

set -eu
set -o pipefail


Update: Thanks to Will Price (@willprice) for pointing out my original link to the proot static binary was broken on Oct 23, 2017:

If you enjoyed this content, please consider sharing this link with a friend, following my GitHub or LinkedIn accounts, or subscribing to my RSS feed.