dotfiles/installers/install-nix.sh
Andrew R. M 85cee95c2e Make a root single user nix install possible
Taken from this issue https://github.com/NixOS/nix/issues/1559

This is only so that the script will succeed when running in docker
containers without systemd (can't use multi-user) and that have root as
the default user, a shockingly common practice
2024-05-22 14:25:21 +00:00

42 lines
992 B
Bash
Executable File

#!/usr/bin/env bash
# Install the Nix package manager as a secondary package manager.
# This can sometimes be useful for getting more recent packages.
set -e
set -x
# Abort installation if Nix is already installed
if [ -d /nix ]; then
exit 0
fi
# Workaround to make a single user install work as root
if [ "${USER:-}" == "root" ] || [ "${UID:-}" == "0" ]; then
mkdir -p /etc/nix
echo "build-users-group =" > /etc/nix/nix.conf
fi
# Download the Nix installer and it's signature from NixOS.org
curl -so install-nix https://releases.nixos.org/nix/nix-2.18.1/install
# Run the installer
sh ./install-nix
# Source the nix profile
cat << EOF > ~/.bashrc
# Source nix if it's installed
if [ -r ~/.nix-profile/etc/profile.d/nix.sh ]; then
. ~/.nix-profile/etc/profile.d/nix.sh
fi
EOF
# Remove the installer and signature
rm -f ./install-nix
# Enable flakes and the nix command
mkdir -p ~/.config/nix
cat <<EOF > ~/.config/nix/nix.conf
experimental-features = flakes nix-command
EOF