name: nix-shell-direnv description: Detect and use Nix shell environments via direnv when running commands. Use BEFORE running any shell command -- the skill checks for Nix indicators and adjusts execution accordingly, so it is safe to run even in projects without Nix. disable-model-invocation: true
Nix Shell / direnv Awareness
When running shell commands in a project, check for a Nix shell environment first.
Detection
Before executing commands, look for these indicators:
.envrccontaininguse nix,use flake, ornix-shellshell.nixordefault.nixin the project rootflake.nixwith adevShellsoutput
Behavior
If a Nix shell environment is detected:
- Prefix commands with
direnv exec .to ensure the environment is loaded - If
direnvis unavailable, fall back tonix-shell --run "<command>"ornix develop -c <command> - Do not install packages globally via
npm install -g,pip install, etc. -- the Nix shell provides them
Examples
# BAD -- runs outside the Nix environment
npm test
# GOOD -- uses direnv to load the Nix shell
direnv exec . npm test
# GOOD -- fallback without direnv
nix-shell --run "npm test"
nix develop -c npm test
Exceptions
Skip the prefix when the command is purely git, file I/O, or unrelated to the project's toolchain (e.g., git status, ls, mkdir).