haskell.nix icon indicating copy to clipboard operation
haskell.nix copied to clipboard

build-tool-depends executables don't appear in shellFor

Open ocharles opened this issue 4 years ago • 23 comments

I want to use tasty-discover, which I have added to my .cabal file as:

  build-tool-depends: tasty-discover:tasty-discover

As described in https://github.com/input-output-hk/nix-tools/issues/95, this adds a build-tools entry in the cabal-to-nix expression, which is used in setup-builder.nix to form executableToolDepends. However, it doesn't propagate correctly into the shell produced with shellFor. For build-tool-depends to work, we need a tasty-discover entry in the ghc-pkg database that also has the tasty-discover executable. As things currently stand, there is no entry at all. We can use additional = pkgs: [ pkgs.tasty-discover ], but that will only add a tasty-discover to the package database as a library - no executables will get included.

ocharles avatar Sep 06 '20 16:09 ocharles

Related/dupe: https://github.com/input-output-hk/haskell.nix/issues/760 https://github.com/input-output-hk/haskell.nix/issues/231

michaelpj avatar Sep 07 '20 09:09 michaelpj

Ah, thanks!

ocharles avatar Sep 07 '20 10:09 ocharles

I think I know how to fix this now, thanks @ocharles.

rvl avatar Sep 08 '20 23:09 rvl

@rvl Oh, fantastic! Do you need any help with anything? Happy to test anything, if that helps!

ocharles avatar Sep 09 '20 14:09 ocharles

A similar issue seems to happen if your shell dependencies have build tool dependencies.

E.g., cardano-transactions has a test suite with a build tool dependency on cardano-tx, and when I try to create a shell on a cabal project that uses it, it errors with:

error: Neither the Haskell package set or the Nixpkgs package set contain the package: cardano-tx (build tool dependency).
If this is a system dependency:
You may need to augment the system package mapping in haskell.nix so that it can be found.
If this is a Haskell dependency:
If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix.

Not sure if the same thing happens on stack projects, but I would presume not considering that cardano-transactions uses stack.

JBetz avatar Sep 24 '20 16:09 JBetz

I spent a little bit of time looking at this.

Firstly, I noticed that we don't pass build-tools into the fake component that we use to create the wrapped GHC for shellFor. Easy enough to fix.

But then it still doesn't appear in the package db. It turns out that makeConfigFiles doesn't use build-tools at all. So... how does anything work? My guess is that the Setup.hs interface to cabal doesn't insist on build-tool-depends being in the package db, and so we get away with just providing the executable. But probably we should register them, I'm just not sure how right now.

michaelpj avatar Nov 12 '20 17:11 michaelpj

Yeah I don't think they should be registered in the same package db, especially if package DBs are to be per machine for cross. When you need a library, you usually need lots of information beyond the machine code (unfoldings for inlining, etc.) but for an executable dependency, one just needs to be able to run the thing, and being agnostic to how the sausage is made is probably better for sake of determinism / caching.

Ericson2314 avatar Dec 12 '20 15:12 Ericson2314

Yeah I don't think they should be registered in the same package db, especially if package DBs are to be per machine for cross.

Well, not having it in the package db confuses cabal, so I don't see how we can avoid it (if we want this usecase to work!).

As far as cross goes, obviously the build-tools should be in the native package db in the glorious future once we've got a separate native package db. Then I think there's no real problem with them being there.

michaelpj avatar Dec 14 '20 09:12 michaelpj

Note that this really isn't specific shellFor, but specific to v2 cabal. You can always use v1-* cabal commands to get the old behavior (see SolveExecutables in cabal code). I think a reason this is coming up recently is that cabal 3.4.0.0 made v2 the default.

The reason this is really difficult is that both Nixpkgs & haskell.nix use the Setup.hs method of configure / install, which doesn't install a .conf file for executable components. I'm not sure if it makes more sense to patch Cabal so Setup.hs method installs executables correctly, or try to switch to the new install method.

See Cabal comment for reference:

build-tools dependencies NB: Only include these dependencies if SolveExecutables is True. It might be false in the legacy solver codepath, in which case there won't be any record of an executable we need.

https://github.com/haskell/cabal/blob/master/cabal-install-solver/src/Distribution/Solver/Modular/IndexConversion.hs#L348-L357

matthewbauer avatar Jul 21 '21 03:07 matthewbauer

Thanks for digging into that!

Ericson2314 avatar Jul 21 '21 18:07 Ericson2314

As far as cross goes, obviously the build-tools should be in the native package db in the glorious future once we've got a separate native package db.

v2 cabal-install recently got a --package-db flag that an be used to specify additional package dbs, though I'm not sure if it can actually help with this issue. Here's the pr for refernece: https://github.com/haskell/cabal/pull/7676

fgaz avatar Feb 21 '22 14:02 fgaz

For the record, this is also an issue for llvm-hs, which needs the hsc2hs executable: https://github.com/llvm-hs/llvm-hs/blob/eda85a2bbe362a0b89df5adce0cb65e4e755eac5/llvm-hs/llvm-hs.cabal#L74.

tscholak avatar Mar 06 '22 22:03 tscholak

The latest state of this issue seems to be: https://github.com/input-output-hk/haskell.nix/issues/1367#issuecomment-1207454622

codygman avatar Aug 07 '22 17:08 codygman

No, I think that's unrelated. This isn't anything to do with source-repository-packages. This is specifically about how build-tool-depends works.

michaelpj avatar Aug 08 '22 11:08 michaelpj

It seems like this is a duplicate of #231?

L-as avatar Aug 08 '22 13:08 L-as

This one is more general, yes the other is a dupe.

michaelpj avatar Aug 08 '22 13:08 michaelpj

Is there any work that can be done to help solve this problem? We're trying to migrate to haskell.nix but this is a problem for us. We'd be happy to contribute fixes or consulting time to the issue.

parsonsmatt avatar Aug 29 '22 14:08 parsonsmatt

Is there any work that can be done to help solve this problem? We're trying to migrate to haskell.nix but this is a problem for us. We'd be happy to contribute fixes or consulting time to the issue.

I haven't been able to look into this yet, but I really hope you are able to push this front forward.

My primary selling point for haskell.nix has been "You can avoid knowing nix and just update your cabal.project/package.cabal file but get cross compilation, reproducibility, docker containers, etc". @parsonsmatt I see in your linked issue your team is wanting the same: Use cabal.project as a source of truth.

Partial cabal.project support breaks this sellling point. I hope to deep dive into this issue and figure out haskell.nix well enough to solve some of these problems myself in the future, but I have other high priority things blocking it sadly :cry:

ParetoOptimalDev avatar Aug 29 '22 19:08 ParetoOptimalDev