Direnv: Difference between revisions

Moved from the nix-shell article. (with significant improvements)
 
Pigs (talk | contribs)
m move nixos content under nixos section
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
'''[https://direnv.net Direnv]''' is an automatic environment setup utility, loading the specified project environment automatically when you enter your project directory, and reporting the loaded variables to you.
'''[https://direnv.net Direnv]''' is an automatic environment setup utility, loading the specified project environment automatically when you enter your project directory, and reporting the loaded variables to you.


After installing {{nixos:package|direnv}} from Nixpkgs using your preferred method of installation, you can set up the <code>.envrc</code> file at the root of your directory. Refer to the [https://github.com/direnv/direnv/wiki Direnv Wiki] for some examples.  
After installing {{nixos:package|direnv}} from Nixpkgs using your preferred method of installation, you can set up the <code>.envrc</code> file at the root of your directory. Refer to the [https://github.com/direnv/direnv/wiki Direnv Wiki] for some examples. For Nix projects, you will probably want to use the special <code>use_nix</code> keyword, that automatically loads the <code>shell.nix</code> file for your repository.


At the root of your repository, Direnv can start by allowing the recently-created <code>.envrc</code> file to execute:
At the root of your repository, Direnv can start by allowing the recently-created <code>.envrc</code> file to execute:
Line 24: Line 24:


Keeping that directory means that an <code>.envrc</code> file only needs to be allowed once in order to run automatically.
Keeping that directory means that an <code>.envrc</code> file only needs to be allowed once in order to run automatically.
== <code>nix-direnv</code> & <code>lorri</code> ==
While Direnv has [https://github.com/direnv/direnv/wiki/Nix full support for Nix] development environments, third-party developers have improved upon Direnv's default implementation of the special <code>use_nix</code> keyword, resulting in the development of [https://github.com/nix-community/nix-direnv <code>nix-direnv</code>] and [https://github.com/nix-community/lorri <code>lorri</code>].


== Configuring on NixOS ==
== Configuring on NixOS ==


There is a [[Overview_of_the_NixOS_Linux_distribution|NixOS]] Module for Direnv (and <code>nix-direnv</code>) which automatically sets everything up in a given NixOS machine. The following line of code is everything that's necessary for NixOS to automatically install and hook Direnv to the available shells in the system:
There is a [[Overview_of_the_NixOS_Linux_distribution|NixOS]] Module for Direnv (and <code>nix-direnv</code>) which automatically sets everything up in a given NixOS machine. The following line of code is everything that's necessary for NixOS to automatically install and hook Direnv to the available [[Command Shell|shells]] in the system:


{{file|configuration.nix|nix|<nowiki>
{{file|configuration.nix|nix|<nowiki>
Line 34: Line 38:
}
}
</nowiki>}}
</nowiki>}}
{{Evaluate}}
{{Evaluate}}
For a full list of Direnv module options, see {{nixos:option|programs.direnv}}.
The NixOS module uses <code>nix-direnv</code> by default when Direnv is enabled. This behavior can be overridden by setting the {{nixos:option|programs.direnv.nix-direnv.enable}} option.


== Troubleshooting ==
== Troubleshooting ==
Line 48: Line 57:
* [https://direnv.net/ direnv.net].
* [https://direnv.net/ direnv.net].
* The [https://github.com/direnv/direnv/wiki/Nix Direnv Wiki].
* The [https://github.com/direnv/direnv/wiki/Nix Direnv Wiki].
[[Category:Development]]
[[Category:Applications]]