Hi, thanks for direnv! It’s been life-changing. Thanks to direnv, my virtualenvs are automatically activated/deactivated per-directory, and project config and secrets are all in environment variables and loaded by direnv, making it easy to have parity between dev and production.
There are too many edge cases. For example, what happens if the user just closes the shell? direnv is just a hook that is executed before every prompt and wouldn’t know about it. Or what happens if two shells are opened on the same project, how does direnv keep track?
Users that ask for this generally want to start/stop service on demand for a project. I think the best for that is to actually open a second shell and start a process manager by hand. Then you get to see what services are running, you can start/stop them, …
“not guaranteed to be called in case of closed terminal” are semantics I would welcome. I just want to hook into where it says “direnv: unloading”. My idea was to style my terminal (eg. terminal tab) by directory, and hooking into direnv’s activated inheritance seemed the perfect place to set/unset it. I can do something on directory enter with a plugin but not on directory leave without unload.
Yes, it would be nice if more projects would support libpq environment variables. Various non-C (and non-C depencies) libraries support them, often by simply not specifying a configuration out of the box. It tends to make a lot of things easier, also when you wanna do postgres over unix sockets - authors tend to forget about that use case.
Direnv is the perfect companion to nix-shell and nix develop and has native support for shell.nix with nix-direnv providing caching support as well as flakes integration. It also integrates well with emacs. In short, per-project nix-based “virtualenvs” activated on entry. Love it!
I’ve been using direnv a lot since I discovered it…. great tool. I mostly use it to switch PASSWORDSTORE_DIR settings based on customer-directory I’m in, do stuff like automatically git-pull when entering project-directories etc.
Can’t recommend it enough.
Yeah, there’s an allowlist based on the file path and (I assume a hash of) the contents:
sub-rosa
> cat .envrc
use flake
> echo "FOO=bar" >> .envrc
direnv: error /home/vector/code/sub-rosa/.envrc is blocked. Run `direnv allow` to approve its content
Since I discovered this at work I started using it for side projects as well. It’s such a useful little tool to have, and it removes a lot of the pain of working with local state like Python virtualenv etc. Together with Nix, it’s really a bit of secret weapon because you can install a complete development environment which doesn’t pollute your profile, without mucking about with Docker-compose or other complex nonsense like that. And, the tools are available from your local shell.
It’s a really really useful tool. Per-directory environment variables are great for complex projects, and I have emacs configured to load the config as well, so it also applies to any buffers I have open.
hi, direnv author here :)
Don’t have a question but love the tool! Thank you!
thanks! :)
Hi, thanks for direnv! It’s been life-changing. Thanks to direnv, my virtualenvs are automatically activated/deactivated per-directory, and project config and secrets are all in environment variables and loaded by direnv, making it easy to have parity between dev and production.
Since you’re here, wanted to ask: you think unload hooks can ever be a thing? There’s a longstanding ticket for the feature: https://github.com/direnv/direnv/issues/129
There are too many edge cases. For example, what happens if the user just closes the shell? direnv is just a hook that is executed before every prompt and wouldn’t know about it. Or what happens if two shells are opened on the same project, how does direnv keep track?
Users that ask for this generally want to start/stop service on demand for a project. I think the best for that is to actually open a second shell and start a process manager by hand. Then you get to see what services are running, you can start/stop them, …
“not guaranteed to be called in case of closed terminal” are semantics I would welcome. I just want to hook into where it says “direnv: unloading”. My idea was to style my terminal (eg. terminal tab) by directory, and hooking into direnv’s activated inheritance seemed the perfect place to set/unset it. I can do something on directory enter with a plugin but not on directory leave without unload.
I freaking love direnv. Thank you so much!
This is a great use of direnv: https://jamey.thesharps.us/2019/05/29/per-project-postgres/ , i myself use it to automatically enter the virtual environment of my projects.
Yes, it would be nice if more projects would support libpq environment variables. Various non-C (and non-C depencies) libraries support them, often by simply not specifying a configuration out of the box. It tends to make a lot of things easier, also when you wanna do postgres over unix sockets - authors tend to forget about that use case.
Project is pretty cool, however my .profile is not clutered.
.profile
.shrc
and other dot files are better kept minimal. I just have a script for each project, something likeIt’s self contained and easy to modify and switch to an alternate one. Want a quick check of a project on a remote machine,
ssh remote the-project-setup make check
My dotfiles https://adi.onl/.*.html
I usually just send CLI parameters
PARAM1=foo PARAM2=bar program
or create launcher scripts with the params presetDirenv is the perfect companion to
nix-shell
andnix develop
and has native support forshell.nix
with nix-direnv providing caching support as well asflakes
integration. It also integrates well withemacs
. In short, per-projectnix
-based “virtualenvs” activated on entry. Love it!I’ve been using direnv a lot since I discovered it…. great tool. I mostly use it to switch PASSWORDSTORE_DIR settings based on customer-directory I’m in, do stuff like automatically git-pull when entering project-directories etc. Can’t recommend it enough.
Is it possible to mess up a shell with this? Like putting something like ´MY_VAR=$(rm -r ~)’ ?
Yes but you have to execute
direnv allow
every time the .envrc file changes, so it’s hard to just sneak it in.Yeah, there’s an allowlist based on the file path and (I assume a hash of) the contents:
That’s right. Both the file path and content are being hashed.
Since I discovered this at work I started using it for side projects as well. It’s such a useful little tool to have, and it removes a lot of the pain of working with local state like Python virtualenv etc. Together with Nix, it’s really a bit of secret weapon because you can install a complete development environment which doesn’t pollute your profile, without mucking about with Docker-compose or other complex nonsense like that. And, the tools are available from your local shell.
It’s a really really useful tool. Per-directory environment variables are great for complex projects, and I have emacs configured to load the config as well, so it also applies to any buffers I have open.