Akin to dotenv in the JS ecosystem, do you guys use anything more generic in your Linux / Mac boxes that automatically loads a file (ideally called .env) when you enter the directory where the file is?
I found direnv so far. Anybody using it? Or anything else?
I prefer to manually source from a set of files which alter my environment to my needs.
During the ruby days I used rvm to manage ruby versions, which allowed to set up the environment when entering the directory. This allowed every random git repository I checked out to run arbitrary code due to how it was implemented.
Also it was kind of strict, as it only allowed to have a single environment, rather than many.
I’ve been using direnv for a very long time. It’s great, no manual sourcing. I always add “PATH_add bin” + needed env variables. The file is always git ignored but I back up it manually to gopass / get variables values from gopass.
I can install direnv alright but not sure how will I go about backing up the files. I use a monolithic single-encrypted-vault-file password manager synced through Dropbox (namely Enpass) already but it doesn’t have an API like gopass (command-line in this case).
I also have scripts that I am source-ing. Maybe I should make the files in the project directories source these because they are already backed up to Dropbox as well.
EDIT: Any idea how to make direnv work for a bunch of directories which are children of the one where your .envrc is located? I have a ~/code/<org_name>/...several projects... directory. I guess I can copy-paste the same file across all of them.
If you’re thinking in terms of project environment variables that works with Mix, then I’ve used Envy before which works pretty well. I don’t recommend this for production use, but for local development it works well.
I just have my dev.exs config file also import a dev.secrets.exs file which isn’t checked in (via .gitignore) and I try to avoid actual env vars on my local machine. Multiple projects with conflicting env vars on a local machine is a good way to lose your sanity.
To load .envrc from higher directories you need to explicitly use source_env [path] where [path] can be relative or absolute, however keep in mind that these files will not be source protected. If you want to load .env files you can use dotenv command in the same manner. More information can be found at man 1 direnv-stdlib.