55 lines
1.6 KiB
Bash
Executable File
55 lines
1.6 KiB
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/store ]; then
|
|
exit 0
|
|
elif [ -d /nix ] && ! [ -O /nix ]; then
|
|
# If we don't own /nix use sudo to chown it.
|
|
# If we can't sudo then nothing we do here will work so we just let this fail
|
|
sudo chown $UID /nix
|
|
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.24.12/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
|
|
elif [ -r "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh" ]; then
|
|
. "${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/etc/profile.d/nix.sh"
|
|
fi
|
|
EOF
|
|
|
|
# Remove the installer and signature
|
|
rm -f ./install-nix
|
|
|
|
# Enable flakes and the nix command
|
|
NIX_CONF_DIR=~/.config/nix
|
|
NIX_CONF_FILE=${NIX_CONF_DIR}/nix.conf
|
|
mkdir -p ${NIX_CONF_DIR}
|
|
cat <<EOF > ${NIX_CONF_FILE}
|
|
experimental-features = flakes nix-command
|
|
use-xdg-base-directories = true
|
|
EOF
|
|
# Conditionally add a link to system certificates for nix
|
|
if [ -f /etc/ssl/certs/ca-certificates.crt ]; then
|
|
echo 'ssl-cert-file = /etc/ssl/certs/ca-certificates.crt' >> ${NIX_CONF_FILE}
|
|
fi
|