-
Notifications
You must be signed in to change notification settings - Fork 991
/
Copy pathsource.sh
executable file
·41 lines (34 loc) · 1.09 KB
/
source.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
# This script makes sure we have Nix tools available
set -e
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
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"
elif [[ "${NIX_INSTALL_TYPE}" == "nixos" ]]; then
echo "Sourcing profile not necessary on NixOS!" >&2
fi
}
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"
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