input-output-hk / haskell.nix

Alternative Haskell Infrastructure for Nixpkgs
https://input-output-hk.github.io/haskell.nix
Apache License 2.0
559 stars 238 forks source link

No clean way of adding non-Hackage and non-Stackage Haskell dependencies #1349

Closed L-as closed 2 years ago

L-as commented 2 years ago

See #1339.

That PR is an attempt to enable this functionality, however, it's a hack, just like the package: ${pkg} approach @angerman proposes. Like @michaelpj wrote, we want a clean way of being able to include external dependencies, perhaps something like the following:

{
  pkg-def-extras = hackage: {
     myPackage = callCabalToNix ./myPackage.cabal;
  };
}

This is also relevant for #1262.

michaelpj commented 2 years ago

Can you explain why source-repository-package doesn't do what you want?

L-as commented 2 years ago

source-repository-package doesn't allow anything not fetchable by Cabal, i.e.

In addition, it's a pain, and not easy to manage when you essentially need to have your own package index. E.g. in the Plutus ecosystem we do the whole copying cabal.project thing because we need to make sure we use the same version of e.g. cardano-prelude as upstream. This is all a huge PITA.

michaelpj commented 2 years ago

These are all problems with Cabal, rather than haskell.nix IMO.

E.g. in the Plutus ecosystem we do the whole copying cabal.project thing because we need to make sure we use the same version of e.g. cardano-prelude as upstream. This is all a huge PITA.

The correct solution is for us to stop using a massive web of source-repository-packages and instead use a proper package repository, either Hackage or an internal one. Again, not a haskell.nix problem IMO.

angerman commented 2 years ago

an internal one

😬 This would become one... but we should know in a few days, thanks to https://github.com/input-output-hk/hackage-overlay-ghcjs

L-as commented 2 years ago

I don't see how such a package repository would work without something like hackage.nix specialised to it.

angerman commented 2 years ago

@L-as i share similar concerns. The storage backing is different though. I'll see over the next few days.

L-as commented 2 years ago

I am a Nix zealot, so I am quite biased, but I imagine you could define the repository in pure Nix, such that it works (only) with exactDeps = true;.

L-as commented 2 years ago

@michaelpj This is another issue with source-repository-package: exactDeps doesn't work with it unless you don't have it in the shell and only while building the shell.

michaelpj commented 2 years ago

I am a Nix zealot, so I am quite biased, but I imagine you could define the repository in pure Nix

IMO haskell.nix is a project for Nix-ifying cabal projects, not a fancy Nix-based Haskell builder that goes beyond cabal.

L-as commented 2 years ago

I don't think that's just your opinion, that's the state of haskell.nix. I do concede that what I ultimately want is not haskell.nix, but something much more lightweight that rather than emulating what Cabal does and make it reproducible, presents a different Nix-native workflow, like I told you in London, however, I still believe that exposing the ability to use a custom Hackage essentially would not be very hard, and now that I think about it, it's probably the approach I should be going for.

angerman commented 2 years ago

Allowing custom hackage repos is certainly something I wish we already had. It's also the way cabal handles this.

Why do we focus so much on cabal? Because that's our ground truth. We don't (and can't: Windows, BSD, ...) force everyone to use nix, this the repos should work fine without.

But we do want nix in CI and for cross compilation, and ...

So if it can be expressed in cabal, Haskell.nix should just take it.

It's the same reason why cabal.project.local is my preferred interface when possible. It's the same strategy the cabal uses. And it ensures we get the same behavior.

One thing where Haskell.nix deviates from cabal is that we don't support multiple plans well. Hence the nonReinstallabaldPkgs madness :-(

michaelpj commented 2 years ago

Custom hackages already work, you just have to make them yourself: https://github.com/input-output-hk/haskell.nix/pull/535

angerman commented 2 years ago

Ohh I completely forgot about that PR! 🤦‍♂️

brainrake commented 2 years ago

Here is a prototype for using extra-hackages and extra-hackage-tarballs to add dependencies by path. https://github.com/mlabs-haskell/haskell-nix-extra-hackage/tree/0a1061b6a9da11da045c543f13ce32af9897ac74 Possible additions to haskell.nix worth considering:

L-as commented 2 years ago

@angerman @michaelpj Forgot to note this, but do note that pkg-def-extras can not be used for this, as it doesn't effect plan generation, hence the IFD will fail and complain that the packages are unknown, and no plan will be generated.

L-as commented 2 years ago

We had some issues with the above too, due to implicit ordering of hackages based on their names, which lead to Hackage taking precedence over the custom Hackage, meaning the compact-map IOG package couldn't be used, until we switched the names internally.

michaelpj commented 2 years ago

We have a working prototype of using a custom Hackage inside IOG. It's just a matter of getting buy-in and doing it now.

L-as commented 2 years ago

@michaelpj That would really be great. Do you plan to do something like the hackage.nix repo or something else?

L-as commented 2 years ago

Also, I think we can remove pkg-def-extras, since it has no use AFAICT?

michaelpj commented 2 years ago

Do you plan to do something like the hackage.nix repo or something else?

Better than that: the cabal repo itself is in a git repository, so you just pull it in as a flake input and do hackage-to-nix to it on the fly, so it's even simpler.

ilyakooo0 commented 2 years ago

For the sake of completeness: I solved a similar problem here: https://github.com/ilyakooo0/haskell-nix-extra-hackage

brainrake commented 2 years ago

version with separate hackage per package, to reduce rebuilds https://github.com/mlabs-haskell/haskell-nix-extra-hackage/tree/separate-hackages