Search code examples
nix

`nix-shell -p [package] --command [command]`


I'm trying to run a command in script using nix-shell -p [package] --command [comand] and getting an error Permission denied on files, that the command needs to operate on. The command needs only read access and if I try to do nix-shell -p [package] and then run the [command] there by hand, then everything is okay, but if I try to do it through the --command [command] it gives me an error. Why is that?

Edit:

The command looks like this: nix-shell -p ormolu --command "ormolu --mode check $(find . -name '*.hs')"


Solution

  • This has nothing to do with nix-shell (or ormolu). Try this instead:

    nix-shell -p ormolu --command "find . -name '*.hs' -exec ormolu --mode check {} + "
    

    The reason you've got permission denied is that you actually passing the first output of the find command to ormolu, and trying to execute the rest of the .hs files.