Files

42 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2020-02-19 14:15:28 +01:00
#!/usr/bin/env bash
# This script makes sure we have Nix tools available
2022-01-05 14:32:02 +01:00
set -e
2020-02-19 14:15:28 +01:00
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
2022-01-05 14:32:02 +01:00
source "${GIT_ROOT}/nix/scripts/lib.sh"
source "${GIT_ROOT}/scripts/colors.sh"
2020-02-19 14:15:28 +01:00
2022-01-05 14:32:02 +01:00
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"
2023-06-19 11:28:03 +02:00
elif [[ "${NIX_INSTALL_TYPE}" == "nixos" ]]; then
2022-01-05 14:32:02 +01:00
echo "Sourcing profile not necessary on NixOS!" >&2
fi
2020-02-19 14:15:28 +01:00
}
2022-01-05 14:32:02 +01:00
main() {
# Just stop if Nix is already available
if [[ -x $(command -v nix) ]]; then
return
fi
# Setup Nix if not available
if [[ ! -d /nix ]]; then
"${GIT_ROOT}/nix/scripts/setup.sh"
2022-01-05 14:32:02 +01:00
fi
# Load Nix profile
source_nix_profile
# Verify Nix is available
if [[ ! -x $(command -v nix) ]]; then
echo -e "${RED}Nix not available, sourcing profile failed!${RST}" >&2
exit 1
fi
}
main