Some Direnv Patterns

May 1, 2024

A by-no-means-exhaustive list of direnv configuration techniques I’ve found helpful.

Local configuration only

Situation: the project requires environment variables to function. There is no need to capture how those variables should be provisioned in source control, or no consensus to do so among the contributors.

Approach:

Shared configuration, local variations

Situation: the project requires environment variables to function. For development, there is a consensus to use direnv, but individual values cannot or should not be captured in source control.

Approach:

Common environment settings across multiple projects

Situation: multiple projects require identical environment variable sets. These projects share a parent directory, which also contains projects that do not need those environment variables.

For me, this is my AWS creds, which are used by multiple projects inside of my ~/Projects directory, but not by everything there.

Approach:

Tokens in a password manager

Situation: you have confidential authentication tokens that you need to provide in order to access an external service. You don’t want them on the filesystem.

Approach:

Caveat: Many password managers implicitly start an agent process, which lurks in the background facilitating access. This agent can cause direnv to wait indefinitely.