Proposal: add direnv config

This issue has been tracked since 2022-10-05.

Here is what I came up with:

#!/usr/bin/env bash

direnv_load devbox shell -- direnv dump
watch_file devbox.json

Thanks to this, as soon as I cd inside my project folder, I'm inside the devbox shell. Newly added package are also automatically loaded in the current shell.

It might be worth to add it somewhere, but I'm not sure where.

methyl wrote this answer on 2022-10-12

This is great. I think there should be a documented way of using devbox shell to provide environment for VSCode (and probably other IDEs), so that any extension can transparently use devbox environment for running binaries.

pomdtr wrote this answer on 2022-10-12

Sadly it is not working really well in vscode (the direnv extension is not really good at overriding the user path). I think writing a devcontainer instead would be better :)

mohsenari wrote this answer on 2022-10-12

@pomdtr That's a great suggestion. We've been looking into integrating with direnv for the past couple weeks. You suggestion technically works but it also makes devbox think it's in a shell subprocess. So if you go into your direnv allowed directory and run devbox shell it will output:

Error: You are already in an active devbox shell.
Run 'exit' before calling devbox shell again. Shell inception is not supported

So when you run exit you're thrown out of your terminal, not the devbox shell subprocess which is not the intended behavior and can be confusing to some users.

This can be fixed, of course, but for the time being we're working on #213 which you put devbox shell --print-env in your .envrc and it updates your PATH with all the binaries you would get if you had been in a devbox shell.
We're also working on improving this command to make your shell's environment as close to a devbox shell environment as possible while making sure the confusions like the error above doesn't happen.

mohsenari wrote this answer on 2022-10-12

@methyl We're looking into VSCode integration with direnv + devbox as well. If we can't get the extension to work with a devbox environment as we intend, we might have to write our own extension.
Either way, we'll follow up on this issue once we have a solid solution for VSCode setup.

pomdtr wrote this answer on 2022-10-12

For direnv to work with vscode, it looks like you will need to patch the whole code process (and it is not working with the last vscode version). See for more details.

This why I thought about using a devcontainer instead (see #226)

mohsenari wrote this answer on 2022-11-03

@methyl We published a devbox extension for VSCode. It detects if you have devbox.json and when you open terminal in the IDE, it automatically goes to devbox shell.
Feel free to give it a try and let us know if you have any suggestions.

methyl wrote this answer on 2022-11-03

@mohsenari thanks for a heads up! I think it's solving less problematic issue of having terminals in vscode open devbox shell, what's more important I think is to make sure extensions can use devbox to run the binaries. Sometimes you can configure the path of the executable, but it's not always possible and quite unhandy to do that for every extension that relies on external binaries.

More Details About Repo
Owner Name jetpack-io
Repo Name devbox
Full Name jetpack-io/devbox
Language Go
Created Date 2022-08-18
Updated Date 2023-03-31
Star Count 4960
Watcher Count 19
Fork Count 68
Issue Count 42


Issue Title Created Date Updated Date