[ -e ".devenv" ] || rm -rf .devenv
[ -L ".devenv" ] || (mkdir -p "$HOME/.cache/devenv$PWD"  && ln -s "$HOME/.cache/devenv$PWD" .devenv)

if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
  source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

watch_file flake.nix
watch_file flake.lock

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