简体   繁体   中英

“ghc-cabal: No such file or directory” error while building Haskell Stack example in NixOS

A) I'm trying to create a Haskell project i) with Stack, ii) on NixOS (channels/nixos-18.03). While following the HelloWorld example in the user guide, to build the project, I get the error ghc-cabal: No such file or directory .

$ stack new helloworld new-template
$ cd helloworld
$ sudo stack build
...
Running /run/current-system/sw/bin/make install in directory /root/.stack/programs/x86_64-linux/ghc-8.6.4.temp/ghc-8.6.4/ exited with ExitFailure 2
...
utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist: line 3: /root/.stack/programs/x86_64-linux/ghc-8.6.4.temp/ghc-8.6.4/utils/ghc-cabal/dist-install/build/tmp/ghc-cabal: No such file or directory
make[1]: *** [ghc.mk:990: install_packages] Error 127
make: *** [Makefile:51: install] Error 2

Error: Error encountered while installing GHC with
         make install
         run in /root/.stack/programs/x86_64-linux/ghc-8.6.4.temp/ghc-8.6.4/

       The following directories may now contain files, but won't be used by stack:
         - /root/.stack/programs/x86_64-linux/ghc-8.6.4.temp/
         - /root/.stack/programs/x86_64-linux/ghc-8.6.4/

B) Iteratively, I've built up my /etc/nixos/configuration.nix file to look like this. And in the resulting system, indeed there's no ghc-cabal binary. There's cabal , but no ghc-cabal .

  environment.systemPackages = with pkgs; [
    wget vim emacs
    pkgs.firefoxWrapper pkgs.chromium

    stack
    haskellPackages.ghc
    haskellPackages.cabal-install
    haskellPackages.cabal2nix
    haskellPackages.hdevtools

    tree gnumake which binutils gcc clang coreutils gnutar
    tmux silver-searcher gitAndTools.gitFull
  ];

C) I've also followed the steps in Stack's Nix Integration section. But to no avail.

What package installs ghc-cabal ? Is there a mismatch between stack and haskellPackages.cabal-install ? What am I missing?

EDIT

I did a bit of digging around and came across some useful resources. In particular, this article points out that my problem could be caused by an unresolved dynamic library.

Indeed when querying the loaded libraries for that binary, I get the result below.

$ ldd ~/.stack/programs/x86_64-linux/ghc-8.6.4.temp/ghc-8.6.4/utils/ghc-cabal/dist-install/build/tmp/ghc-cabal
    linux-vdso.so.1 (0x00007fff0ab01000)
    libm.so.6 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libm.so.6 (0x00007fe82c07f000)
    libHSCabal-2.4.0.1-ghc8.6.4.so => not found
    libHSprocess-1.6.5.0-ghc8.6.4.so => not found
    libHSpretty-1.1.3.6-ghc8.6.4.so => not found
    libHSparsec-3.1.13.0-ghc8.6.4.so => not found
    libHStext-1.2.3.1-ghc8.6.4.so => not found
    libHSmtl-2.2.2-ghc8.6.4.so => not found
    libHStransformers-0.5.6.2-ghc8.6.4.so => not found
    libHSdirectory-1.3.3.0-ghc8.6.4.so => not found
    libHSunix-2.7.2.2-ghc8.6.4.so => not found
    libHStime-1.8.0.2-ghc8.6.4.so => not found
    libHSfilepath-1.4.2.1-ghc8.6.4.so => not found
    libHSbinary-0.8.6.0-ghc8.6.4.so => not found
    libHScontainers-0.6.0.1-ghc8.6.4.so => not found
    libHSbytestring-0.10.8.2-ghc8.6.4.so => not found
    libHSdeepseq-1.4.4.0-ghc8.6.4.so => not found
    libHSarray-0.5.3.0-ghc8.6.4.so => not found
    libHSbase-4.12.0.0-ghc8.6.4.so => not found
    libHSinteger-gmp-1.0.2.0-ghc8.6.4.so => not found
    libHSghc-prim-0.5.3-ghc8.6.4.so => not found
    libHSrts-ghc8.6.4.so => not found
    libffi.so.7 => not found
    librt.so.1 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/librt.so.1 (0x00007fe82c06d000)
    libutil.so.1 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libutil.so.1 (0x00007fe82c068000)
    libdl.so.2 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libdl.so.2 (0x00007fe82c063000)
    libpthread.so.0 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libpthread.so.0 (0x00007fe82c042000)
    libgmp.so.10 => not found
    libc.so.6 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libc.so.6 (0x00007fe82be8a000)
    /lib64/ld-linux-x86-64.so.2 => /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib64/ld-linux-x86-64.so.2 (0x00007fe82c219000)

I tried resolving the missing libs, by adding haskellPackages.stdio and haskellPackages.stdf to configuration.nix. But further upstream errors spring from that (ex: I can't add aeson as an environment.systemPackages dependency). So I haven't gotten the right mix yet.

CallStack (from HasCallStack):
  die', called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:950:20 in Cabal-2.4.0.1:Distribution.Simple.Configure
  configureFinalizedPackage, called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:460:12 in Cabal-2.4.0.1:Distribution.Simple.Configure
  configure, called at libraries/Cabal/Cabal/Distribution/Simple.hs:596:20 in Cabal-2.4.0.1:Distribution.Simple
  confHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:67:5 in Cabal-2.4.0.1:Distribution.Simple.UserHooks
  configureAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:178:19 in Cabal-2.4.0.1:Distribution.Simple
  defaultMainHelper, called at libraries/Cabal/Cabal/Distribution/Simple.hs:115:27 in Cabal-2.4.0.1:Distribution.Simple
  defaultMain, called at Setup.hs:2:8 in main:Main
Setup: Encountered missing dependencies:
aeson ==0.8.*, base ==4.7.*, binary ==0.7.*, text ==1.1.*

ghc-cabal is an artifact in ghc's build, included in ghc binary distributions:

$ ls -l  ~/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.3.tar.xz
-rw-rw-r--. 1 user group 182356948 Dec 25 15:11 ghc-tinfo6-8.6.3.tar.xz
$ tar tvf ~/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.3.tar.xz | grep tmp/ghc-cabal
-rwxr-xr-x ghc/ghc      225936 2018-12-08 00:03 ghc-8.6.3/utils/ghc-cabal/dist-install/build/tmp/ghc-cabal
-rwxr-xr-x ghc/ghc         858 2018-12-08 00:03 ghc-8.6.3/utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist

So I solved this with the help of Kirill Zaborsky in a commercialhaskell/stack issues thread . The cause of the error (in stack new and stack build ) was an old Stack version. Specifically, my local user had an older stack ( 1.6.5 ) than root ( 1.9.3 ).

Version 1.6.5 uses Cabal-2.0 , and since then new features were introduced by Cabal (ex base-noprelude ) use leading commas, implemented in haskell/cabal#4953 which came with 2.2. So Stack fails parsing cabal files using the new format features.

Details are in the commercialhaskell/stack issues thread . And upgrading my local user's stack ( nix-env --upgrade stack ) fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM