How do I `nix run` a binary that isn't the default application?

I am trying to run psql with nix run. The postgresql package in nixpkgs offers the psql binary, but I can’t figure out the correct incantation.

After reading some other answers on GitHub and this forum I tried nix run nixpkgs#postgresql -c psql but -c is now an unrecognised option.

Is this possible? Or must I use nix shell instead?

nix run doesn’t do that, it’s designed around the applications feature of flakes. It’ll only execute the “main” program of derivations, which is either the one with the same name as the package, or whatever meta.mainProgram points to.

nix shell is indeed what you want.

2 Likes