Skip to content
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

Dynamic (TH-friendly) nix hls derivation #2665

Closed
eviefp opened this issue Jan 31, 2022 · 8 comments
Closed

Dynamic (TH-friendly) nix hls derivation #2665

eviefp opened this issue Jan 31, 2022 · 8 comments
Labels
type: enhancement New feature or request

Comments

@eviefp
Copy link

eviefp commented Jan 31, 2022

Is your feature request related to a problem? Please describe.

I would like to be able to easily use HLS on NixOS/form a nix expression WITH template haskell support.

Describe the solution you'd like

A sample shell.nix somewhere? A link to a blog post? Anything would be nice, hopefully linked to from https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries-and-template-haskell-support

Describe alternatives you've considered

Getting this error

haskell-language-server: error while loading shared libraries: libHSCabal-3.2.1.0-ghc8.10.7.so: cannot open shared object file: No such file or directory

What I did is I added this repository as a niv source, then:

let
  sources = import ../../nix/sources.nix;
  pkgs = import sources.nixpkgs { };
  hls = import sources.haskell-language-server;

  commonTooling = [
    pkgs.haskell.compiler.ghc8107
    pkgs.haskell.packages.ghc8107.cabal-install
  ];

  hlsPackage = hls.outputs.packages.x86_64-linux.haskell-language-server;
  dynamicHls = hlsPackage.overrideAttrs(attrs: {
    configureFlags = ["--enable-executable-dynamic"];
  });

  personalTooling = [
    dynamicHls
    pkgs.haskell.packages.ghc8107.cabal2nix
    pkgs.haskell.packages.ghc8107.implicit-hie
    pkgs.ghcid
  ];
in pkgs.mkShell {
  buildInputs = commonTooling ++ personalTooling;
}

Additional context

n/a

@guibou
Copy link
Collaborator

guibou commented Jan 31, 2022

Have you tried using the flake or simply nix build?

I'm using that at work with a codebase with a lot of TH and we have no issue, on nixos and ubuntu.

Otherwise, could you try to describe your working context more precisly (top: a repository that I can checkout and nix-shell in)? I'll have a look at that ASAP.

@codygman
Copy link

codygman commented Feb 2, 2022

Trying to use hls on this repo might help in reproducing any linking errors:

https://github.com/codygman/th-pq-segfault/tree/try-nix-libpq

From discussion at #1982 (comment).

@eviefp
Copy link
Author

eviefp commented Feb 2, 2022

I'll try reproducing it on the OSS version of our repo and report back with full reproduction instructions.

@skykanin
Copy link

skykanin commented Mar 8, 2022

Have you tried using the flake or simply nix build?

I'm using that at work with a codebase with a lot of TH and we have no issue, on nixos and ubuntu.

Otherwise, could you try to describe your working context more precisly (top: a repository that I can checkout and nix-shell in)? I'll have a look at that ASAP.

I've tried building from the flake directly, specifically the haskell-language-server-8107 package on the 1.6.1.0-hackage branch, without overriding any configure flags or anything and I get the error

LSP :: This HLS binary does not support Template Haskell. Follow the [instructions](https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries) to build an HLS binary with support for Template Haskell.

EDIT: Seems that building HLS from the flake on the master branch without doing any overrides works fine for me. I no longer get errors about missing support for template haskell 👍

@guibou
Copy link
Collaborator

guibou commented Mar 8, 2022

Could you try a more recent version than the 1.6.1.0-hackage.

git diff -r origin/master origin/1.6.1.0-hackage flake.nix | grep -B2 -A2 Static
           with pkgs.haskell.lib;
-          (enableSharedExecutables (overrideCabal hpkgs.haskell-language-server
+          justStaticExecutables (overrideCabal hpkgs.haskell-language-server
             (_: {
               postInstall = ''

EDIT: the diff between current master and 1.6.1.0-hackage shows the changes done in order to fix the template haskell problem, which are not part of the branch you were used.

EDIT2: Just saw your edit ;) It confirms my comment ;) Have fun.

@sternenseemann
Copy link

FWIW nixpkgs supports linking HLS dynamically via the wrapper derivation we provide:

pkgs.haskell-language-server.override {
  dynamic = true;
  supportedGhcVersions = [ "902" ]; # GHC 9.0.2
}

It's disabled by default to keep the closure size reasonable, dynamic linking leads to a lot of unnecessary downloads if all GHC versions are enabled (which is the default).

@domenkozar
Copy link
Contributor

I think having it on by default and having -minimal is more in the spirit of Nix.

If you have dynamic linking disabled, one gets terrible error messages and might take hours to figure out what to do.

If the closure size is the problem, you know what to do in Nix.

Human time > machine time.

@fendor
Copy link
Collaborator

fendor commented Jul 13, 2022

I don't think there is anything left for us to do here? Re-open if you disagree

@fendor fendor closed this as completed Jul 13, 2022
sandydoo added a commit to sandydoo/nixos that referenced this issue Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants