Skip to content

v3 is missing an equivalent for nix-shell -p #12867

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

Open
2 tasks done
NobbZ opened this issue Apr 1, 2025 · 4 comments
Open
2 tasks done

v3 is missing an equivalent for nix-shell -p #12867

NobbZ opened this issue Apr 1, 2025 · 4 comments
Labels
feature Feature request or proposal

Comments

@NobbZ
Copy link
Contributor

NobbZ commented Apr 1, 2025

Is your feature request related to a problem?

With the v2 interface I can create fully functional dev shells from a single command without the necessity of declaring them in a file:

$ nix-shell -p pkg-config openssl --run 'pkg-config --libs openssl'
-L/nix/store/954l60hahqvr0hbs7ww6lmgkxvk8akdf-openssl-3.4.1/lib -lssl -lcrypto

There is no way known to me (and many other people I have asked) to reproduce this behavior with the v3 CLI.

Proposed solution

Provide a flag for nix develop that is capable of mimicking the nix-shell -p behavior.

Alternative solutions

Additional context

Checklist


Add 👍 to issues you find important.

@NobbZ NobbZ added the feature Feature request or proposal label Apr 1, 2025
@Sk7Str1p3
Copy link

You have 'nix shell nixpkgs#pkg' and 'nix run nixpkgs#pkg --arg'

@NobbZ
Copy link
Contributor Author

NobbZ commented Apr 4, 2025

Can you reconstruct my example, given those commands?

I am aware of the develop, shell, and run verbs of the v3 CLI, though I have not found a way to use them in a way that would result in the same functionality as exampled in the OP.

@NobbZ
Copy link
Contributor Author

NobbZ commented Apr 4, 2025

Addendum:

The intuitive replacement does not work, as nix shell does not run setup hooks:

$ nix shell nixpkgs#{pkg-config,openssl} -c pkg-config --libs openssl
Package openssl was not found in the pkg-config search path.
Perhaps you should add the directory containing `openssl.pc'
to the PKG_CONFIG_PATH environment variable

And after several discussions we figured an actual invocation, though we siply consider it to not exist, as it is convoluted and impure and doesn't support flakeref syntax directly and is basically just writing out a shell expression on the CLI…

$ nix develop --impure --expr 'let pkgs = (builtins.getFlake "flake:nixpkgs").legacyPackages.x86_64-linux; in pkgs.mkShell { packages = with pkgs; [pkg-config openssl]; }' -c pkg-config --libs openssl
-L/nix/store/954l60hahqvr0hbs7ww6lmgkxvk8akdf-openssl-3.4.1/lib -lssl -lcrypto

A pure variant of this can be done by using a hashed version of getFlake, but that doesn't make it easier to use…

@roberth
Copy link
Member

roberth commented Apr 7, 2025

I don't think we should make the mistake of coupling with Nixpkgs / stdenv interfaces again. For instance nativeBuildInputs is unsupported, and we'd need to implement and endless stream of features to keep up with shell building functions.
Instead, we could make the CLI invocation easier.

a. Make it easy to bring a flake into the scope of an expression that's passed as an argument
b. Make it easy to bring things from a flake into scope. This should be the same solution that replaces the rejected repl-overlays feature.

Then it should look somewhat like nix develop --use nixpkgs 'mkShell { buildInputs = [ openssl ]; nativeBuildInputs = [ pkg-config ]; }'. I don't know if --use is a good name, but this could be made to work.

For (b) I think it should be a flake output attribute containing a function that receives currentSystem as an argument, and returns an attrset whose attributes will be brought into scope as variables by nix repl and --use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

3 participants