3

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.

CH.
  • 556
  • 1
  • 5
  • 16

1 Answers1

1

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
Robert Hensing
  • 6,708
  • 18
  • 23
  • Thank you for your answer! I've tried building with `build-tool-depends` instead, but the error unfortunately persists. – CH. Dec 14 '20 at 10:36
  • Seems like you didn't have a package list yet. See the answer. It's a bad error message from cabal. – Robert Hensing Dec 15 '20 at 12:06
  • Yes, that is correct. I have been using nix to fulfill other dependencies so far without a package list. Running `cabal update; cabal build` does indeed work, but this makes cabal pull alex and happy from Hackage, instead of using the nix provided one. (I can tell this because it explicitly says it is downloading, and it uses 3.2.6 from Hackage instead of 3.2.5 from nix for alex). Is there any way to get nix to properly provide alex/happy in a way that cabal recognizes, instead of using Hackage? (Your first paragraph seems to imply that there unfortunately isn't :( ) – CH. Dec 15 '20 at 16:51
  • 1
    That's a solvable problem. You'd have to figure out how Cabal/cabal-install looks up build tools in the package db. With that info you could improve the package db generation in Nixpkgs. If that's not feasible, and I'd be surprised, you could even patch Cabal/cabal-install from within Nixpkgs. – Robert Hensing Dec 17 '20 at 09:27
  • Thanks for providing the direction, I'll try that out! – CH. Dec 17 '20 at 12:43
  • Did you find a solution to your problem? I know that the `v1-` set of commands works somewhat in these cases. However, now I am struggling with a benchmark using alex that does not work even with `v1-` commands. – Dominik Schrempf Sep 22 '22 at 07:02
  • 2
    For reference, there are tickets about this in the Nixpkgs issue list: https://github.com/NixOS/nixpkgs/issues/130556, and https://github.com/NixOS/nixpkgs/issues/176887. – Dominik Schrempf Sep 22 '22 at 10:22