Direnv: Difference between revisions

Nix support stuff
Toastal (talk | contribs)
Add note on Direnv being a personalized file to encourage projects to stop committing files that mess with contributor workflows.
 
(2 intermediate revisions by 2 users not shown)
Line 28: Line 28:


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>].
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>].
The NixOS module uses <code>nix-direnv</code> by default when Direnv is enabled, but this can be overriden with the {{nixos:option|programs.direnv.nix-direnv.package}} option.


== 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 40: 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.
== User Customization & Repositories ==
Direnv is meant to be used as a personalized environment file so each user can set any necessary environment variables and/or run some setup scripts. As every user can have different environment needs (such as changing ports, location of <code>$TMPDIR</code>, project-specific VCS/PGP/SSH credentials) it’s recommended <strong>not</strong> to track or commit the <code>.envrc</code> so users may make adjustments for themselves. In fact, it’s best to add both to your ignorefile
<syntaxHighlight>
.direnv
.envrc
</syntaxHighlight>
to avoid accidentally checking in your personal setup (as seen in Nixpkgs’s repository). If you have a complex <code>.envrc</code> you wish to share, create a <code>.envrc.example</code> file that users can copy, symlink, or source depending on what works for them.


== Troubleshooting ==
== Troubleshooting ==
Line 54: Line 68:
* [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]]