jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.87k stars 211 forks source link

[Bug]: Global packages are not available in project shell #1099

Open dubielt1 opened 1 year ago

dubielt1 commented 1 year ago

Current Behavior (bug) Global packages are not available in project shell:

$ devbox global add ripgrep
$ devbox run which rg #no output
$ devbox shell
(devbox) $ which rg #no output

Explicitly using global will make rg available:

$ devbox global run which rg
/path/to/rg

Warning: devbox global is not activated.

Add the following line to your shell's rcfile (e.g., ~/.bashrc or ~/.zshrc)
and restart your shell to fix this:

        eval "$(devbox global shellenv)"

Expected Behavior (fix) I expect rg to be globally available in all devbox shells

The devbox docs state the following:

You can install a package using devbox global add [], where the package names should be a list of Nix Packages you want to install. ... Once installed, the packages will be available whenever you start a Devbox Shell, even if it's not included in the project's devbox.json.

Additional context OS: Ubuntu 20.04 on WSL2

devbox version -v:

Version:     0.5.4
Platform:    linux_amd64
Commit:      92bb293af46fe6869648c20e4a6476dc83df0092
Commit Time: 2023-06-01T21:35:06Z
Go Version:  go1.20.4
Launcher:    0.2.0

global devbox.json (~/.local/share/devbox/global/default/devbox.json):

{
  "packages": [
    "ripgrep@latest",
    "lazygit@latest",
    "nodejs@18",
    "nodePackages.neovim@latest",
    "python@3.10",
    "python310Packages.pynvim@latest"
  ],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

local devbox.json:

{
  "packages": [
    "go@latest",
    "python@latest",
    "poetry@latest"
  ],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}
Lagoja commented 1 year ago

Hey @dubielt1, based on the message when you run devbox global run which rg, it sounds like you haven't sourced devbox global in your shell's rc file. Is your goal to use the devbox global packages in your devbox projects, but not in your host shell?

dubielt1 commented 1 year ago

Hi @Lagoja, that's correct. I only intend to use global packages when I am inside of a devbox shell. I would prefer not to edit my bashrc, per the warning mentioned

Lagoja commented 1 year ago

Gotcha. I'll discuss with the team on Monday. Thanks for reporting!

jpambrun-vida commented 1 year ago

I had the same expectation as @dubielt1. Given the documentation, I also expected global package to be available when devbox shell --pure.

If the goal is to eliminate the "it works on my machine" then host app/lib should not be available on the shell. On the other hand, since you mount $HOME and bashrc is loaded, individual dev needs the ability to add some packages to all devboxes. For example, my bashrc has alias ls=exa so I personally need exa everywhere.