I'm currently trying to build a Haskell project using nix-shell and cabal, with alex and happy as build tools. Building inside nix-shell (with and without --pure
), I get the following strange error message:
cabal: Could not resolve dependencies:
[__0] trying: aoc-0.1.0.0 (user goal)
[__1] unknown package: aoc:happy:exe.happy (dependency of aoc)
[__1] fail (backjumping, conflict set: aoc, aoc:happy:exe.happy)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: aoc, aoc:happy:exe.happy
It appears to be trying to satisfy some nonsense dependency aoc:happy:exe.happy
, despite no reference to such a thing in the cabal file. Within the nix-shell, I am able to run alex
and happy
directly as executables, as they have been provided by nix.
Question: Does anyone know what I might be able to try to resolve this? I would like to try to provide dependencies completely using nix, instead of using cabal update
to download packages from Hackage.
The source code can be found in the branch unhappy
here, with files of interest:
- package.yaml (for hpack)
- aoc.cabal
- default.nix
Some things I've tried so far are:
I found a similar-looking error here, but it was not fully resolved, and the nix build there was using haskell.nix.
I've tried the following other build methods while troubleshooting:
Building with cabal/ghc installed through ghcup (cabal 3.2.0.0, ghc 8.10.2): the build succeeds—alex and happy are fetched from Hackage and run successfully as
build-tools
.Building with nix-build: the build runs successfully (without packages being fetched to .cabal).
callCabal2nix
recognizes alex and happy, and provides them successfully to cabal.Building within nix-shell with
cabal update
: the same as 1. occurs and it succeeds, as nix's provided cabal fetches the packages from Hackage, but this is not what I'm trying to accomplish.
I've also tried using nix-shell to build a minimal example alex/happy project, using the same generic *.nix files from my own project, with the same errors being produced.
Cabal simply isn't convinced that
alex
is installed by Nixpkgs' custom Haskell environment (the.env
attribute on the package that you correctly use for the shell).If you run
cabal update
, cabal-install will be able to installalex
andhappy
the way it wants and continue to build your project.According to the Cabal
build-tools
documentation the field has been deprecated and removed. It seems like you'll be better off withbuild-tool-depends
.