nix
nix copied to clipboard
`nix run`: Better feedback for app with wrong executable name
Is your feature request related to a problem? Please describe.
As a new user learning about flakes, I was playing around with writing one for a simple haskell project called "yesoder" using the cabal2nix flake template. I was using flake-utils.lib.mkApp to create the default app. When I typed nix run, I got the following error:
error: unable to execute '/nix/store/59gp19sna8p2pjhvpv1zza68b7q9wfi5-yesoder-0.1.0.0/bin/yesoder': No such file or directory`
This was very confusing for me.
The issue was that haskell build tools by default output binaries with "-exe" appended to them. In this case the binary was yesoder-exe. I, being a beginner, had not realized I needed to pass exePath = "/bin/yesoder-exe"; to mkApp. I'm not entirely sure what happened, but my assumption is that mkApp defaults to using the package name as the app's program if exePath is not supplied.
Describe the solution you'd like
Perhaps nix run could give some feedback along the lines of
Make sure your app's `program` attribute is set correctly.
<pretty printed evaluated app attrset>
See <link to documentation of flake output schema> for more details
This would go a long way towards making the problem easier to understand. As a bonus, if it was really smart it might be able to scan the bin directory for similar names and ask "did you mean /bin/yesoder-exe?"
Describe alternatives you've considered None
Additional context n/a
I think this would really increase the UX, as this sometimes happens to me when running a binary from nixpkgs which I forgot to install or want to try out. E.g. nix run nixpkgs#freerdp3 fails. It took a frustrating long time to find out what I can do instead, especially because it is another sub-command (because it works different internally): nix shell nixpkgs#freerdp3 --command sdl-freerdp.
(Not specially important for this issue, but in my example it fails because freerdp3 provides different binaries, depending on the backend: xfreerdp, wlfreerdp & sdl-freerdp. In that example, it is not feasible to just fix the package.)
A different solution here would be to make nix run a bit more forgiving in how it finds the executable. For example, if there is only a single executable in <store-path>/bin, it could just use that (and maybe show a warning).
Additionally it would be nice if nix run could also just execute <store-path> if it's a file and not a directory. This would be helpful, see https://github.com/nix-community/disko/pull/78