Skip to content

Instantly share code, notes, and snippets.

@Amar1729
Forked from mbbx6spp/README.md
Created October 30, 2018 17:09
Show Gist options
  • Save Amar1729/d4227bc01a378428663640fcdaf84e7a to your computer and use it in GitHub Desktop.
Save Amar1729/d4227bc01a378428663640fcdaf84e7a to your computer and use it in GitHub Desktop.
How to install Nix in your home directory

Nix

Prerequisites

  • wget is installed
  • tar is installed

Purpose

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 homedir_install.sh 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="http://static.proot.me/proot-x86_64"
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="http://nixos.org/releases/nix/nix-${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
echo "proot -b \"${nixdir}/nix-${nixver}-${arch}-${os}/:/nix\" \$@"
} > "${bindir}/nixrun"
chmod u+x "${bindir}/nixrun"
}
set -eu
set -o pipefail
install_nix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment