Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: devbox shell -p somepackage #1465

Open
altano opened this issue Sep 10, 2023 · 9 comments
Open

[Feature]: devbox shell -p somepackage #1465

altano opened this issue Sep 10, 2023 · 9 comments
Labels
feature New feature or request

Comments

@altano
Copy link

altano commented Sep 10, 2023

Is your feature request related to a problem you're trying to solve? Please describe.
There are too many steps to testing out a package. I potentially potentially have to:

  1. devbox init
  2. devbox add X
  3. devbox shell
  4. rm devbox.json ... # maybe cleanup stuff I don't need

Describe the solution you'd like
I would like something equivalent to nix-shell -p <package>1 which allows you to temporarily, on only the current shell, have access to a package. I think the most obvious way to expose this is to have devbox shell take a -p option that allows the same syntax as devbox.json packages, e.g. devbox shell -p ruby@3.2.2 should work.

Describe alternatives you've considered
This doesn't enable anything new. It is just a convenience method.

Additional context
This was requested in #50 but I think that request got misinterpreted as having a way of running a one-off command on a temporary devbox shell and the part about having access to a package got missed.

Footnotes

  1. https://nixos.org/manual/nix/stable/command-ref/nix-shell#options

@altano altano added the feature New feature or request label Sep 10, 2023
@Lagoja
Copy link
Contributor

Lagoja commented Sep 11, 2023

This is interesting, and something we've discussed previously. A few questions for discussion:

  1. If you run devbox shell -p in a directory with a devbox.json, would you expect it to apply the devbox.json environment as well?
  2. Would this also support creating a shell with multiple packages? (I think so)
  3. Would you want this to function like devbox shell, where we leak your current environment variables and shell, or like nix shell, where you get a fully new shell?

@altano
Copy link
Author

altano commented Sep 12, 2023

I think you can make up whatever you want, as the most simple of use-cases (I want a shell with a package and I don't care how I get it) is probably all that is desired most of the time. This feature is dangerous if over-used or relied on too much, so it should very much be a one-off temporary thing.

That said, I'd be happy to tell you what nix-shell does as inspiration:

If you run devbox shell -p in a directory with a devbox.json, would you expect it to apply the devbox.json environment as well?

nix-shell -p inherits the current shell and all available packages (e.g. it continues to use configuration.nix). It is also nestable, unlike devbox shells, so that would be a consideration here (just special case and allow nesting when -p is specified?):

$ which ruby; which python
which: no ruby in ...
which: no python in ...

$ nix-shell -p ruby

$ which ruby; which python
/nix/store/.../bin/ruby
which: no python in ...

$ nix-shell -p python3

$ which ruby; which python
/nix/store/.../bin/ruby
/nix/store/.../bin/python

Would this also support creating a shell with multiple packages? (I think so)

nix-shell -p does allow this (and the full option name is plural: --packages):

$ nix-shell -p ruby python3
$ which ruby; which python;
/nix/store/.../bin/ruby
/nix/store/.../bin/python

Would you want this to function like devbox shell, where we leak your current environment variables and shell, or like nix shell, where you get a fully new shell?

I don't have a use-case that cares so I won't state my arbitrary preference.

@Akiyamka
Copy link
Contributor

Akiyamka commented Sep 14, 2023

Cool feature!
Sometimes I need to build some utility from an open repository that requires rust, or golang of a certain version. Since these dependencies are needed only once, it would be very convenient to specify the packages at once without creating a devbox file.

If you run devbox shell -p in a directory with a devbox.json, would you expect it to apply the devbox.json environment as well?

Not my case, these projects don't have devbox.json (yet ;- )

Would this also support creating a shell with multiple packages? (I think so)

Sure

Would you want this to function like devbox shell, where we leak your current environment variables and shell

I think yes

@Lagoja
Copy link
Contributor

Lagoja commented Sep 14, 2023

Related to #1275

@wrdls
Copy link

wrdls commented Oct 10, 2023

I created the following in my .zshrc

dbe () {
        local pkgs="$@" 
        [ -z "$pkgs" ] && printf "dbe: missing argument.\nUsage: dbe PKG1 PKG2 ...\n" && return 255
        local pkgs_sha256=$(echo "$pkgs" | sort | sha256sum | awk '{print $1}') 
        local configdir="${HOME}/.cache/devbox/ephemeral/${pkgs_sha256}" 
        mkdir -p "$configdir"
        devbox init "$configdir"
        devbox add -c "$configdir" $pkgs
        devbox shell -c "$configdir"
}

(dbe = DevBox Ephemeral)

E.g.

dbe terraform_0_15@0.15.5

My main use-case for this is a Terraform repository with a bunch of projects with different Terraform versions.
Devbox is not widely used in my company yet, so I also don't want to pollute the repository.

@pomdtr
Copy link

pomdtr commented Nov 3, 2023

Another usecase: I would love to use devbox for writing portable scripts (by leveraging shebangs).

See https://yukiisbo.red/notes/spice-up-with-nix-scripts/

@altano
Copy link
Author

altano commented Nov 3, 2023

Wow I love that use case.

@kadaan
Copy link
Contributor

kadaan commented Mar 4, 2024

See https://pkgx.sh/ for inspiration.

@djgoku
Copy link

djgoku commented Mar 5, 2024

Another usecase: I would love to use devbox for writing portable scripts (by leveraging shebangs).

See https://yukiisbo.red/notes/spice-up-with-nix-scripts/

https://nixos.wiki/wiki/Nix-shell_shebang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Development

No branches or pull requests

7 participants