Direnv: Difference between revisions

Pigs (talk | contribs)
m move nixos content under nixos section
Ghb (talk | contribs)
m I documented how to determine whether a configuration file is managed or not, as it may be a cause of an unhooked direnv.
 
(One intermediate revision by one other user not shown)
Line 44: Line 44:


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.
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 51: Line 62:
Depending on the shell you are using, you need to add a line in your shell configuration file. See the [https://direnv.net/docs/hook.html ''Hook'' section of the Direnv Documentation] for more information.
Depending on the shell you are using, you need to add a line in your shell configuration file. See the [https://direnv.net/docs/hook.html ''Hook'' section of the Direnv Documentation] for more information.


Setting Direnv up using the NixOS module should do this by default.
Setting Direnv up using the NixOS module should do this by default. If direnv is not hooked, after having setup the NixOS module as described above please ensure, that you have no unmanaged shell configuration files, e.g. <code>.bashrc</code>, <code>.zshrc</code>, <code>.profile</code>, etc.. To determine whether a configuration file is unmanged, use the ''list directory contents'' command with the ''long listing format'' flag as shown below; if the file points to the nix store, it is managed, otherwise, it is unmanaged. If the appropriate configuration files are managed, and direnv is still not hooked, please ensure that your shell session has been reloaded after your latest rebuild.<syntaxhighlight lang="shell-session">
# Supposing managed .bashrc
$ ls -l ~/.bashrc
lrwxrwxrwx 1 ghb users 70 sep  1 11:41 /home/user/.bashrc -> /nix/store/wfzbf11b0mff8d1isp3lx5pr4ainbc7p-home-manager-files/.bashrc
 
</syntaxhighlight>


== See Also ==
== See Also ==