Skip to content

Cabal tries to rebuild build-tool-depends in Nix shells where they are already provided #8492

Closed
@lf-

Description

@lf-

Describe the bug

When I invoke cabal test, cabal tries to build hspec-discover. This is deeply mysterious to me, since it is listed in ghc-pkg dump | rg -C10 hspec-discover on account of Nix putting it there.

I think a possible cause is that that's just the library and not the executable, but the Nix infrastructure will dump the executable into the PATH if it's in build-tool-depends (cabal2nix will ensure this).

So I'm filing this bug because this means I can either have build-tools and have it do pointless work in a Nix shell (but notably not when Nix invokes the testsuite as part of a build, since it invokes it with ./Setup test), or have the build of tests fail outside a Nix shell.

To Reproduce

Clone https://github.com/lf-/cabal-build-tools-repro

co/cabal-repro - [main] » nix develop --extra-experimental-features "flakes nix-command" -c cabal v2-test  
warning: Using saved setting for 'allow-import-from-derivation = true' from ~/.local/share/nix/trusted-settings.json.
Resolving dependencies...
Build profile: -w ghc-9.2.4 -O1
In order, the following will be built (use -v for more details):
 - hspec-discover-2.10.6 (lib) (requires build)
 - hspec-discover-2.10.6 (exe:hspec-discover) (requires build)
 - sample-0.0.0 (test:test) (first run)
Starting     hspec-discover-2.10.6 (lib)
^C

Expected behavior

Cabal should not bother building hspec-discover since it exists in PATH due to Nix (I think it's possibly reason able to ignore the one on PATH if Nix wasn't what put it there).

System information

  • Operating system: archlinux with nix
    GHC version: 9.2.4
    Cabal version:
[jade@tail-bot cabal-repro]$ cabal --version
cabal-install version 3.6.2.0
compiled using version 3.6.3.0 of the Cabal library 

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions