-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.envrc
81 lines (68 loc) · 2.12 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/env sh
nf () {
nix --extra-experimental-features nix-command --extra-experimental-features flakes "$@"
}
get_repo_basename() {
basename "$(git rev-parse --show-toplevel)"
}
get_profile() {
basename="$(get_repo_basename)"
echo "$HOME/.config/nix/profiles/$basename"
}
cleanup() {
echo "Cleaning Up..."
basename="$(get_repo_basename)"
profile="$(get_profile)"
if [ -z "$basename" ]; then echo "basename is empty"; exit 1; fi
export NIX_PATH="$profile"
export NIX_PROFILE="$profile"
nix-env --profile "$profile" --delete-generations +3
nix-env --profile "$profile" --list-generations
}
if ! which "$0" | grep -q nix; then
print 'Entering Environment...'
basename="$(get_repo_basename)"
profile="$(get_profile)"
export NIX_PROFILE="$profile"
print 'Updating Nix Cache...'
nf flake update
echo 'Installing Nix Profile...'
nf profile install . --profile "$profile"
nf profile list --profile "$profile"
print 'Starting...'
# --impure allows Nix to reuse previously built paths
# --ignore-environment ignores the environment variables and paths to tools not installed by nix
nf develop \
--ignore-environment \
--impure \
--keep HOME \
--keep SSH_AUTH_SOCK \
--keep GITHUB_TOKEN \
--keep AWS_ROLE \
--keep AWS_REGION \
--keep AWS_DEFAULT_REGION \
--keep AWS_ACCESS_KEY_ID \
--keep AWS_SECRET_ACCESS_KEY \
--keep AWS_SESSION_TOKEN \
--keep KUBE_CONFIG_PATH \
--keep TERM \
--keep XDG_DATA_DIRS \
--keep NIX_SSL_CERT_FILE \
--keep NIX_PROFILE \
--profile "$profile" \
--command bash -c "bash --rcfile .envrc"
print 'Exiting Dev Environment...'
cleanup
else
# this is run inside the dev environment so we can make assumptions about what is available
echo 'Setting up dev environment...'
. .functions
. .variables
. .rcs
. .aliases
if [ -z "$SSH_AUTH_SOCK" ]; then eval "$(ssh-agent -s)"; ssh-add; fi
if ! env | grep -q 'AWS'; then
echo 'Unable to find AWS authentication information in the environment, please make sure you authenticate with AWS.'
echo 'Try using the "aws" cli included in the environment.'
fi
fi