# Claudette devshell activation via nix-direnv.
#
# Why nix-direnv:
#   • `use flake` (vanilla direnv) re-evaluates the flake on every shell
#     entry and rebuilds the env. nix-direnv caches the rendered
#     environment to `.direnv/` and only re-evaluates when one of the
#     watched files actually changes — entry time drops from multi-
#     second (cold `nix print-dev-env`) to sub-second on warm cache
#     hits.
#   • Cache invalidation is keyed on flake.nix + flake.lock by default —
#     touching scripts in `scripts/` or anything else outside the flake
#     does not force a reload, which is what makes the steady-state
#     loop fast.
#
# If nix-direnv is installed system-wide (e.g. via home-manager /
# nix-darwin), this `source_url` line is a no-op fast path — the
# installed copy wins because direnv resolves `nix_direnv_version`
# before running the bootstrap. Otherwise the bootstrap downloads a
# pinned `direnvrc` once, stores it under `~/.cache/direnv/` for
# subsequent reuse, and we get cached activation everywhere — including
# teammate machines that don't run a Nix-managed home.
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
  source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi

# Speed knobs:
#   `nix_direnv_manual_reload` is a shell variable read by nix-direnv
#   when this `.envrc` is evaluated — direnv's `direnv.toml` does not
#   propagate arbitrary variables into the evaluated env. If you want
#   to opt out of auto-reload on flake.nix/.lock changes, export it
#   here before `use flake` (or set it in your user-wide
#   `~/.config/direnv/direnvrc`):
#     # nix_direnv_manual_reload=1

# `use flake` (intercepted by nix-direnv) builds the devShell with
# `nix print-dev-env`, caches the result, and exports the env on
# subsequent entries without re-running Nix. The cache is invalidated
# only when flake.nix or flake.lock change — script bodies referenced
# by devshell `commands` entries (e.g. scripts/dev.sh) are exec'd at
# runtime and do NOT affect the env, so they intentionally aren't
# watched.
use flake
