can't install ghc in nixos

1.1k Views Asked by At

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.

1

There are 1 best solutions below

7
On

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.