-
-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/direnv: init #192667
nixos/direnv: init #192667
Conversation
This allows setting DIRENV_CONFIG to (nix-profile)/share/direnv and have it find the nix-direnv script, while also allowing other direnv integrations to coexist. Old path kept for backwards compat.
nix-direnv is surprisingly annoying to configure correctly, due to it needing both system-wide adjustments (`nix.conf` changes), but also user-wide adjustments (telling direnv to load nix-direnv using ~/.config/direnv/direnvrc). This module puts an end to that, allowing a direnv + nix-direnv installation with just programs.direnv.enable = true;
@@ -26,6 +26,9 @@ stdenv.mkDerivation rec { | |||
installPhase = '' | |||
runHook preInstall | |||
install -m500 -D direnvrc $out/share/nix-direnv/direnvrc | |||
|
|||
# Allows NixOS to set DIRENV_CONFIG to /run/current-system/sw/share/direnv and have direnv load this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, the module will also have to handle user settings since DIRENV_CONFIG is also used to locate the direnv.toml
.
Alternatively, it could make sense to change direnv so it also loads all the libraries in
share/direnv/lib/*.sh
, following the XDG spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that, given that direnv already reads ${XDG_CONFIG_HOME:-$HOME/.config}/direnv/lib/*.sh
it makes perfect sense for it to read the equivalent system directory, does it not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think so too, I quote the XDG Base Directory Specification:
$XDG_CONFIG_DIRS
defines the preference-ordered set of base directories to search for configuration files in addition to the$XDG_CONFIG_HOME
base directory. The directories in$XDG_CONFIG_DIRS
should be seperated with a colon ':'.If
$XDG_CONFIG_DIRS
is either not set or empty, a value equal to /etc/xdg should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a direnv PR for this: direnv/direnv#990
This generally looks okay. I will say though that I'm not completely sure I see the need to introduce this. All of this to say that the system changes are good but not wholly necessary to eek out use from nix-direnv. |
"/share/direnv" | ||
]; | ||
|
||
environment.sessionVariables.DIRENV_CONFIG = "/run/current-system/sw/share/direnv"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned: This disallows user customization entirely, I think.
Either we need a change to direnv to address this or we need a change here to give us the ability for the user to specify additional contents.
@@ -26,6 +26,9 @@ stdenv.mkDerivation rec { | |||
installPhase = '' | |||
runHook preInstall | |||
install -m500 -D direnvrc $out/share/nix-direnv/direnvrc | |||
|
|||
# Allows NixOS to set DIRENV_CONFIG to /run/current-system/sw/share/direnv and have direnv load this | |||
install -m500 -D direnvrc $out/share/direnv/lib/nix-direnv.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this not be a symlink?
Sounds like this will be addressed by #192667 (comment)
I had a bit of trouble understanding your concern, but I believe you're trying to say that the Here's some arguments for why I think such a module is useful:
|
This is exactly it. There are already about 5 ways to install nix-direnv. |
No this PR doesn't add another, it will allow you to replace the existing instructions for NixOS with much simpler ones, namely {
programs.direnv.enable = true;
} |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-37/22409/1 |
Can we get a release notes entry please, so we nudge people to use this instead of the clumsy things they configured before. |
I will have to describe the old behavior and the new behavior until acceptance of the new version is high enough. Likely well beyond the 22.11 release, as old installs may not be updated immediately. Do know that I have said I support this change once appropriate changes are made to direnv as to allow the user to provide augmentations to the direnv stdlib. I am holding off approval until direnv/direnv#990 is approved, merged, released and updated in nixpkgs. |
@bbenne10 Awesome that sounds great. You can also just keep everything as-is for now, the old way of installing it continues working the same way. |
Whether to enable direnv integration. Takes care of both installation and | ||
setting up the sourcing of the shell. Additionally enables nix-direnv | ||
integration. Note that you need to logout and login for this change to apply. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should mention the nix setting changes.
What's the status of this useful PR ? |
direnv/direnv#990 is still open. I still haven't signed off on it. This PR would still artificially limit the ability of users to override direnv stdenv functions when using this installation mechanism. that is to say: no - there's no change, as the referenced PR is stagnate right now too. If we can get that merged, I'm happy to assign here once the appropriate changes are made to allow |
FYI, #241528 |
Description of changes
nix-direnv is surprisingly annoying to configure correctly, due to it needing both system-wide adjustments (
nix.conf
changes), but also user-wide adjustments (telling direnv to load nix-direnv using ~/.config/direnv/direnvrc).This module puts an end to that, allowing a direnv + nix-direnv installation with just
Currently this module comes with nix-direnv enabled by default and there's no way to turn it off. If there ever is a need to only enable direnv without nix-direnv we can do that in another PR. I don't need that myself.
Ping @zimbatm @Mic92 @bbenne10
Things done