Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Last active September 17, 2023 10:28
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mbbx6spp/4f467adb4e0133063fd87e264c6b9f78 to your computer and use it in GitHub Desktop.
Save mbbx6spp/4f467adb4e0133063fd87e264c6b9f78 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
@Amar1729
Copy link

Link to proot is outdated:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment