2020-02-19 13:15:28 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# This script makes sure we have Nix tools available
|
2022-01-05 13:32:02 +00:00
|
|
|
set -e
|
2020-02-19 13:15:28 +00:00
|
|
|
|
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
2022-01-05 13:32:02 +00:00
|
|
|
source "${GIT_ROOT}/nix/scripts/lib.sh"
|
|
|
|
source "${GIT_ROOT}/scripts/colors.sh"
|
|
|
|
|
|
|
|
source_nix_profile() {
|
|
|
|
NIX_INSTALL_TYPE=$(nix_install_type)
|
|
|
|
if [[ "${NIX_INSTALL_TYPE}" == "multi" ]]; then
|
|
|
|
source "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
|
|
|
|
elif [[ "${NIX_INSTALL_TYPE}" == "single" ]]; then
|
|
|
|
source "${HOME}/.nix-profile/etc/profile.d/nix.sh"
|
2024-04-25 14:57:48 +00:00
|
|
|
elif [[ "${NIX_INSTALL_TYPE}" == "nixos" ]]; then
|
2022-01-05 13:32:02 +00:00
|
|
|
echo "Sourcing profile not necessary on NixOS!" >&2
|
|
|
|
fi
|
|
|
|
}
|
2020-02-19 13:15:28 +00:00
|
|
|
|
2022-01-05 13:32:02 +00:00
|
|
|
main() {
|
|
|
|
# Just stop if Nix is already available
|
|
|
|
if [[ -x $(command -v nix) ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2020-05-04 16:32:47 +00:00
|
|
|
|
2020-02-19 13:15:28 +00:00
|
|
|
# Setup Nix if not available
|
2022-01-05 13:32:02 +00:00
|
|
|
if [[ ! -d /nix ]]; then
|
2022-07-25 20:38:41 +00:00
|
|
|
"${GIT_ROOT}/nix/scripts/setup.sh"
|
2022-01-05 13:32:02 +00:00
|
|
|
fi
|
2020-02-19 13:15:28 +00:00
|
|
|
|
2022-01-05 13:32:02 +00:00
|
|
|
# Load Nix profile
|
|
|
|
source_nix_profile
|
2020-05-04 16:32:47 +00:00
|
|
|
|
2022-01-05 13:32:02 +00:00
|
|
|
# Verify Nix is available
|
|
|
|
if [[ ! -x $(command -v nix) ]]; then
|
|
|
|
echo -e "${RED}Nix not available, sourcing profile failed!${RST}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-19 13:15:28 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 13:32:02 +00:00
|
|
|
main
|