reflex-platform icon indicating copy to clipboard operation
reflex-platform copied to clipboard

Can’t install specific version of haskell-language-server with reflex-platform

Open bradrn opened this issue 3 years ago • 4 comments

I have a project using reflex-platform with GHC 8.6.5. Therefore, this project requires haskell-language-server built with GHC 8.6.5. The haskell4nix documentation is very clear on how to install a specific version of HLS, and after looking around the reflex-platform source a bit, I managed to produce the following Nix expression:

{ system ? builtins.currentSystem }:
let config = {
  packageOverrides = pkgs: {
    haskell-language-server = pkgs.haskell-language-server.override { supportedGhcVersions = [ "865" ]; };
  };
}; in
(import ./reflex-platform { inherit system config; }).project ({ pkgs, ... }: {
# snip
})

Of course, I soon discovered that this doesn’t work: supplying config to ./reflex-platform only affects the expression resulting from the import, so installing HLS using nix-env -i haskell-language-server (inside nix-shell) still gets the wrong version, because it’s still looking in <nixpkgs>.

I then did some debugging with nix repl, and this produced the curious result that nixpkgs inside ./reflex-platform does not even appear to contain haskell-language-server:

$ nix repl
Welcome to Nix version 2.3.16. Type :? for help.

nix-repl> config = { packageOverrides = pkgs: { haskell-language-server = pkgs.haskell-language-server.override { supportedGhcVersions = [ "865" ]; }; }; }

nix-repl> system = builtins.currentSystem

nix-repl> rplat = import ./reflex-platform { inherit system config; }

nix-repl> rplat.nixpkgs.haskell-language-server
error: attribute 'haskell-language-server' missing, at (string):1:57

By contrast, it contained other packages I’d expect, for instance GCC:

nix-repl> rplat.nixpkgs.gcc
«derivation /nix/store/hhdqlmw9z0kmnhfcc48ng6bfd8ng4fy0-gcc-wrapper-9.3.0.drv»

And the global nixpkgs certainly contained HLS as expected:

nix-repl> (import <nixpkgs> {}).haskell-language-server
«derivation /nix/store/rg188igj8bscm9wml7riqyblyb2pdf0r-haskell-language-server-1.4.0.0.drv»

Furthermore, even if (import ./reflex-platform { inherit system config; }).nixpkgs were to contain HLS as expected, I’m not sure how I would even go about installing it within my Nix shell, given that said version of nixpkgs is accessible only within the function call in default.nix.

Thus I enquire: does there exist any way to install a specific version of HLS using reflex-platform? And if there is, could it please be added to the documentation? (I know it’s a beginner topic, but then again, HLS is likely one of the first things a beginner would want to install.)

bradrn avatar Oct 10 '21 13:10 bradrn

I then did some debugging with nix repl, and this produced the curious result that nixpkgs inside ./reflex-platform does not even appear to contain haskell-language-server:

IIRC the nixpkgs pinned down here had HLS in a different place than more recent nixpkgs.

so installing HLS using nix-env -i haskell-language-server (inside nix-shell) still gets the wrong version, because it’s still looking in <nixpkgs>.

I think you want to add shellToolOverrides to the body of project: https://github.com/reflex-frp/reflex-platform/blob/53ef944aa6dbe1620817bde451d01c65e435f08c/project/default.nix#L89-L92

Haven't tried supportedGhcVersions, but what worked for me was using the HLS from the ghc 8.6.5 package set (default for pinned nixpkgs is 8.10) and launching my editor inside nix-shell -A shells.ghc:

  shellToolOverrides = self: super: {
    inherit (pkgs.haskell.packages.ghc865) haskell-language-server;
  };

Thus I enquire: does there exist any way to install a specific version of HLS using reflex-platform?

The above method gives you the pinned nixpkgs's HLS which is 0.4.0.0. @fendor had a shot at using newer ones but I think it turned out to be complicated.

alexfmpe avatar Oct 10 '21 19:10 alexfmpe

IIRC the nixpkgs pinned down here had HLS in a different place than more recent nixpkgs.

Hmm, in that case do you know where it is?

I think you want to add shellToolOverrides to the body of project: https://github.com/reflex-frp/reflex-platform/blob/53ef944aa6dbe1620817bde451d01c65e435f08c/project/default.nix#L89-L92

I must have looked through that file about five times for a field like that, and still I managed to miss it — thanks for pointing this out! shellToolOverrides is indeed what I was looking for.

The above method gives you the pinned nixpkgs's HLS which is 0.4.0.0. @fendor had a shot at using newer ones but I think it turned out to be complicated.

In that case, I think I’ll leave this issue open. After all HLS is one of the most widely-used packages for Haskell development, and I think most people (including me) would prefer to use a newer version.

bradrn avatar Oct 11 '21 00:10 bradrn

Using this approach with nixpkgs 20.09:

shellToolOverrides = self: super: {
    inherit (pkgs.haskell.packages.ghc865) haskell-language-server;
  };

I get an error:

Unexpected usage error can't load .so/.DLL for: /nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib/librt.so (/nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib/librt.so: undefined symbol: __clock_nanosleep, version GLIBC_PRIVATE)

rubenmoor avatar Dec 29 '21 22:12 rubenmoor

If anyone else comes across this thread, I was able to get a haskell-language-server with the latest reflex-platform (1.1.1.0) (uses ghc 8.10.7 ) by doing the steps mentioned here (btw I'm not using obelisk): https://discourse.haskell.org/t/haskell-language-server-ghc-version-could-not-be-determined/5856/10

These are the steps in the link:

  • checkout haskell-language-server (I used the 1.8-release branch since that's the last version for ghc 8.10.7)
  • go into your reflex platform project nix-shell
  • cd into haskell language-server directory
  • run cabal install
  • configure your ide LSP settings to find the hls server executable at $HOME/.cabal/bin/haskell-language-server (the wrapper doesn’t work)

I think reflex-platform should provide an option to install hls. Nix could probably automate the cabal install manual step right?

iogrt avatar Aug 18 '23 17:08 iogrt