direnv is an open source environment management tool that allows setting unique environment variables per directory in your file system. This guide covers how to configure direnv to seemlessly work with a devbox project.
- Install direnv and hook it to your shell. Follow this guide if you haven't done it.
Setting up Devbox Shell and direnv
Note: If you already have a devbox project you may skip to step 3.
devbox initif you don't have a devbox.json in the root directory of your project.
devbox shell -- 'ls'to activate devbox shell temporarily and make sure dependencies mentioned in your devbox.json are installed.
- Create a new file, name it
.envrcand put the following snippet inside it:
eval $(devbox shell --print-env)
direnv allowto give permission to
direnvto setup your environment variables.
- At this point, your project directory is setup so that every time you
cdinto it, the binaries from your devbox shell will be used. To test this, you can compare running
which python3from your project directory and outside.
Global settings for direnv
Note that every time changes are made to
devbox add ...,
devbox rm ... or directly editing the file, requires
direnv allow to run so that
direnv can setup the new changes.
Alternatively, a project directory can be whitelisted so that changes will be automatically picked up by
direnv. This is done by adding following snippet to direnv config file typically at
~/.config/direnv/direnv.toml. You can create the file and directory if it doesn't exist.
prefix = [ "/absolute/path/to/project" ]
If this guide is missing something, feel free to contribute by opening a pull request in Github.