Skip to content
Jonas Chevalier edited this page Jan 29, 2021 · 4 revisions

Status: not working

Please contact @zimbatm if you want to contribute to this.

In theory, it's possible to combine direnv and Homebrew to bring project-specific dependencies into the environment.

It's not as precise as using Nix or Guix and old versions might get removed. Need more experience to know how viable the solution is.

Basic idea

Homebrew has a concept of "keg", where each specific version of the software is installed into their own prefix. Eg: /usr/local/Cellar/postgresql@11/11.10/

So, in principle, it should be possible to pull all those dependencies and construct our own PATH from those. Which would allow to precisely pin all of the versions being used in a project.

Homebrew also has a concept of "Brewfile" which is a file that describes a set of dependencies. It even has a "Brewfile.lock.json". So, again in principle, this could be used to describe all the dependencies for a project.

Then finally it has a brew bundle exec -- <command> [...<args>] command that can be used to execute things in the context of the bundle.

An .envrc could then look something like that:

direnv_load brew bundle exec -- direnv dump

Current problems

brew bundle is missing a "--keg-only" option.

Currently, brew bundle installs all of the dependencies and links them into "/usr/local". That's not what we want. The project dependencies should not influence the system installation.

brew bundle exec doesn't install anything

Ideally, it would automatically check the Brewfile and Brewfile.lock.json and install the missing dependencies. That's not a big problem as we can always invoke brew bundle first.

brew bundle exec cleans the environment

direnv_load depends on having some environment variable set and forwarded to the direnv dump command.

Ideally brew bundle exec would have a mode that only appends to the environment.

Repro: DIREN_DUMP_PATH=/foo/bar brew bundle exec -- bash -c 'env | grep DIRENV' returns nothing.

We can work around this by selectively forwarding specific env vars like PATH.

Clone this wiki locally