nix-community / nix-index

Quickly locate nix packages with specific files [maintainers=@bennofs @figsoda @raitobezarius]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`command-not-found` prints out wrong `nix run` command

bbjubjub2494 opened this issue · comments

On a flakified system, the interactive shell CNF handler responds with something like

The program 'ff2png' is currently not installed. You can install it
by typing:
  nix profile install nixpkgs#farbfeld.out

Or run it once with:
  nix run nixpkgs#farbfeld.out --command ...

It does not appear as though --command is a flag for nix run. nix shell however has such a flag, so the message could be
nix shell nixpkgs#farbfeld.out --command ...

OS: NixOS 22.05
Nix: 2.8.1, 2.9.1

Having this same issue 😅 I'll look into fixing it and make a PR.

Ok so there's two options:

  • using nix run $toplevel#$attrs -- <args>
  • using nix shell $toplevel#$attrs --command <command>

Personally I prefer the second option, because you'd occasionally have no application defined in the output for "$attrs", which trips up run; but with shell it adds the package to the PATH and then runs whatever comes after --command. Additionally, it allows to use it in conjunction with other programs in a pipe and such.

commented

I'd recommend the latter with -c instead of --command (just because it takes up less space).

That's fair! I usually like presenting the longer options so new people can understand it more easily at a glance, but they can always run --help at some point later on

commented

Yeah I'm usually a long options defender, but in this case I think teaching people there's a syntax short enough to want to type is valuable. It also reduces confusion with the nix-shell(1) --command option which works slightly differently.

That's fair, we should go with -c then! 😁