Using flake input with `nix shell`

I use nix flakes to control project inputs, and sometimes this includes something like nvfetcher. e.g.:

    inputs.nvfetcher = { url = "github:berberman/nvfetcher"; };

Sometimes it would be useful to open a nix shell and grab a binary from exactly version of the input flake my flake is using, rather than what my global registry points it to. Is there a way to do this that I’m overlooking?

In this case I’d like to grab a copy of nvfetcher-bin without having to re-export it as a package.

1 Like

--inputs-from . seems to be exactly what you needed

   • --inputs-from flake-url
     Use the inputs of the specified flake as registry entries.

o\ I assumed it’d pick the “raw” input, rather than what flake.lock locks it to, but that’s not how flakes work at all.


How does this work exactly?

I have a flake.nix with inputs like

  inputs = {
    agenix.url = "github:ryantm/agenix";

Now I want to run a nix shell with the locked inputs.agenix in my shell environment.
I can do that somehow with nix shell --inputs-from .?

See Flakes: syntax for referring to a flake's input at the command-line · Issue #5660 · NixOS/nix · GitHub

You can use:

nix shell --inputs-from . agenix#agenix

This will treat your flake.nix’ inputs as the flake registry, and therefore “agenix” will refer to the pinned repo, which in turn (presumably) has an agenix derivation that this will evaluate and make part of your shell environment.

1 Like