Fixing a Haskell package - Nix

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Magnus Therning

One of the reasons I started looking at Nix was to take advantage of pre-built haskell binaries, in particular ghcide.

Now it turns out ghcide is marked broken. I know what to do to fix it (set specific versions on two libs), but I don't know how to get it into a/my nixpkgs properly.

Any pointers!

Asad Saeeduddin

@Magnus Therning I generally get ghcide from https://github.com/hercules-ci/ghcide-nix

Nix installation for ghcide. Contribute to hercules-ci/ghcide-nix development by creating an account on GitHub.
Asad Saeeduddin

the general pattern is called "IFD" (import from derivation)

Asad Saeeduddin

instead of trying to get everything from nixpkgs, you have a Nix expression that evaluates to a derivation that downloads more Nix expressions, then import the result as a Nix expression

Magnus Therning

Yes, I get the idea, but find the instructions in that repo a bit lacking.. what do I put in my shell.nix to get ghcide in my shell?

Magnus Therning

I import it using something like

  ghcide-nix = import (builtins.fetchGit {
    name = "ghcide-nix";
    url = https://github.com/hercules-ci/ghcide-nix;
    rev = "4f3e98f211f34698805eb7a3c5f7b4361d97f541";
  }) {};
Magnus Therning

I tried just adding ghcide-nix to my list of packages to bring in:

  shell-pkgs = with haskellPackages;
    [cabal-install
     ghcid
     ghcide-nix
     ormolu];

but that resulted in an error I don't really know what to do with:

error: cannot coerce a set to a string, at /nix/store/3abw7pkjmf850s048q45i203vj9z3czd-nixpkgs-20.03pre203317.8bb98968edf/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:311:9
(use '--show-trace' to show detailed location information)

I'm guessing the added import isn't a derivation?

Rizary

I import it using something like

ghcide-nix = import (builtins.fetchGit {
name = "ghcide-nix";
url = https://github.com/hercules-ci/ghcide-nix;
rev = "4f3e98f211f34698805eb7a3c5f7b4361d97f541";
}) {};


ghcide-nix, is a set because you use {} at the end of import, while shell-pkgs, requires a list of string. So maybe you can find ghcide, inside the set of ghcide-nix?

Nix installation for ghcide. Contribute to hercules-ci/ghcide-nix development by creating an account on GitHub.
Magnus Therning

Ah, is that what the {} at the end does. I'll have to try it.

If someone would write a guide on how to do introspection in Nix I'd be very happy :grinning_face_with_smiling_eyes:

Magnus Therning

Without the {} I instead get

cannot coerce a function to a string, at /nix/store/3abw7pkjmf850s048q45i203vj9z3czd-nixpkgs-20.03pre203317.8bb98968edf/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:311:9
Magnus Therning

I'm lost :disappointed:

Jack Henahan

There's a function called unmarkBroken under haskell.lib. Example here: https://github.com/jhenahan/dotnix/blob/master/overlays/haskell.nix#L37

Nix config, finally version controlled. Contribute to jhenahan/dotnix development by creating an account on GitHub.
Jack Henahan

It looks like you'd want to put ghcide-nixpkgs.<some version> as listed here: https://github.com/hercules-ci/ghcide-nix/blob/master/nix/default.nix

Nix installation for ghcide. Contribute to hercules-ci/ghcide-nix development by creating an account on GitHub.
Jack Henahan

Like this one https://github.com/hercules-ci/ghcide-nix/blob/4f3e98f211f34698805eb7a3c5f7b4361d97f541/nix/default.nix#L27

Nix installation for ghcide. Contribute to hercules-ci/ghcide-nix development by creating an account on GitHub.
Jack Henahan

So ghcide-nix.ghcide-ghc865

Asad Saeeduddin

@Magnus Therning What @Jack Henahan said. The README has an example of how to access a derivation representing ghcide for ghc 8.6.5:

(import (builtins.fetchTarball "https://github.com/hercules-ci/ghcide-nix/tarball/master") {}).ghcide-ghc865
Magnus Therning

Yes, indeed. However, working that out of the source wasn't very easy at all.

Magnus Therning

I have to admit that, as an absolute beginner at Nix, I find that example completely impenetrable.

Jack Henahan

It absolutely is. I basically just recommend reading Nix Pills, reading the bits of the manual about the particular languages you use, and then stealing everything else from other people. Basically how I learned Emacs

Jack Henahan

Reading Matthew Bauer's blog helps, too (matthewbauer.us)

Magnus Therning

Already read Nix Pills, and the bits on Haskell in the Nix/Nixpkgs manual too. That didn't help much in working out how that particular derivation works though.

I just wish there was some description on how to work things out on my own, stuff like how to visualize a derivation (with some limit on depth) would help immensely when trying to understand something.

Rizary

I am sorry that I couldn't explain it in detail. But I think others have replied with the answer. Did you finally able to build it?

Magnus Therning

No worries, @Rizary, my frustrations is not at all due to a lack of help, so far you and the rest of the Nix community I've interacted with has been wonderfully helpful. My frustration comes more from my inability to work things out myself and having to ask so many questions.

Yes I did get it to build.