devbox icon indicating copy to clipboard operation
devbox copied to clipboard

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

Open dubielt1 opened this issue 2 years ago • 5 comments

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",
    "[email protected]",
    "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"
      ]
    }
  }
}

dubielt1 avatar Jun 03 '23 22:06 dubielt1

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?

Lagoja avatar Jun 03 '23 22:06 Lagoja

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

dubielt1 avatar Jun 03 '23 22:06 dubielt1

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

Lagoja avatar Jun 04 '23 01:06 Lagoja

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.

jpambrun-vida avatar Nov 22 '23 21:11 jpambrun-vida

This is still an issue. Please let me know how I can contribute. I'm happy to jump on Discord and discuss it. 🤓

What was the decision in Nov 2023 @Lagoja?

Current State

The documentation on https://www.jetify.com/docs/devbox/cli_reference/devbox_global/ says:

You can use devbox global to install packages that you want to use across all your local devbox projects. For example -- if you usually use ripgrep for searching in all your projects, you can use devbox global add ripgrep to make it available whenever you start a devbox shell without adding it to each project's devbox.json.

This does not say that you must activate devbox global in order to use it. In fact, the next line signals the opposite. I've added **** for emphasis.

You can ****also**** use Devbox as a global package manager by adding the following line to your shellrc:

eval "$(devbox global shellenv)"

That reads like, outside of devbox shell you can also use devbox global to manage packages.

Scope

The feature is documented here:

  • https://github.com/jetify-com/devbox/blob/a235f7d3bf4c7dc787f2e037bcd45120718d519f/docs/app/docs/devbox_global.md?plain=1#L22
  • https://github.com/jetify-com/devbox/blob/a235f7d3bf4c7dc787f2e037bcd45120718d519f/docs/app/docs/cli_reference/devbox_global.md?plain=1#L3

Steps to Reproduce

Confirm there are no global packages:

$ devbox global list
[Evidence no packages are installed]

Add ripgrep:

$ devbox global add ripgrep
Info: Adding package "ripgrep@latest" to devbox.json
Info: Installing the following packages to the nix store: ripgrep@latest

Warning: devbox global is not activated.
...

Start a fresh devbox shell and expect ripgrep to be available:

$ mkdir demo
$ cd demo

$ devbox init

$ devbox shell
✓ Computed the Devbox environment.
Starting a devbox shell...

(devbox) developer@vm demo % which ripgrep
ripgrep not found

Verify ripgrep is installed globally from devbox shell:

(devbox) developer@vm demo % devbox global list
* ripgrep@latest - 14.1.1

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)"

It reports devbox global is not activated. 😭

Attempt to activate:

(devbox) developer@vm demo % eval "$(devbox global shellenv)"
(devbox) developer@vm demo % which ripgrep
ripgrep not found

It is not found when activated from inside the shell. 🐛

seanpoulter avatar Jul 15 '25 00:07 seanpoulter