-
Notifications
You must be signed in to change notification settings - Fork 5
/
.envrc
56 lines (48 loc) · 1.69 KB
/
.envrc
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Function to compare Nix versions
nix_version_ge() {
# Compare two version numbers
[ "$1" = "$2" ] && return 0
local IFS=.
local i ver1=($1) ver2=($2)
# Fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# Fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
return 0
fi
if ((10#${ver1[i]} < 10#${ver2[i]})); then
return 1
fi
done
return 0
}
# Get the current version of nix
current_nix_version=$(nix --version | awk '{print $3}')
# Required version of nix
required_nix_version="2.23"
# Check if the current version is greater than or equal to the required version
if ! nix_version_ge "$current_nix_version" "$required_nix_version"; then
echo "Installed Nix version $current_nix_version is < $required_nix_version. Please upgrade: https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#upgrading-nix." >&2
exit 1
fi
# Check to ensure an up-to-date version of direnv is installed
if ! direnv_version 2.32.0; then
exit 1
fi
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
fi
watch_file flake.nix
watch_file flake.lock
watch_file devenv.nix
if ! use flake . --impure
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
dotenv_if_exists .env