Created
March 3, 2022 22:14
-
-
Save jfroche/614cc07943e3337ad73a3504827177e7 to your computer and use it in GitHub Desktop.
Nix install without root access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function install_nix() { | |
set -x | |
local -r bindir="${HOME}/bin" | |
local -r proot_url="https://github.com/proot-me/proot/releases/download/v5.3.0/proot-v5.3.0-x86_64-static" | |
local -r nixdir="${HOME}/mnt/nix" | |
local -r nixver="2.5.1" | |
local -r arch="x86_64" | |
local -r os="linux" | |
local -r nix_url="https://releases.nixos.org/nix/nix-${nixver}/nix-${nixver}-${arch}-${os}.tar.xz" | |
local -r nix_cli_dir=nix-${nixver}-${arch}-${os} | |
mkdir -p "${bindir}" | |
test \! -f "${bindir}/proot" && curl -L "${proot_url}" > "${bindir}/proot" | |
chmod u+x "${bindir}/proot" | |
mkdir -p "${nixdir}" | |
pushd "${nixdir}" | |
test \! -f nix.tar.xz && curl -L "${nix_url}" > nix.tar.xz | |
test \! -d $nix_cli_dir && tar -xJf "nix.tar.xz" | |
local -r nixbin="$(dirname "$(find "${nixdir}/${nix_cli_dir}" -name "nix-shell" | head -1)")" | |
local -r nix_profile="$(dirname $nixbin)/etc/profile.d/nix.sh" | |
{ | |
echo "#!/usr/bin/env bash" | |
echo | |
echo export PATH="${bindir}:${nixbin}:${PATH}" | |
echo source "${nix_profile}" | |
echo export PROOT_NO_SECCOMP=1 | |
echo export NIX_PATH=\${NIX_PATH:+\$NIX_PATH:}\$HOME/.nix-defexpr/channels | |
echo | |
echo "${bindir}/proot -b \"${nixdir}/nix-${nixver}-${arch}-${os}/:/nix\" \$@" | |
} > "${bindir}/nixrun" | |
chmod u+x "${bindir}/nixrun" | |
} | |
set -eu | |
set -o pipefail | |
install_nix | |
mkdir -p ${HOME}/.config/nix | |
echo "sandbox = false" > ${HOME}/.config/nix/nix.conf | |
nixrun /nix/install --no-daemon --no-channel-add | |
grep -qF 'nixrun' ~/.bashrc || echo 'test \! -e $HOME/.nix-profile && nixrun bash -l' >> ${HOME}/.bashrc | |
cat >> $HOME/.nix-channels << EOF | |
https://github.com/rycee/home-manager/archive/release-21.11.tar.gz home-manager | |
https://github.com/NixOS/nixpkgs/archive/release-21.11.tar.gz nixpkgs | |
EOF | |
nixrun nix-channel --update | |
nixrun nix-shell '<home-manager>' -A install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment