Use ambient Nix when available, with a two stage fallback

First, we try to use the ambient Nix version.
Then, we try to use $NIX_DIRENV_FALLBACK_NIX, which is set by default,
but can also be overridden by the user.
Only then, if neither is available, we fail.

Fixes #451.
This commit is contained in:
K900 2024-08-21 16:50:26 +03:00
parent cff4f3cb0f
commit 94def84445
3 changed files with 62 additions and 17 deletions

View file

@ -311,6 +311,14 @@ invocation or are purely incidental and should not be relied upon.
flake's devShell are invalid and nix-direnv has loaded the last known working
shell.
nix-direnv also respects the following environment variables for configuration.
- `NIX_DIRENV_FALLBACK_NIX`: Can be set to a fallback Nix binary location, to be
used when a compatible one isn't available in `PATH`. Defaults to
`config.nix.package` if installed via the NixOS module, otherwise needs to be
set manually. Leave unset or empty to fail immediately when a Nix
implementation can't be found on `PATH`.
## General direnv tips
- [Changing where direnv stores its cache][cache_location]