Haskell-stack build fails

Hi all,

I’m having some difficulties to build the “hello world” project of exercism.io, the first haskell exercise.

This project uses stack and the log of the build displays many lines with
Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.3: The program 'ar' is required but it could not be found.

I wonder if it’s because of my customized stack.yaml

system-ghc: true
enable: false
resolver: lts-12.4

Since it’s my first post, I really would like to thank all the people working on NixOS. I do enjoy using it.

Hi @jojo,

I’m not sure exactly what problem you’re facing, but it would be very helpful for me (and others who might come across this question), if you could give a detailed explanation of the exact code you’re trying to build, the commands you’re trying to run, the full output, etc. Also, if you could link to a single repo (on Github) where you can reproduce the problem, that would be very helpful.

Here’s a couple links that explain how to create a minimal reproducible example:

There are lots of people successfully using stack on NixOS, so I’m hopeful that we will be able to find a solution to your problem!

I’m mobile now but may be able to give enough direction:

I have been working on Exercism’s Haskell Problems recently and ran into exactly the same problem. IIRC I wound up needing to set a ‘compiler’ key in the stack.yaml to reflect the then-current version of GHC versus what appears in Stack’s resolver.

You can look that up with some variation of ‘nix-env -QAPA pkgs.ghc.compiler’ but I’ve almost certainly got the attribute path wrong in the final argument there.

There is a different stack.yaml key that is visible in the stack docs that allows the compiler to be newer than what was specified in the resolver by patch-level only, but I didn’t see an improvement the last time I tried it.


Edit: misread the OP and didn’t see ‘enable: false’, so most of my post is useless to that person. Sorry for the noise.

Thanks for the quick answers and sorry to be late.

@shanesveller : I found that enable: false was necessary to avoid error: attribute 'ghc843' missing, at (string):1:43 but I don’t need to stick to it.

As you suggested, I removed it and I added compiler : ghc-8.6.5, since my last system ghc is the 8.6.5 version. My stack.yaml is now

compiler: ghc-8.6.5
resolver: lts-12.4

Building the project with stack seemed to work a bit better :slight_smile:

Now I have another bug :

--  While building package stm- using:
      /home/jlucas/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal- build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
Progress 14/18

@cdepillabout Ok, I will try to make a reproducible example if I cannot overcome the new issue. Thanks for the links.

Since I’m still stuck, here is a detailed explanation of what I did.
(I’m on NixOS 19.03, I use ghc-8.6.5 and stack

  1. Install exercism package (nix-env -i exercism)
  2. Then exercism download --exercise=hello-world --track=haskell will download and install the data in /home/jlucas/exercism/haskell/hello-world.
  3. After cd /home/jlucas/exercism/haskell/hello-world, in the file ./stack.yaml, I added compiler: ghc-8.6.5 (or whatever is your system version I guess)
  4. Next stack build works for me
  5. But stack test returns the next error log (I only pasted relevant lines)
WARNING: Ignoring stm's bounds on base (>=4.3 && <4.12); using base-
stm        > Building library for stm-
stm        > /run/user/1000/stack-a8a4ca0abf4d9831/stm- error: Not in scope: ‘always’
stm        > /run/user/1000/stack-a8a4ca0abf4d9831/stm- error: Not in scope: ‘alwaysSucceeds’
--  While building package stm- using:
      /home/jlucas/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal- build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
Progress 14/18

The error seems to be caused by the test dependency, stm, that cannot be built, isn’t it ?

Just to check, I verified that I could create an empty stack project. from scratch, following the guide. Here is what I did

  1. At first, stack new helloworld, returned the error

    Cannot determine project root directory for Docker sandbox.
  2. Thus, in ~/.stack/config.yaml I disabled nix with

        enable: false

    and stack new helloworld worked

  3. Next, I did,

    cd helloworld
    stack build

    The last command returned the error:

    I don't know how to install GHC on your system configuration, please install manually
  4. Thus, in ~/.stack/config.yaml I re-enabled nix :

      enable: true

    With that, stack build did work… :thinking: :laughing:

  5. stack test also worked.
    Thus, at the end, I was able to build a full project from scratch. What was surprising is that I had to first disable nix to create the project, then to enable nix to build and test the project.