-
Notifications
You must be signed in to change notification settings - Fork 626
Homebrew
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.
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
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.
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.
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.