Proposal: Add a devcontainer config for VS Code / Github Codespaces

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

I did not find a way to effectively integrate devbox with vscode. As the broad majority of devs are using this editor these days, this is a concern for adoption in large teams.

You can start a devbox shell in the vscode terminal, but it does not set the env of all other vscode process (tasks, debugger, extensions...)

I feel like writing a devcontainer could be a great way to fix this (and free user for the required nix dependency), but I was not successful in implementing it.

Lagoja wrote this answer on 2022-11-03

Hey @pomdtr, we'll look into this feature. Is this something you use to develop locally on your own machine as well? Or is it for remote development?

pomdtr wrote this answer on 2022-11-03

I use this workflow both on my local machine and my remote workspaces. It allows me to get an uniform dev env across all my devices.

mohsenari wrote this answer on 2022-11-03

@pomdtr We recently published the first version of devbox VSCode extension. We'll try to see if we can have the environment for the whole IDE (debugger & path to binaries and dependencies) be updated by the extension. Devcontainer seems like a possible solution as well. We'll update under this issue once we have a solution to move forward on this.

mohsenari wrote this answer on 2022-11-03

on a local environment a workaround for the time being is to open your terminal (outside of IDE) go to devbox shell, then open your IDE from inside devbox shell.

cd my-devbox-project/
devbox shell
code .
pomdtr wrote this answer on 2022-11-03

Cool ! Here is an interesting read on the devcontainer / nix integration:

pomdtr wrote this answer on 2022-11-03

I've got a draft version working for devbox. Please take a look at it:


mohsenari wrote this answer on 2022-11-03

@pomdtr Thanks for sharing this. I don't have codespaces enabled on my github account but I tested it locally with Docker desktop and Dev Containers extension on VSCode and it woks great. Although, it runs vscode from inside a Docker container with a shared volume between the host machine and Docker. That means in a non-Linux OS there might be a performance hit.

That said, I really liked the Dev Containers extension when it detects a .devcontainer it prompts with "Reopen this in devcontainers". Maybe we can add a similar functionality to Devbox's extension. Because if we open vscode from inside a devbox shell, the language binaries and interpreter settings in vscode will be set to devbox's shell environment.

pomdtr wrote this answer on 2022-11-03

I think the performance hit should be quite minimal since the bind mount only contains the workspace folder. There are way to mitigate the performance penalty (see :

mohsenari wrote this answer on 2022-11-03

Ah interesting!
@pomdtr I've shared your example on devcontainer setup with Devbox with the team. Are you ok if we add it to our docs/guides?

pomdtr wrote this answer on 2022-11-03

Go ahead !

pomdtr wrote this answer on 2022-11-03

@mohsenari I have made some improvements on the template. The dependencies are now populated during the build, and the .devbox dir is no longer in the workspace directory (since the symlinks only work in the container, it should not be synced with the host).

The only issue is that the devbox cli is no longer working in the container. It would be cool to add support for setting the .devbox dir path via config.


devbox --config .devcontainer/devbox.json --cache /devbox/.devbox

Ideally I would also like to be able to set these options using environment variable since it would allow me set them in the dockerfile:

ENV DEVBOX_CONFIG=.decontainer/.devbox.json
ENV DEVBOX_CACHE=/devbox/.devbox

Then the user would be able to use devbox add python310 inside the dev container. Currently I need to do this:

devbox --config /devbox/devbox.json add python310 && copy /devbox/devbox.json .devcontainer/devbox.json

Also a devbox install command would be a better alternative to devbox shell --config /devbox/devbox.json -- echo "Devbox Store Populated".

mohsenari wrote this answer on 2022-11-03

Thanks a ton for improving the templates! to summarize your suggestions are:

  • "add support for setting the .devbox/ dir path via config"
  • setting --config and --cache flags using env variables
  • adding a devbox install command as alternative to devbox shell --config /devbox/devbox.json -- echo "Devbox Store Populated"

I'll make separate issues for them to track each independently.

pomdtr wrote this answer on 2022-11-03

Thanks a lot ! If you have some time, it would loke to get some feedback on the dockerfile. I tried to use the buildkit cache feature to reduce the build time on successive builds, but I was not successful.

pomdtr wrote this answer on 2022-11-03

Also, is it ok to move the .devbox file out of the workspace dir ?
It looks like a specific version of the nixpkgs channel is pinned in it.

mohsenari wrote this answer on 2022-11-03

@pomdtr I looked at the Dockerfile, there is not much feedback I have on making it faster. Nix installation takes some time and also first time running devbox shell after a new installation also takes time due to Nix copying stuff to /nix/store. So One idea is to have everything before calling devbox shell and publish it as a public Docker image. That way Nix and devbox get cached as a layer and subsequent runs won't install nix and devbox. Other than that, the Dockerfile looks ok imo.

For moving .devbox/ out of the workspace dir, I don't think it is supported as of now. But if there is a reason other than preference for it, we can prioritize implementing it similar to --config for custom devbox.json path.

Lagoja wrote this answer on 2022-12-01

@pomdtr we have added a feature to the VSCode extension that can generate a .devcontainer.json file and Dockerfile that works with your Devbox project. If you have a chance to try it out, we'd love your feedback on how it works! Closing this comment for now, but can reopen if there are any issues with the Extension

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