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

Cannot build packages depending on ghc

Open rtimush opened this issue 6 years ago • 15 comments

Projects that have ghc as a dependency cannot be built (in my case it's a transitive dependency of polysemy-plugin).

I reproduced it by running stack new, adding default.nix and adding ghc to package.yaml, but probably the exact setup doesn't matter too much here.

The full log:

trace: Using index-state: 2019-10-20T00:00:00Z for alex
trace: Using index-state: 2019-10-20T00:00:00Z for happy
trace: Using index-state: 2019-10-20T00:00:00Z for hscolour
trace: Cleaning component source not supported for hpack package: foo-0.1.0.0
trace: Cleaning component source not supported for hpack package: foo-0.1.0.0
these derivations will be built:
  /nix/store/fknxgmw24l99i918cqqflka0yk60p2ck-foo-0.1.0.0-lib-foo.drv
  /nix/store/9vq9d1cyp2mm1n9i43ygv5i045lx12k0-foo-0.1.0.0-test-foo-test-config.drv
  /nix/store/ajj7kdi8w2b5000g0p6mfij970aswl5v-foo-0.1.0.0-test-foo-test-ghc-8.6.5.drv
  /nix/store/lcm3hc685xpi6pfycmxzjbzhwm500jp4-foo-0.1.0.0-test-foo-test.drv
building '/nix/store/fknxgmw24l99i918cqqflka0yk60p2ck-foo-0.1.0.0-lib-foo.drv'...
unpacking sources
unpacking source archive /nix/store/3psp7dkcqv8gv086kwgg70rxwndfnb1n-foo
source root is foo
patching sources
generated foo.cabal
configuring
Configure flags:
--prefix=/nix/store/psq6vxmvih9say0mkdh9scnpic4k3ksa-foo-0.1.0.0-lib-foo lib:foo --package-db=clear --package-db=/nix/store/jw6z9v1vbcnmr84jqk3i9mxw9i8cwkkj-foo-0.1.0.0-lib-foo-config/package.conf.d --exact-configuration --dependency=rts=rts --dependency=ghc-heap=ghc-heap-8.6.5 --dependency=ghc-prim=ghc-prim-0.5.3 --dependency=integer-gmp=integer-gmp-1.0.2.0 --dependency=base=base-4.12.0.0 --dependency=deepseq=deepseq-1.4.4.0 --dependency=array=array-0.5.3.0 --dependency=ghc-boot-th=ghc-boot-th-8.6.5 --dependency=pretty=pretty-1.1.3.6 --dependency=template-haskell=template-haskell-2.14.0.0 --dependency=ghc-boot=ghc-boot-8.6.5 --dependency=ghc=ghc-8.6.5 --dependency=Cabal=Cabal-2.4.0.1 --dependency=array=array-0.5.3.0 --dependency=binary=binary-0.8.6.0 --dependency=bytestring=bytestring-0.10.8.2 --dependency=containers=containers-0.6.0.1 --dependency=directory=directory-1.3.3.0 --dependency=filepath=filepath-1.4.2.1 --dependency=ghc-boot=ghc-boot-8.6.5 --dependency=ghc-compact=ghc-compact-0.1.0.0 --dependency=ghc-prim=ghc-prim-0.5.3 --dependency=hpc=hpc-0.6.0.3 --dependency=mtl=mtl-2.2.2 --dependency=parsec=parsec-3.1.13.0 --dependency=process=process-1.6.5.0 --dependency=text=text-1.2.3.1 --dependency=time=time-1.8.0.2 --dependency=transformers=transformers-0.5.6.2 --dependency=unix=unix-2.7.2.2 --dependency=xhtml=xhtml-3000.2.2.1 --with-ghc=ghc --with-ghc-pkg=ghc-pkg --with-hsc2hs=hsc2hs --with-gcc=cc --with-ld=ld --with-ar=ar --with-strip=strip --disable-executable-stripping --disable-library-stripping --disable-library-profiling --disable-executable-profiling --docdir=/nix/store/rsckmgij214amcd2fbhwmlnm6vrhr7wa-foo-0.1.0.0-lib-foo-doc/share/doc/foo
Configuring library for foo-0.1.0.0..
Warning: The flag --disable-executable-profiling is deprecated. Please use
--disable-profiling instead.
Error:
    The following packages are broken because other packages they depend on are missing. These broken packages must be rebuilt before they can be used.
installed package ghc-8.6.5 is broken due to missing package ghci-8.6.5, terminfo-0.4.1.2

builder for '/nix/store/fknxgmw24l99i918cqqflka0yk60p2ck-foo-0.1.0.0-lib-foo.drv' failed with exit code 1
cannot build derivation '/nix/store/9vq9d1cyp2mm1n9i43ygv5i045lx12k0-foo-0.1.0.0-test-foo-test-config.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/lcm3hc685xpi6pfycmxzjbzhwm500jp4-foo-0.1.0.0-test-foo-test.drv': 1 dependencies couldn't be built
error: build of '/nix/store/lcm3hc685xpi6pfycmxzjbzhwm500jp4-foo-0.1.0.0-test-foo-test.drv' failed

rtimush avatar Nov 11 '19 23:11 rtimush

It requires a recompilation but it usually works if you specify

{
  reinstallableLibGhc = true;
}

as a module.

considerate avatar Nov 12 '19 09:11 considerate

Thanks, this helped! Now my build fails because of ghc-tcplugins-extra imports from ghc, and I get the same failure if I add

 import TcPluginM ( FindResult(..) )

to one of my sources. The same project is built successfully with stack. Have you maybe also seen this before?

Full log
building '/nix/store/9frfqvc70crsgvnsyynxcpd1lgvjfl0c-git-ls-files.drv'...
trace: Using index-state: 2019-10-20T00:00:00Z for alex
trace: Using index-state: 2019-10-20T00:00:00Z for happy
trace: Using index-state: 2019-10-20T00:00:00Z for hscolour
trace: Cleaning component source not supported for hpack package: foo-0.1.0.0
trace: Cleaning component source not supported for hpack package: foo-0.1.0.0
these derivations will be built:
  /nix/store/d7hngzv1bzdb8ihz86i66484zgkl4b3h-foo-0.1.0.0-lib-foo.drv
  /nix/store/ddqsbgjjzy1q2c6dlkaricf72d99ggqy-foo-0.1.0.0-test-foo-test-config.drv
  /nix/store/mjg5mrgm3qw4v2r36bfhgj24bkzdws1q-foo-0.1.0.0-test-foo-test-ghc-8.6.5.drv
  /nix/store/p94s5hi6ggwfgdaffnn83fpk2hwgq23h-foo-0.1.0.0-test-foo-test.drv
building '/nix/store/d7hngzv1bzdb8ihz86i66484zgkl4b3h-foo-0.1.0.0-lib-foo.drv'...
unpacking sources
unpacking source archive /nix/store/hv95ijnqzgrn3mxmd3fh5541i8nf3hp9-foo
source root is foo
patching sources
generated foo.cabal
configuring
Configure flags:
--prefix=/nix/store/ib1nich455gpf05hy3p7qkkzyirp2ac0-foo-0.1.0.0-lib-foo lib:foo --package-db=clear --package-db=/nix/store/bcii13rxwffb4xfji0g6crz8l0i0g9w6-foo-0.1.0.0-lib-foo-config/package.conf.d --exact-configuration --dependency=ghc=ghc-8.6.5-HvYRTommLnF4kf1hWuE8GL --dependency=rts=rts --dependency=ghc-heap=ghc-heap-8.6.5 --dependency=ghc-prim=ghc-prim-0.5.3 --dependency=integer-gmp=integer-gmp-1.0.2.0 --dependency=base=base-4.12.0.0 --dependency=deepseq=deepseq-1.4.4.0 --dependency=array=array-0.5.3.0 --dependency=ghc-boot-th=ghc-boot-th-8.6.5 --dependency=pretty=pretty-1.1.3.6 --dependency=template-haskell=template-haskell-2.14.0.0 --with-ghc=ghc --with-ghc-pkg=ghc-pkg --with-hsc2hs=hsc2hs --with-gcc=cc --with-ld=ld --with-ar=ar --with-strip=strip --disable-executable-stripping --disable-library-stripping --disable-library-profiling --disable-executable-profiling --docdir=/nix/store/agb7a181hvwpsavwc9kjn0q14ma4lmgy-foo-0.1.0.0-lib-foo-doc/share/doc/foo
Configuring library for foo-0.1.0.0..
Warning: The flag --disable-executable-profiling is deprecated. Please use
--disable-profiling instead.
building
Preprocessing library for foo-0.1.0.0..
Building library for foo-0.1.0.0..
[1 of 2] Compiling Lib              ( src/Lib.hs, dist/build/Lib.o )

src/Lib.hs:5:51: error: Module ‘TcPluginM’ does not export ‘FindResult(..)’ | 5 | import TcPluginM ( FindResult(..)) | ^^^^^^^^^^^^^^ [2 of 2] Compiling Paths_foo ( dist/build/autogen/Paths_foo.hs, dist/build/Paths_foo.o ) builder for '/nix/store/d7hngzv1bzdb8ihz86i66484zgkl4b3h-foo-0.1.0.0-lib-foo.drv' failed with exit code 1 cannot build derivation '/nix/store/ddqsbgjjzy1q2c6dlkaricf72d99ggqy-foo-0.1.0.0-test-foo-test-config.drv': 1 dependencies couldn't be built cannot build derivation '/nix/store/p94s5hi6ggwfgdaffnn83fpk2hwgq23h-foo-0.1.0.0-test-foo-test.drv': 1 dependencies couldn't be built error: build of '/nix/store/p94s5hi6ggwfgdaffnn83fpk2hwgq23h-foo-0.1.0.0-test-foo-test.drv' failed

rtimush avatar Nov 12 '19 11:11 rtimush

Fixed by removing #if defined(GHCI) from TcPluginM.hs with the following patch: https://gist.github.com/rtimush/fd56b980b45fe5fed7926f4f77a350ce

I will keep this issue open in case you want to include the patch by default, for me the problem has been resolved.

rtimush avatar Nov 13 '19 23:11 rtimush

@rtimush interesting. So we fail to build lib:ghc with -DGHCI

I guess you could alternatively do

{
  packages.ghc.ghc-options = "-DGHCI";
}

or

{
  packages.ghc.flags.ghci = true;
}

the more confusing part though is that I thought we already removed all the GHCI def checks from ghc. Maybe that only ended up in 8.8? That's definetly worth an invesitgation.

angerman avatar Nov 14 '19 02:11 angerman

At least in head there is no GHCI ifdef anymore:

https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/typecheck/TcPluginM.hs

angerman avatar Nov 14 '19 02:11 angerman

@angerman I first tried packages.ghc.flags.ghci, but then it tried to build ghci and failed. Haven't tried with ghc-options. As far as I can see, the condition is indeed not there anymore in master, but is still present in the 8.6 and 8.8 ghc branches.

rtimush avatar Nov 14 '19 07:11 rtimush

We also experience this with ghcide-nix. I've tried it with haskell.nix master, but the ghc isn't right. I've tried both with and without reinstallable libghc. It does build without ghci but that's not usable in practice (https://github.com/hercules-ci/ghcide-nix/pull/18#issuecomment-555127101)


              reinstallableLibGhc = true;
              packages.ghc.flags.ghci = pkgs.lib.mkForce true;

results in /nix/store/b1pgdflmgrlw3vqbcl6wh43yggg5nbjp-ghc-8.6.5-lib-ghc.drv failing with:

[313 of 492] Compiling GHCi             ( ghci/GHCi.hs, dist/build/GHCi.o )

ghci/GHCi.hs:53:1: error:
    Could not find module ‘GHCi.Run’
    Use -v to see a list of the files searched for.
   |
53 | import GHCi.Run
   | ^^^^^^^^^^^^^^^

whereas without reinstallableLibGhc we get

-disable-library-profiling --disable-executable-profiling --docdir=/nix/store/7bh4wn1dq1qggrpb20j1pfpihy17g1ly-hie-bios-0.2.0-lib-hie-bios-doc/share/doc/hie-bios --enable-split-sections 
  Configuring library for hie-bios-0.2.0..
  Warning: The flag --disable-executable-profiling is deprecated. Please use
  --disable-profiling instead.
  Error:
      The following packages are broken because other packages they depend on are missing. These broken packages must be rebuilt before they can be used.
  installed package ghc-8.6.5 is broken due to missing package terminfo-0.4.1.2
error: build of '/nix/store/dfysyqpccb2cj49cm4a851jyj4k5rn1g-hie-bios-0.2.0-lib-hie-bios.drv' failed

roberth avatar Nov 26 '19 20:11 roberth

@roberth the first issue with lib-ghc failing sounds like the the ghci-flag is not picked up correctly. That is rather confusing. Do you happen to have the full log for /nix/store/b1pgdflmgrlw3vqbcl6wh43yggg5nbjp-ghc-8.6.5-lib-ghc.drv?

angerman avatar Nov 27 '19 01:11 angerman

The following change seems to have resolved the issue @roberth has been seeing:

packages.ghc.flags.ghci = pkgs.lib.mkForce true;
packages.ghci.flags.ghci = pkgs.lib.mkForce true;

angerman avatar Nov 28 '19 01:11 angerman

The following change seems to have resolved the issue @roberth has been seeing:

packages.ghc.flags.ghci = pkgs.lib.mkForce true;
packages.ghci.flags.ghci = pkgs.lib.mkForce true;

I was able to fix libiserv breakage in a cross-compiling build by adding to my module inputs to stackProject, though I simply wrote true and didn't need the mkForce

eamsden avatar Dec 17 '19 22:12 eamsden

I've bumped into the same problem in a cross-compiling build as well (GHC 8.6.5), but I had to add the following flag to make it work: packages.libiserv.flags = { network = true; }; Hope it can help!

michivi avatar Feb 06 '20 06:02 michivi

I'm also having trouble with polysemy-plugin and cleff-plugin. Could somebody clarify where reinstallableLibGhc = true is supposed to go? I added it to default.nix and got error: The option 'reinstallableLibGhc' does not exist.

goertzenator avatar Apr 20 '22 18:04 goertzenator

error: The option 'reinstallableLibGhc' does not exist.

That is odd. How did you pass it? It needs to be in the modules argument for the project. So normally that means something like this:

modules = [{ reinstallableLibGhc = true; }];

hamishmack avatar Apr 21 '22 01:04 hamishmack

Thanks, that was the hint I needed. I had it one level up alongside the src property. (I am still learning this stuff).

goertzenator avatar Apr 21 '22 19:04 goertzenator

I am going to close this as reinstallableLibGhc is now the default and I think that should clear up most of the issues discussed here.

hamishmack avatar Sep 20 '22 10:09 hamishmack