Cabal tries to build unknown package when building with alex, happy in nix-shell

880 views Asked by At

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:


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:

    1. 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.

    2. 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.

    3. 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.

1

There are 1 answers

7
Robert Hensing On

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 install alex and happy the way it wants and continue to build your project.

$ cabal v2-build
[... omitted ...]
[__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

$ cabal update
Downloading the latest package list from hackage.haskell.org

$ cabal v2-build
Resolving dependencies...
Build profile: -w ghc-8.10.2 -O1
In order, the following will be built (use -v for more details):
 - alex-3.2.6 (exe:alex) (requires download & build)
 - happy-1.20.0 (exe:happy) (requires download & build)
 - aoc-0.1.0.0 (lib) (configuration changed)
 - aoc-0.1.0.0 (exe:aoc) (dependency rebuilt)
Downloading  happy-1.20.0
[... omitted ...]
Configuring library for aoc-0.1.0.0..
Preprocessing library for aoc-0.1.0.0..
Building library for aoc-0.1.0.0..
[... omitted ...]


According to the Cabal build-tools documentation the field has been deprecated and removed. It seems like you'll be better off with build-tool-depends.

    build-tool-depends:
      alex:alex >=3.2.5 && <3.3
    , happy:happy >=1.20.0 && <1.21