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
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:
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.
HTH!
Edit: misread the OP and didn’t see ‘enable: false’, so most of my post is useless to that person. Sorry for the noise.
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 2.1.1.1)
Install exercism package (nix-env -i exercism)
Then exercism download --exercise=hello-world --track=haskell will download and install the data in /home/jlucas/exercism/haskell/hello-world.
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)
Next stack build works for me
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-4.12.0.0.
...
stm > Building library for stm-2.4.5.0..
...
stm > /run/user/1000/stack-a8a4ca0abf4d9831/stm-2.4.5.0/Control/Monad/STM.hs:34:9: error: Not in scope: ‘always’
...
stm > /run/user/1000/stack-a8a4ca0abf4d9831/stm-2.4.5.0/Control/Monad/STM.hs:35:9: error: Not in scope: ‘alwaysSucceeds’
...
-- While building package stm-2.4.5.0 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-2.4.0.1 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
At first, stack new helloworld, returned the error
Cannot determine project root directory for Docker sandbox.
Thus, in ~/.stack/config.yaml I disabled nix with
nix:
enable: false
and stack new helloworld worked
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
Thus, in ~/.stack/config.yaml I re-enabled nix :
nix:
enable: true
With that, stack build did work…
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.
What is weird is that the deprecation of always and alwaysSucceeds happened on v2.5.0.0 not v2.4.5.0. Citing the source code on top of Control/Monad/STM.hs from the stm package version 2.5.0
-- Note that invariant checking (namely the @always@ and @alwaysSucceeds@
-- functions) has been removed. See ticket [#14324](https://ghc.haskell.org/trac/ghc/ticket/14324) and
-- the [removal proposal](https://github.com/ghc-proposals/ghc-proposals/blob/d5f1dbb456d13d298902e8d27ede65ab47598695/proposals/0011-deprecate-stm-invariants.rst).
-- Existing users are encouraged to encapsulate their STM operations in safe
-- abstractions which can perform the invariant checking without help from the
-- runtime system.
I don’t use stack, so I am not able to help further.
Then exercism download --exercise=hello-world --track=haskell will download and install the data in /home/<user>/exercism/haskell/hello-world.
cd /home/<user>/exercism/haskell/hello-world
Write default.nix file in current directory
Run nix-shell --run ghcid
EDIT:
Actually you will need to run once something like stack test to build a hello-world.cabal file before last step. Sorry to forget to mention that.
Oh yea, I see what is happening. There is no .cabal file, because they use hpack. You need to generate the cabal file, so commands like ghcid and cabal work correctly. Do this:
Add hpack along side ghcid in your default.nix (there should be three packages in total: [cabal-install ghcid hpack]).
Run nix-shell --run "hpack && ghcid"
You can also use ghcid to automatically run the tests:
I did that from scratch. After nix-shell --run "hpack && ghcid" I got stuck with All good (2 modules, at 11:41:19) on top of a fully cleaned terminal; for unknown reason.
<interactive>:36:1-10: error:
Not in scope: ‘Tests.main’
No module named ‘Tests’ is imported.
...done
at the bottom. And, again, I’m stuck in this state.
In both cases I can write characters with the keyboard but pressing enter does nothing except going to a new line. Ctr+C is the only solution to escape this.
I cannot understand that it works on your system. The only reason I see would be that we have something that differs in our environment… But using nix-shell should prevent such a case.
I got stuck with All good (2 modules, at 11:41:19)
That means you succeeded (you didn’t get stuck). ghcid will say “All good” when the compilation succeeds (and it tried to compile 2 modules), and there are no errors.
No module named ‘Tests’ is imported.
Did you add module Tests where as the first line to the file test/Tests.hs, as indicated above?
It works ! Thank you so much. Sorry for the wrong error log, you were right, the line was missing. My bad.
Ok, I was really surprised that it did not return to the prompt after a success, but I guess that it must be a kind conventional behavior to see a rapid prompt.