2

I installed minimal edition of nixos on vm, and then install some pkgs like i3, firefox, code, ...

but when i want to install ghc compiler of haskell i encounter with a problem

i used ghcup from its offical site for installing haskell ecosystem it needs some requirement like python3, gcc ,...., i installed all of them,

I successfully instal the ghcup but when i want to install ghc this error happen:

checking for -ar ... no
checkinf for ar ... no
configure: error: cannot find ar in your PATH, no idea how to make a library

I installed some pkgs like binutils, but error still is there.

Sibi
  • 47,472
  • 16
  • 95
  • 163
xmoooz
  • 411
  • 5
  • 8
  • Extending on the reply from Sibi, newer versions of GHC from nixpkgs can be accessed via `nix-shell -p haskell.compiler.ghc922`. Depending on the version of nixpkgs available, you may have to fiddle with minor version. E.g. for NixOS 22.05 it may be `ghc921`. – Artem Pelenitsyn Jul 11 '22 at 21:24

1 Answers1

3

As of now ghcup doesn't work on NixOS. I did open an upstream issue related to that: https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/174

If you want ghc to be installed on Nix, you have couple of options:

  • Use the one supplied via nixpkgs:
❯ nix-shell -p ghc
❯ ghc --version                                                                                                                                                                                                                     
The Glorious Glasgow Haskell Compilation System, version 8.10.7

If you want a GHC version, which is not present in the nixpkgs you are using, you would have to use the revision set which has the appropriate version. There are couple of ways you can find it:

I have been mostly using the second method from above. Let's say I want GHC 8.10.4 and I can find the revision set from the search there. And once I have that, I create a shell.nix file like this:

let
  pkgs = import (builtins.fetchTarball {
    url =
      "https://github.com/NixOS/nixpkgs/archive/9986226d5182c368b7be1db1ab2f7488508b5a87.tar.gz";
  }) { };

in pkgs.stdenv.mkDerivation {
  name = "my-project";
  buildInputs = [ pkgs.zlib pkgs.ghc ];
}

And then you can do the following:

$ nix-shell -v
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.4

Note that you can use other techniques too apart from the nix-shell one that has been used above.

Sibi
  • 47,472
  • 16
  • 95
  • 163
  • Unfortunately the last two links seems to be quite outdated and do not contain recent ghc versions like 8.10.7, and I cannot find any specific ghc versions in the standard nixos package search. I personally always use something like `nix-shell -p haskell.compiler.ghc8107` (or `...ghc921`), but I have no idea where you can find a list of all available versions in that form. – Noughtmare Jan 03 '22 at 09:32
  • 1
    @Noughtmare Seems the second link has stopped updating and there is an open issue: https://github.com/lazamar/nix-package-versions/issues/12 I guess it would be nice to know how the third list was generated and to see if that can be updated through a CI job or something like that. – Sibi Jan 03 '22 at 09:44
  • And I would also like to mention that there are some upstream nix dervations that might contain more recent (and even development) versions of GHC: https://gitlab.haskell.org/bgamari/ghcs-nix and https://github.com/mpickering/ghc-artefact-nix. – Noughtmare Jan 03 '22 at 09:48
  • @Noughtmare That looks interesting, does it have list of different versions specified somewhere ? From my quick look on Ben's repo, I wasn't able to find any. (And the other one seems to be targeted towards GHC's head) – Sibi Jan 03 '22 at 11:01
  • The versions are listed [in the `default.nix` file](https://gitlab.haskell.org/bgamari/ghcs-nix/-/blob/014eaa52aad930cc5e8beb9b4c497b8b66408bc9/default.nix#L72-239) which is not that hard to read. – Noughtmare Jan 03 '22 at 11:05
  • Ah, okay. That is indeed much easier to read. – Sibi Jan 03 '22 at 11:13
  • @Noughtmare The second link has started working and that issue has been fixed by the author. – Sibi Jan 24 '22 at 03:00