Hspec-discover not available in shell

I have a Haskell package I’m developing and trying to write a flake.nix for. Its tests use hspec-discover and the cabal file contains


After entering a shell with nix develop I see that hspec-discover is installed:

(ins)$ ghc-pkg list | rg hspec

(ins)$ whereis hspec-discover
hspec-discover: /nix/store/vaq3gvak92whk5l169r06xrbkx6c0lqp-ghc-9.2.8-with-packages/bin/hspec-discover /nix/store/986bnyyhmi042kg4v6d918hli32lh9dw-hspec-discover-2.9.7/bin/hspec-discover

However, cabal isn’t able to find hspec-discover and thus building and running the tests fail in the shell:

(ins)$ cabal run test:my-test
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: my-pkg-0.0.1 (user goal)
[__1] trying: my-pkg:*test
[__2] next goal: my-pkg:hspec-discover:exe.hspec-discover (dependency of my-pkg *test)
[__2] rejecting: my-pkg:hspec-discover:exe.hspec-discover-2.9.7/installed-G6Vto7m4JRcDmAko2pMBBi (does not contain executable 'hspec-discover', which is required by my-pkg *test)
[__2] fail (backjumping, conflict set: my-pkg, my-pkg:hspec-discover:exe.hspec-discover, my-pkg:test)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: my-pkg, my-pkg:test, my-pkg:hspec-discover:exe.hspec-discover, hspec, hspec-discover, servant-openapi3
Try running with --minimize-conflict-set to improve the error message.

What should I do to make sure hspec-discover is found?

1 Like

See the warning:

Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.

It’s a hint that cabal-install wants to build something itself (here hspec-discover), and it should succeed after a cabal update.
I don’t know if there is a way to make cabal-install use build-tool-depends provided by nix develop.
You can use cabal v1-test.
There is a cabal issue about that change of behavior with v2-* commands: `build-tool-depends` executables don't have a `.conf` file · Issue #8434 · haskell/cabal · GitHub
Note that nix build is not affected because it uses another build method:

both Nixpkgs & haskell.nix use the Setup.hs method of configure / install, which doesn’t install a .conf file for executable components

1 Like

Indeed, just running cabal update solved it.

That particular warning

Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.

is printed when running other cabal commands too, but they still work without an updated package list :man_shrugging:

I did see others asking about this online too, but not any mention of simply following what the tools tells you to do :grin: