haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.66k stars 355 forks source link

Nix installation? #122

Closed spacekitteh closed 2 years ago

spacekitteh commented 4 years ago

Anyone have a nix expression to install this?

korayal commented 4 years ago

When I have spare time, I try to keep up with the master branch for GHC 8.6.5 here:

https://github.com/korayal/hls-nix

It also has a cachix cache for darwin & linux

On Sat, May 23, 2020, 08:57 Sophie Taylor notifications@github.com wrote:

Anyone have a nix expression to install this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haskell/haskell-language-server/issues/122, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACMTSIMIE5E3K6KKNII7V3RS5QVVANCNFSM4NIJ3CYA .

414owen commented 4 years ago

@korayal I tried out a bunch of different derivations I found floating around. Yours is the only one that worked out of the box. If you're happy to maintain this, it would be great to add a link to hls-nix from the haskell-language-server readme. Might prevent a few other people from waiting for GHC builds.

alanz commented 4 years ago

Would anyone like to update the README to reflect this?

korayal commented 4 years ago

@414owen I don't think my version is useful for everyone using nix, because the build is only confirmed on the fixed nixpkgs version I'm using on GHC 8.6.5. The nix expression could be useful for people trying this out on their own versions. I don't plan on maintaining this on any other combinations than what I use at the time. Even 'that' takes ~0-2 hours of my time depending on the change in dependencies.

It would be nice to build a hls clone for all-hies (or ghcide-nix) though. But unfortunately, I do not have the time to do that. but if someone does, I can support and contribute to that effort when I have the spare time.

414owen commented 4 years ago

@korayal fair enough. I might look into supporting more GHC versions and setting up CI. Thanks for bootstrapping a build :)

zypeh commented 4 years ago

Is it ok if I work on this? I am learning Nix packaging and try to build hls on Nix too.

korayal commented 4 years ago

@414owen thanks! Btw, I did kick off a clone of ghcide-nix on a branch here for hls-nix and started a build for hls-ghc865. it could take hours, so I don't know if it will succeed on first try. but I think if we can make it build and push to a cache, it would be pretty easy to maintain. Maybe @domenkozar can help us out here.

@zypeh this can also be useful if you wanted to take on this challenge.

domenkozar commented 4 years ago

Would you be up to having Nix expressions in this repo? That would really make things easy.

zypeh commented 4 years ago

@domenkozar you mean having the nix expression installation working directly on this repo?

domenkozar commented 4 years ago

Yup.

korayal commented 4 years ago

My take above using ghcide-nix's haskell.nix method failed for this project, which I think is related to stack-to-nix, I got the error below:

substituteStream(): WARNING: pattern '# nix-sha256:' doesn't match anything in file 'stack-8.6.5.yaml'
fatal: not a tree object: fb3859dca2e54d1bbb2c873e68ed225fa179fbef
error: program 'git' failed with exit code 128
(use '--show-trace' to show detailed location information)

Which, I think is related to this dependency

edit: oh, it looks like stack-to-nix has a requirement to add the sha256 as comment.

domenkozar commented 4 years ago

That's right - it's quite tricky. As part of https://nix.dev/ I plan to write also a tutorial for haskell.nix

korayal commented 4 years ago

On my latest take I was able to build for GHC 8.8.3 and 8.6.5, but not others. GHC 8.10.1 is not supported by haskell.nix yet. I haven't digged deeper for 8.8.2 and 8.6.4.

On the other hand, since haskell-language-server exposes two executables (haskell-language-server and haskell-language-server-wrapper), when I install packages.haskell-language-server.components.exes, I get priority conflict on LICENCE files. But if I install packages.haskell-language-server.components.exes.haskell-language-server then change it's priority and then install packages.haskell-language-server.components.exes.haskell-language-server-wrapper, it does work. Though I don't think this is the way to fix that.

I've pushed to my cachix cache on that branch for both hls-ghc865 and hls-ghc883 for Linux.

unrelated to these above, but I was wondering about something. Right now this project is using ghcide as a submodule. Would it be possible to install this project without explicitly defining that ghcide dependency within nix files?

Normally when we install a nix package from GitHub we use the tarball and submodules are not included there.

spacekitteh commented 4 years ago

On my latest take I was able to build for GHC 8.8.3 and 8.6.5, but not others. GHC 8.10.1 is not supported by haskell.nix yet. I haven't digged deeper for 8.8.2 and 8.6.4.

On the other hand, since haskell-language-server exposes two executables (haskell-language-server and haskell-language-server-wrapper), when I install packages.haskell-language-server.components.exes, I get priority conflict on LICENCE files. But if I install packages.haskell-language-server.components.exes.haskell-language-server then change it's priority and then install packages.haskell-language-server.components.exes.haskell-language-server-wrapper, it does work. Though I don't think this is the way to fix that.

I've pushed to my cachix cache on that branch for both hls-ghc865 and hls-ghc883 for Linux.

Hmm. When I try installing hls-ghc883 using home-manager, I get a type error: The option valuehome.packages.[definition 23-entry 36]' in /home/spacekitteh/.config/nixpkgs/home.nix' is not of typepackage'.`

spacekitteh commented 4 years ago

Ah, your installation instructions were wrong. I'll submit a PR.

korayal commented 4 years ago

I just noticed there's already an issue on all-hies for this. I think the best path forward is to wait for/help @Infinisil on that since he's already working on a haskell.nix port for all-hies.

infinisil commented 4 years ago

Here's the current issue for using haskell.nix for all-hies: https://github.com/Infinisil/all-hies/issues/19, with this branch having the changes: https://github.com/Infinisil/all-hies/tree/haskell.nix

It's a bit unfortunate that I can only get 8.6.5 and 8.8.3 working with it though :/

poscat0x04 commented 4 years ago

I've just generated some nix derivations using the haskell.nix infra, they seem to be usable but I'm not entirely sure.

repo

Edit: The source links are incorrect, you'll need to clone haskell-language-server and point those links to the cloned folder.

michaelpj commented 4 years ago

I have a slightly different haskell.nix expression that I got working recently: https://github.com/input-output-hk/plutus/blob/6021baf728ed812a45a1a87c5deac2ee7d756d9d/nix/haskell-extra.nix#L33

poscat0x04 commented 4 years ago

Did an overhaul to my repository, now it supports all GHC versions on both release version and the master version

sir4ur0n commented 4 years ago

Thank you @poscat0x04 , I have started again from your derivation and had it work on my project! I had to duplicate your project to change various things to make it work with my project though, so I opened a few issues on your repo to smoothen the derivation consumption, but it otherwise seems to work! I'd be happy to switch back to your derivation if you agree on these changes (and I can try to open PRs to do the changes I proposed).

Again, thank you!

spacekitteh commented 4 years ago

Anybody have an up-to-date version for the vanilla Haskell infrastructure?

sir4ur0n commented 4 years ago

For what it's worth: a first version has been merged into the nixpkgs repository 2 days ago, thanks to @GuillaumeDesforges, see https://github.com/NixOS/nixpkgs/pull/91279 for more information.

I don't think it's yet available on nixpkgs-unstable channel, but it should land soon.

spacekitteh commented 4 years ago

Oh sweet!

spacekitteh commented 4 years ago

Hmm, what attribute is it under?

sir4ur0n commented 4 years ago

@GuillaumeDesforges are you able to tell us more? I just tested with nixpkgs-unstable and I can't find the haskell-language-server executable, nor hls, neither at top level or inside haskellPackages, but I'm not 100% familiar with how Haskell packages are updated/published on nixpkgs.

leungbk commented 4 years ago

It's not yet on the unstable channel, but it is on the master branch of nixpkgs right now.

On Tue, Jul 7, 2020 at 3:15 PM Julien Debon notifications@github.com wrote:

@GuillaumeDesforges https://github.com/GuillaumeDesforges are you able to tell us more? I just tested with nixpkgs-unstable and I can't find the haskell-language-server executable, nor hls, neither at top level or inside haskellPackages, but I'm not 100% familiar with how Haskell packages are updated/published on nixpkgs.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haskell/haskell-language-server/issues/122#issuecomment-655164647, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG65GOS7L76ZHUIN2MVDZZDR2ONBHANCNFSM4NIJ3CYA .

GuillaumeDesforges commented 4 years ago

You can find nixpkgs status here: https://status.nixos.org/

It says that the last update was yesterday for nixpkgs-unstable, so it should be there after updating the channel (are you on the unstable channel?)

It should be available in (import <nixpkgs> {}).haskell.packages.ghc883.haskell-language-server

EDIT: just checked

nix-repl> (import <nixpkgs> {}).lib.version
"20.09pre233323.dc80d7bc4a2"
nix-repl> (import <nixpkgs> {}).haskell.packages.ghc883.haskell-language-server
«derivation /nix/store/ia0slqaljc6jyvpphc79y49ra4ir3b5k-haskell-language-server-0.1.0.0.drv»
[arsleust@poseideep:~]$ nix-shell -p haskell.packages.ghc883.haskell-language-server
[nix-shell:~]$ haskell-language-server --version
ghcide version: 0.1.0.0 (GHC: 8.8.3) (PATH: /nix/store/da1s18qqbgqn0aj1v5sbh2vrqbbs1z2c-haskell-language-server-0.1.0.0/bin/haskell-language-server)

You can then create a Haskell dev environment as usual using the nixpkgs Haskell infrastructure. Someone should probably work on adding it to haskell.nix.

sir4ur0n commented 4 years ago

Thank you Guillaume, I think I am more lost because of Nix then 🤔

$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
unpacking channels...
$ echo $NIX_PATH
/home/sir4ur0n/.nix-defexpr/channels:/home/sir4ur0n/.nix-defexpr/channels
$ ll /home/sir4ur0n/.nix-defexpr/channels/
nixpkgs -> /nix/store/fazhhnw3ywcxxh16zlbb15h381gvxc2f-nixpkgs-20.09pre233103.4855aa62fa1/nixpkgs/
$ nix repl
nix-repl> (import <nixpkgs> {}).lib.version
"20.09pre233103.4855aa62fa1"
nix-repl> (import <nixpkgs> {}).haskell.packages.ghc883.haskell-language-server
error: attribute 'haskell-language-server' missing, at (string):1:1

I assume based on the number 233103 that my version is older than yours 233323 (which may explain why I don't yet see the HLS package), however for the life of me I can't figure out what I'm doing wrong 😐

If anyone would be kind enough to tell me what's wrong, I would appreciate 🙇 I did search on Nix documentation but could not find any other way than nix-channel --update to update my nixpkgs...

spacekitteh commented 4 years ago

I found I had to run nix-channel --update twice for it to actually work for some reason :woman_shrugging:

sir4ur0n commented 4 years ago

I found I had to run nix-channel --update twice for it to actually work for some reason 🤷‍♀️

What. The. F*ck.

I just tested and it also worked O_o

Would anybody be able to explain this dark magic/bug?

spacekitteh commented 4 years ago

@copumpkin ?

sir4ur0n commented 4 years ago

Slightly unrelated question: how come the packages doesn't appear in https://nixos.org/nixos/packages.html?channel=nixpkgs-unstable&query=haskell-language-server ?

GuillaumeDesforges commented 4 years ago

Slightly unrelated question: how come the packages doesn't appear in https://nixos.org/nixos/packages.html?channel=nixpkgs-unstable&query=haskell-language-server ?

image

I just clicked on your linked btw, please check that you are looking at unstable channel

sir4ur0n commented 4 years ago

Yes, I am, it's part of the URL...

When I click: image

Interestingly, when trying in a private-mode browser, it appears: image

I guess this is related to caching, however this website is highly confusing, as it displays a loading bar (even on my regular web browser) before displaying "No results found", so the user (at least me) expects this is a server response, not some cache: image

Note: it still displays "No results found" when force refreshing (in Chrome: Ctrl + F5, Shift + F5)...

I guess this solves this mystery, though I find it a poor user experience :/

If anyone is affiliated or knows maintainers of this website, this may be worth letting them know :disappointed:

sir4ur0n commented 4 years ago

In case anyone is interested, I took a second look at this caching problem.

The problem seems to come from the fact that this page at some points loads https://channels.nixos.org/nixpkgs-unstable/packages.json.br which is a HTTP 301 (redirect to the latest nixpkgs).

On my regular browser, it hits a disk cache and thus always targets https://releases.nixos.org/nixpkgs/nixpkgs-20.09pre232864.55668eb671b/packages.json.br (even if using Ctrl + F5)

image

Note the version is stuck at 232864.

When doing the same thing in an incognito browser, it redirects to https://releases.nixos.org/nixpkgs/nixpkgs-20.09pre233849.1d801806827/packages.json.br (note the version is 233849).

The former does not contain haskell-language-server, the latter does.

I guess the page should not cache this 301 redirect :man_shrugging:

mulderr commented 4 years ago

Short experience report. Moved project to nixos-unstable-small rev 9ab83c6eed9d1c6840940f5918713383346706a3 and GHC 8.8.4. Had to add haskell.packages.ghc884.haskell-language-server to my shell.nix. This gives:

haskell-language-server version: 0.2.2.0 (GHC: 8.8.4) (...)

And... it's alive! VS code plugin picked it up automatically.

@GuillaumeDesforges nice work! :+1:

rybern commented 4 years ago

Thank you @GuillaumeDesforges!!

It's worth noting that the version pointed to by nixpkgs doesn't have PR #243, which fixed an issue with lsp-haskell in emacs (see here). In case anyone else runs into that: I got around it by modifying the HLS nixpkgs derivation to point at master, which wouldn't compile because nixpkgs doesn't have lsp-test 0.11.0.3 yet, so I forked HLS to remove that dependency (that fork here), and turned off the check phase.

soulomoon commented 4 years ago

Since currently cachix cache does not have enough pre build versions. I create a simple python3 script to ease the installation of all pre-builds binaries from github release.

sir4ur0n commented 4 years ago

Besides documenting the availability in Nixpkgs (with a minimal shell.nix example?), is there anything else to be done in this issue? If not, I can try to open a PR and then we finally close this issue?

tscholak commented 4 years ago

Hi, I was able to get it to work with haskell.nix, see here: https://github.com/hasktorch/hasktorch-skeleton/blob/master/nix/default.nix#L35-L54 and here: https://github.com/hasktorch/hasktorch-skeleton/blob/master/shell.nix#L24

peterstorm commented 4 years ago

Can someone help me install the 864 version with nix, using fetchUrl? I tried this, but I can't make it work.

{ pkgs ? import ../nixpkgs.nix }:
pkgs.stdenv.mkDerivation rec {
  name = "haskell-language-server";

  src = pkgs.fetchurl {
    url = "https://github.com/haskell/haskell-language-server/releases/download/0.3.0/haskell-language-server-Linux-8.6.4.gz";
    sha256 = "1q3vq2gdb3zsmxab1fmq4s7f7p4r3kdzn709aqf83hhfx18sn1rj";

  };
  phases = ["installPhase"];

  installPhase = ''
    mkdir -p $out/bin
    ${pkgs.gzip}/bin/gzip -d $src  $out/bin
    chmod +x $out/bin/haskell-language-server-Linux-8.6.4

  '';
}
GuillaumeDesforges commented 4 years ago

@peterstorm I'd advice using the haskell-language-server from nixpkgs:

for instance if you want a shell.nix file for nix-shell:

{ pkgs ? import <nixpkgs> }:
pkgs.mkShell {
  buildInputs = with pkgs; [ cabal-install stack haskell.packages.ghc864.haskell-language-server ];
}

your <nixpkgs> should be "unstable" (see https://nixos.wiki/wiki/Nix_channels)

peterstorm commented 4 years ago

Oh, I didn't know that version was added, I'll check that out, thank you @GuillaumeDesforges!

peterstorm commented 4 years ago

@GuillaumeDesforges Hmm, it says that the gh864 attribute is missing, and I'm importing sources from unstable :(

GuillaumeDesforges commented 4 years ago

Oops, ghc864 not gh864

GuillaumeDesforges commented 4 years ago

Well, seems like ghc864 has been dropped in favor of ghc865. Can you upgrade?

peterstorm commented 4 years ago

@GuillaumeDesforges Not really, I'm on that specific version because of a GHCJS project :( I'll try to figure out how to get the binary

Galagora commented 4 years ago

This issue is fixed and can be closed. The latest version is in Nixpkgs; it can be installed just like any other Haskell package.

Galagora commented 4 years ago

@peterstorm If you still have this issue, try

# { stdenv
# , autoPatchelfHook
# }:
with import (import ./nix/sources.nix).nixpkgs {};
stdenv.mkDerivation {
  name = "haskell-language-server";
  src = fetchurl {
    url = "https://github.com/haskell/haskell-language-server/releases/download/0.4.0/haskell-language-server-Linux-8.6.4.gz";
    sha256 = "0fhzm9190mgya08mcjz9zrd34p1s3k1a1l9dzxpxm7ij9b43n333";
  };
  nativeBuildInputs = [
    autoPatchelfHook
  ];

  buildInputs = [
    git
    gmp
    ncurses
    zlib

    haskellPackages.cabal-install
    haskellPackages.hlint
  ];

  phases = ["installPhase"];

  installPhase = ''
    mkdir -p $out/bin
    gzip -d < $src > $out/bin/haskell-language-server-Linux-8.6.4
    chmod +x $out/bin/haskell-language-server-Linux-8.6.4
  '';
}