Skip to content

How to have a properly setup haskell-language-server in nix-shell? #1012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abailly opened this issue Jan 21, 2021 · 13 comments
Closed

How to have a properly setup haskell-language-server in nix-shell? #1012

abailly opened this issue Jan 21, 2021 · 13 comments

Comments

@abailly
Copy link
Contributor

abailly commented Jan 21, 2021

Disclaimer: I am a total noob when it comes to nix + Haskell setup.

In order to learn how to use nix with Haskell, I have tried adding nix configuration to an existing simple package: https://github.com/abailly/hydra-sim/blob/master/shell.nix following the tutorial here: https://input-output-hk.github.io/haskell.nix/tutorials/getting-started/
After some fiddling I managed to have nix-build building the package, and nix-shell dropping me into a properly configured shell. However, I am struggling with configuration of haskell-language-server, more specifically to get the correct version which should be HLS for 8.10.2 (the compile version defined in default.nix).
I have tried to configure it following https://haskell4nix.readthedocs.io/nixpkgs-users-guide.html?highlight=language%20server#how-to-install-haskell-language-server with some adaptation:

    buildInputs = with pkgs.haskellPackages;
      [ ghcid
        haskell-language-server.override { supportedGhcVersions = [ "8102" ]; }
      ];

but to no avail. What am I missing?

@rvl
Copy link
Contributor

rvl commented Jan 22, 2021

The haskell4nix docs apply to the standard nixpkgs Haskell infrastructure, and not Haskell.nix.

Add haskell-language-server = "0.8.0"; to the shellFor tools attrset.
It will use the ghc version matching the project.

@abailly
Copy link
Contributor Author

abailly commented Jan 22, 2021

Thanks a lot @rvl! Did I miss something in the documentation I should have paid more attention to? Is there a way to know which tools are available? I am happy to help on proposing a documentation PR if this can help someone else.

@rvl
Copy link
Contributor

rvl commented Jan 22, 2021

tools is a shortcut way of getting the executable from any package on hackage (plus a few special ones like haskell-language-server).

There is a shellFor reference here: https://input-output-hk.github.io/haskell.nix/reference/library/#shellfor, but more user-guide-type documentation might help.

@abailly
Copy link
Contributor Author

abailly commented Jan 22, 2021

plus a few special ones like haskell-language-server

That's probably the part which might cause confusion to unwary users like myself. Is there a place that could be linked to listing those special packages?

@hamishmack
Copy link
Collaborator

That's probably the part which might cause confusion to unwary users like myself. Is there a place that could be linked to listing those special packages?

Only custom-tools are haskell-language-server and an old branch of ghcide that we should really remove. I don't think we want to add more of these, better just to make sure things are put in hackage.

@abailly
Copy link
Contributor Author

abailly commented Jan 24, 2021

OK. One last snag I am hitting is that haskell-language-server-wrapper is not installed as part of the haskell-language-server installation. Am I missing something? The hls-wrapper is needed for proper IDE (Emacs in my case) integration.

@hamishmack
Copy link
Collaborator

Added #1015 to fix the -wrapper issue. Also haskell-language-server is in hackage now!

@abailly
Copy link
Contributor Author

abailly commented Jan 24, 2021 via email

@hamishmack
Copy link
Collaborator

Something like this should work now (with the current haskell.nix master):

project.shellFor {
  buildInputs = builtins.attrValues
    (haskell-nix.hackage-package {
      compiler-nix-name = "ghc8103";
      name = "haskell-language-server";
      version = "latest";
    }).components.exes;
}

With #1015 these will also work:

project.shellFor {
  tools = {
    haskell-language-server = "latest";
    haskell-language-server-wrapper = "latest";
  };
}
project.shellFor {
  buildInputs = [
    (haskell-nix.tool "ghc8103" "haskell-language-server" "latest")
    (haskell-nix.tool "ghc8103" "haskell-language-server-wrapper" "latest")
  ];
}

@abailly
Copy link
Contributor Author

abailly commented Jan 24, 2021 via email

@abailly
Copy link
Contributor Author

abailly commented Jan 24, 2021

So I tried the first solution

    # Some you may need to get some other way.
    buildInputs = builtins.attrValues
      (haskellNix.hackage-package {
          compiler-nix-name = "ghc8102";
          name = "haskell-language-server";
          version = "latest";
        }).components.exes;

and it says

trace: No index state specified for hydra-sim, using the latest index state that we know about (2021-01-20T00:00:00Z)!
trace: To make project.plan-nix for hoogle a fixed-output derivation but not materialized, set `plan-sha256` to the output of the 'calculateMaterializedSha' script in 'passthru'.
trace: To materialize project.plan-nix for hoogle entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
error: attribute 'hackage-package' missing, at /home/curry/hydra-sim/shell.nix:26:8
(use '--show-trace' to show detailed location information)

I guess I will have to wait for #1015 to reach master?

@TerrorJack
Copy link
Contributor

Feel free to borrow the shell.nix from one of our own projects, the lines to set up haskell-language-server is here :)

@abailly
Copy link
Contributor Author

abailly commented Jan 28, 2021

Thanks to the kind help from quite a few people I managed to solve that issue. I now have a working environment with emacs, LSP, HLS and Nix working together! There are still a few glitches and lot of stuff I don't really understand but at least I can load a file in Emacs and have the HLS installed in nix-shell give me errors and hints.
The result lives here: https://github.com/abailly/hydra-sim/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants