65 lines
1.6 KiB
Bash
65 lines
1.6 KiB
Bash
#!/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 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
|
|
fi
|