Wrong nix parameters given to Stack

After bumping GHC from “ghc8107” to “ghc924”, Stack is not working anymore.

It seems the way to add flags has changed. Here trying to generate a new cabal file:

$ stack hpack                                                                                                                                                                                       
stack: WARNING! Expecting stack options comment at line 1, column 1
stack: WARNING! Missing or unusable stack options specification
stack: WARNING! Using runghc without any additional stack options
Invalid argument `nix/stack-integration.nix'
Error executing interpreter command: stack --nix --no-nix-pure --nix-shell-file runghc -- nix/stack-integration.nix hpack

Stack version is “2.7.5 x86_64 hpack-0.34.7”, apparently it should be hpack 0.35 but I could not find a way to bump it.
I looked at Stack documentation to see if I could spot a format change in parameter but found nothing.

Any idea where to look please? Or even better, a fix!

Edit:
I tried a different order:

$ stack --nix --no-nix-pure --nix-shell-file nix/stack-integration.nix runghc -- hpack
Invalid option `--nix-shell-file'

Do you have some way that someone else could reproduce the error you’re seeing?

A command like stack --nix --no-nix-pure --nix-shell-file nix/stack-integration.nix does seem like it should work. stack --nix-help does list --nix-shell-file as a valid argument, as least with stack-2.7.5.

I’d also suggest using the --verbose flag with stack, so that you can see the actual nix-shell command that stack will invoke under-the-hood.

Thank you for your comments.
My mistake, I thought hpack was installed by default with Stack but it’s not the case, so it could not be found in the new version.
In the end I had to install it separately and call it directly.

1 Like

Stack does not install Hpack, it is compiled with the Hpack library ‘built in’.

If you command (for example) stack build --dry-run and Stack finds a package.yaml file, it will re-create a Cabal file.

Command stack --hpack-numeric-version to discover what version of the Hpack library comes with your version of Stack. Stack 2.9.1 (coming very soon …), will use Hpack version 0.35.0.

Use stack --with-hpack <path_to_your_own_Hpack_executable> to use Stack with your own Hpack executable (for example stack --with-hpack hpack ... if Hpack is on your PATH).

2 Likes

Thanks too, useful additions!

Particularly the --with-hpack option to run it in another context.