diff --git a/doc/languages-frameworks/haskell.section.md b/doc/languages-frameworks/haskell.section.md index cba4d0561b07..c2838c733c72 100644 --- a/doc/languages-frameworks/haskell.section.md +++ b/doc/languages-frameworks/haskell.section.md @@ -359,6 +359,39 @@ services.hoogle = { }; ``` +### How to install haskell-language-server + +In short: Install `pkgs.haskell-language-server` and use the +`haskell-language-server-wrapper` command to run it. See the [hls +README](https://github.com/haskell/haskell-language-server) on how to configure +your text editor to use hls and how to test your setup. + +Hls needs to be compiled with the ghc version of the project you use it on. + +`pkgs.haskell-language-server` provides `haskell-language-server-wrapper`, +`haskell-language-server`, `haskell-language-server-x.x` and +`haskell-language-server-x.x.x` binaries, where `x.x.x` is the ghc version for +which it is compiled. By default it includes binaries for all ghc versions +that are provided in the binary caches. You can override that list with e.g. + +```nix +pkgs.haskell-language-server.override { supportedGhcVersions = [ "884" "901" ]; } +``` + +When you run `haskell-language-server-wrapper` it will detect the ghc version +used by the project you are working on (by asking e.g. cabal or stack) and pick +the appropriate above mentioned binary from your path. + +Be careful when installing hls globally and using a pinned nixpkgs for a Haskell +project in a nix-shell. If the nixpkgs versions deviate to much (e.g. use +different `glibc` versions) hls might fail. It is recommended to then install hls +in the nix-shell from the nixpkgs version pinned in there. + +If you know, that you only use one ghc version, e.g. in a project specific +nix-shell You can either use an override as given above or simply install +`pkgs.haskellPackages.haskell-language-server` instead of the top-level +attribute `pkgs.haskell-language-server`. + ### How to build a Haskell project using Stack [Stack](http://haskellstack.org) is a popular build tool for Haskell projects. diff --git a/pkgs/development/tools/haskell/haskell-language-server/withWrapper.nix b/pkgs/development/tools/haskell/haskell-language-server/withWrapper.nix new file mode 100644 index 000000000000..09cb60901e43 --- /dev/null +++ b/pkgs/development/tools/haskell/haskell-language-server/withWrapper.nix @@ -0,0 +1,58 @@ +{ lib, supportedGhcVersions ? [ "865" "884" "8102" ], stdenv, haskellPackages +, haskell }: +# +# The recommended way to override this package is +# +# pkgs.haskell-language-server.override { supportedGhcVersions = [ "901" ]; } +# +# for example. Read more about this in the haskell-language-server section of the nixpkgs manual. +# +let + inherit (lib) concatStringsSep concatMapStringsSep take splitString; + getPackages = version: haskell.packages."ghc${version}"; + getMajorVersion = packages: + concatStringsSep "." (take 2 (splitString "." packages.ghc.version)); + tunedHls = hsPkgs: + haskell.lib.justStaticExecutables + (haskell.lib.overrideCabal hsPkgs.haskell-language-server (old: { + postInstall = '' + remove-references-to -t ${hsPkgs.ghc} $out/bin/haskell-language-server + remove-references-to -t ${hsPkgs.shake.data} $out/bin/haskell-language-server + remove-references-to -t ${hsPkgs.js-jquery.data} $out/bin/haskell-language-server + remove-references-to -t ${hsPkgs.js-dgtable.data} $out/bin/haskell-language-server + remove-references-to -t ${hsPkgs.js-flot.data} $out/bin/haskell-language-server + ''; + })); + targets = version: + let packages = getPackages version; + in [ + "haskell-language-server-${packages.ghc.version}" + "haskell-language-server-${getMajorVersion packages}" + ]; + makeSymlinks = version: + concatMapStringsSep "\n" (x: + "ln -s ${ + tunedHls (getPackages version) + }/bin/haskell-language-server $out/bin/${x}") (targets version); + pkg = tunedHls haskellPackages; +in stdenv.mkDerivation { + pname = "haskell-language-server"; + version = haskellPackages.haskell-language-server.version; + buildCommand = '' + mkdir -p $out/bin + ln -s ${pkg}/bin/haskell-language-server $out/bin/haskell-language-server + ln -s ${pkg}/bin/haskell-language-server-wrapper $out/bin/haskell-language-server-wrapper + ${concatMapStringsSep "\n" makeSymlinks supportedGhcVersions} + ''; + meta = haskellPackages.haskell-language-server.meta // { + maintainers = [ lib.maintainers.maralorn ]; + longDescription = '' + This package provides haskell-language-server, haskell-language-server-wrapper, ${ + concatMapStringsSep ", " (x: concatStringsSep ", " (targets x)) + supportedGhcVersions + }. + + You can override the list supportedGhcVersions. + ''; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8e71ec4fc232..afa6ffb40c0e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -4340,6 +4340,8 @@ in hash-slinger = callPackage ../tools/security/hash-slinger { }; + haskell-language-server = callPackage ../development/tools/haskell/haskell-language-server/withWrapper.nix { }; + hasmail = callPackage ../applications/networking/mailreaders/hasmail { }; hal-flash = callPackage ../os-specific/linux/hal-flash { };