input-output-hk / haskell.nix

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

Unable to build hackage package derive-storable-plugin #879

Closed hhefesto closed 4 years ago

hhefesto commented 4 years ago

Firstly, hello and thank you for your time on this. I really like haskell.nix: it has make a lot of things simpler. <3

To the business in hand: Currently unable to build derive-storable-plugin

Compile error:

src/Foreign/Storable/Generic/Plugin/Internal/Compile.hs:110:45: error:
    • Couldn't match type ‘ghci-8.8.4:GHCi.RemoteTypes.ForeignRef
                             ghci-8.8.4:GHCi.RemoteTypes.HValue’
                     with ‘ForeignRef a0’
      NB: ‘ForeignRef’
            is defined in ‘GHCi.RemoteTypes’ in package ‘ghci-8.8.4’
          ‘ghci-8.8.4:GHCi.RemoteTypes.ForeignRef’
            is defined in ‘GHCi.RemoteTypes’ in package ‘ghci-8.8.4’
      Expected type: ForeignRef a0
        Actual type: ghci-8.8.4:GHCi.RemoteTypes.ForeignHValue
    • In the first argument of ‘withForeignRef’, namely ‘foreign_hval’
      In the second argument of ‘($)’, namely
        ‘withForeignRef foreign_hval localRef’
      In a stmt of a 'do' block:
        hval <- liftIO $ withForeignRef foreign_hval localRef
    |
110 |     hval         <- liftIO $ withForeignRef foreign_hval localRef
    |                                             ^^^^^^^^^^^^

builder for '/nix/store/m65kr0fwh12ap1wb0dmmvfa35x0azhi4-derive-storable-plugin-lib-derive-storable-plugin-0.2.3.0.drv' failed with exit code 1

Warning worth noting:

Warning:
    This package indirectly depends on multiple versions of the same package. This is very likely to cause a compile failure.
      package ghc (ghc-8.8.4) requires ghci-8.8.4
      package derive-storable-plugin (derive-storable-plugin-0.2.3.0) requires ghci-8.8.4-Auiqaz0h7Fj7dVgubAzoqP

Got the same error trying to build another project with a local reference to this package in project.cabal

Successful ways of building this package:

On channel nixos-20.09:

git clone https://github.com/mkloczko/derive-storable-plugin.git
cd derive-storable-plugin
nix-shell -p haskell.compiler.ghc884 haskellPackages.Cabal_3_2_0_0 cabal-install --pure
cabal new-build

Was also able to build using a standard nix-shell provided by haskell.nix with cabal new-build

Was also able to build with nix-build using pkgs.haskellPackages.callPackage on the output of cabal2nix cabal://derive-storable-plugin-0.2.3.0 on channel nixos-20.03

Also tried with ghc865 and cabal 3.0.0.0 and with derive-storable-plugin-0.2.2.0 (channel nixos-20.03)

If I'm interpreting this right, hackage also marks it as healthy: https://matrix.hackage.haskell.org/#/package/derive-storable-plugin

Thanks!

hhefesto commented 4 years ago

Being able to override a haskell.nix haskell package would definitely be a nice workaround (https://github.com/input-output-hk/haskell.nix/issues/510). But seems to be that this isn't supported yet.

michaelpj commented 4 years ago

Generally, hackage packages should work with haskell.nix out of the box, so thanks for filing an issue. The GHC library is a bit of a pain for various reasons, unfortunately. You may need to set reinstallableLibGhc = true (like here). That's a bit obscure, I know, but it's often a remedy for weird issues with the GHC library.

Overriding a haskell.nix package with one from somewhere else is just not going to work, unfortunately. We build Haskell packages component-by-component, which e.g. the nixpkgs infrastructure doesn't, so things just won't line up.

hhefesto commented 4 years ago

setting reinstallableLibGhc = true worked!

I first ran into a weird problem were it misplaced the haskell alex package.

trace: Using latest index state for telomare!
trace: Using index-state: 2020-10-14T00:00:00Z for telomare
error: Neither the Haskell package set or the Nixpkgs package set contain the package: alex (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.

(use '--show-trace' to show detailed location information)

Which got fixed by specifying alex in our overlay (which I learned from you).

For completeness this is our working default.nix:

{ # Fetch the latest haskell.nix and import its default.nix
  haskellNix ? import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/ef6ca0f431fe3830c25cb2d185367245c1cce894.tar.gz") {}
  # haskellNix ? import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}

  # # For LLVM
  # , enableLLVMAssertions ? true # TODO: Fix

, compiler ? "ghc884"
}:
let
  # haskell.nix provides access to the nixpkgs pins which are used by our CI,
  # hence you will be more likely to get cache hits when using these.
  # But you can also just use your own, e.g. '<nixpkgs>'.
  nixpkgsSrc = haskellNix.sources.nixpkgs-2003;

  # haskell.nix provides some arguments to be passed to nixpkgs, including some
  # patches and also the haskell.nix functionality itself as an overlay.
  nixpkgsArgs = haskellNix.nixpkgsArgs;

  telomare_jumper = pkgs.stdenv.mkDerivation {
    name = "telomareJumper";
    src = ./cbits;
    buildInputs = [ pkgs.boehmgc ];
  };

  telomareOverlays = [ (self: super: {
    jumper = telomare_jumper;
    gc = self.boehmgc;
    llvm-config = self.llvm_9;
    alex = self.haskellPackages.alex;
  }) ];

  # import nixpkgs with overlays
  pkgs = (import nixpkgsSrc (nixpkgsArgs // { overlays = nixpkgsArgs.overlays ++ telomareOverlays;}));
in
pkgs.haskell-nix.cabalProject {
  src = pkgs.haskell-nix.cleanSourceHaskell {
    src = ./.;
    name = "telomare";
  };
  compiler-nix-name = compiler;
  pkg-def-extras = with pkgs.haskell.lib; [
     (hackage: {
       llvm-hs = hackage.llvm-hs."9.0.1".revisions.default;
       llvm-hs-pure = hackage.llvm-hs-pure."9.0.0".revisions.default;
     })
   ];
  # modules = [];
  modules = [
    { reinstallableLibGhc = true; }
  ];
}

the derive-storable-plugin reference is in the cabal file under the library's build-depends