Building ghcide? - Nix

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

Magnus Therning

I thought I'd try to build ghcide myself, and quite possibly use it to experiment a bit with cachix late on. The following is the expression I came up with.

- Is it a reasonable way of building these packages?
- Will I run into any issues later on if I mix this build of ghcide with expressions for building packages based on "plain nixpkgs"? (I think not, since the result is an executable, so quite possibly I won't even have to match pin shas I suspect.)

with (import <nixpkgs> {});

let
  ghc_ver = "ghc865";

  ghcide-0_0_4-src = builtins.fetchTarball {
    url = https://hackage.haskell.org/package/ghcide-0.0.4/ghcide-0.0.4.tar.gz;
  };

  haskell-lsp_0_17_0_0-src = builtins.fetchTarball {
    url = https://hackage.haskell.org/package/haskell-lsp-0.17.0.0/haskell-lsp-0.17.0.0.tar.gz;
  };

  haskell-lsp-types_0_17_0_0-src = builtins.fetchTarball {
    url = https://hackage.haskell.org/package/haskell-lsp-types-0.17.0.0/haskell-lsp-types-0.17.0.0.tar.gz;
  };

  lsp-test_0_8_0_0-src = builtins.fetchTarball {
    url = https://hackage.haskell.org/package/lsp-test-0.8.0.0/lsp-test-0.8.0.0.tar.gz;
  };

  myHaskellPackages = pkgs.haskell.packages.${ghc_ver}.override {
    overrides = self: super: rec {
      haskell-lsp = self.callCabal2nix "haskell-lsp" haskell-lsp_0_17_0_0-src {};
      haskell-lsp-types = self.callCabal2nix "haskell-lsp-types" haskell-lsp-types_0_17_0_0-src {};
      lsp-test = self.callCabal2nixWithOptions "lsp-test" lsp-test_0_8_0_0-src "--no-check" {};
      ghcide = self.callCabal2nixWithOptions "ghcide" ghcide-0_0_4-src "--no-check" {};
    };
  };

in {
  haskell-lsp_0_17_0_0 = myHaskellPackages.haskell-lsp;
  haskell-lsp-types_0_17_0_0 = myHaskellPackages.haskell-lsp-types;
  lsp-test_0_8_0_0 = myHaskellPackages.lsp-test;
  ghcide_0_0_4 = myHaskellPackages.ghcide;
}
Ben Kolera

You'll want callHackage

Magnus Therning

Nice, but as so often documentation is lacking :disappointed:

What is an AttrSet actually?

Magnus Therning

I'm guessing I have to use AttrSet to turn off checking, passing --no-check to `cabal2nix, it's just that I don't know at all how to do that.

Magnus Therning

I was thinking backwards... I don't want to pass in attrs, I want to run functions from haskell.lib on it. In the end it looks like this:

with (import <nixpkgs> {});

let
  hl = haskell.lib;

  ghc_ver = "ghc865";

  myHaskellPackages = pkgs.haskell.packages.${ghc_ver}.override {
    overrides = self: super: rec {
      haskell-lsp = self.callHackage "haskell-lsp" "0.17.0.0" {};
      haskell-lsp-types = self.callHackage "haskell-lsp-types" "0.17.0.0" {};
      lsp-test = hl.dontCheck (self.callHackage "lsp-test" "0.8.0.0" {});
      ghcide = hl.dontCheck (self.callHackage "ghcide" "0.0.4" {});
    };
  };

in {
  haskell-lsp_0_17_0_0 = myHaskellPackages.haskell-lsp;
  haskell-lsp-types_0_17_0_0 = myHaskellPackages.haskell-lsp-types;
  lsp-test_0_8_0_0 = myHaskellPackages.lsp-test;
  ghcide_0_0_4 = myHaskellPackages.ghcide;
}
Magnus Therning

In the code above I explicitly set the ghc version to be used. Is there some variable in nixpkgs that already holds the correct value for the "current" ghc version?

Ben Kolera

pkgs.haskellPackages

Ben Kolera

Oh, an attrSet is basically just a dictionary / record in nix.

Ben Kolera

Use pkgs.haskell.lib.dontCheck function to add the dont-check to a haskell derivation.

Magnus Therning

@Ben Kolera What about pkgs.haskellPackages?

Ben Kolera

That's the concept of the latest Haskell package set.

Magnus Therning

Yes.. I know.

I found a solution, a bit of a hack really, to the question about getting the GHC version in that specific format:

ghcver = builtins.replaceStrings ["-" "."] ["" ""] pkgs.ghc.name;