Auto Activation
New in version 2.1
devenv includes a built in shell hook that automatically activates your developer environment when you cd into a project directory. No external tools required.
Setup
Add one line to your shell configuration file:
Setup via the NixOS, nix-darwin, or home-manager module
New in version 2.2
NixOS, nix-darwin, and home-manager users can import the flake modules that devenv ships, which install the package and source the shell hook for every shell you have enabled — no rc-file edits required.
Add devenv as a flake input:
By default, every supported shell that you have enabled also gets the hook sourced. Disable an individual integration with:
programs.devenv.enableBashIntegration = false;
programs.devenv.enableZshIntegration = false;
programs.devenv.enableFishIntegration = false;
programs.devenv.enableNushellIntegration = false; # home-manager only
The exported hook scripts are also available directly under ${pkgs.devenv}/share/devenv/shell-integration/<shell>/hook.<ext> if you want to wire them up by hand.
Trusting a project
Before a project can auto activate, you need to explicitly trust it. This is a security measure that prevents untrusted projects from modifying your shell.
Navigate to the project directory and run:
When you cd into the directory next time, devenv will automatically start a shell:
Revoking trust
To stop a project from auto activating:
How it works
The hook runs on every directory change and:
- Walks up from the current directory looking for a
devenv.yamlfile. - Checks the trust database to verify the project was allowed.
- If trusted, runs
devenv shellin a subshell for that project.
If a project has not been trusted yet, you will see a message asking you to run devenv allow:
Note
The hook only detects projects that have a devenv.yaml file. Projects with only devenv.nix (without devenv.yaml) are not detected.
Automatic deactivation
When you cd out of the project directory (or any of its subdirectories), the devenv shell exits automatically and you return to your normal shell:
Re-entry protection
The hook will not nest environments. While inside a devenv shell, navigating into a subdirectory of the same project keeps the current shell. Only navigating outside the project triggers deactivation.
Comparison with direnv
| Feature | devenv hook |
direnv |
|---|---|---|
| External dependencies | None | Requires direnv |
| Setup | One line in shell config | direnv install + .envrc per project |
| Trust granularity | Per project directory | Per .envrc file |
| Environment application | Spawns a subshell | Modifies current shell in place |
| Unloading on exit | Subshell exits automatically | direnv unloads variables |
Use devenv hook for a simple, dependency free setup. Use direnv if you prefer in place environment modification without a subshell.