Skip to content

ghcide often fails to build project under nixos, where cabal succeeds. #922

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
maralorn opened this issue May 2, 2020 · 11 comments
Closed

Comments

@maralorn
Copy link
Contributor

maralorn commented May 2, 2020

So I am not sure if this is a bug report or just a question. My setup is the following:

  • I am on nixpkgs stable where everything is ghc 8.6.5.
  • I have installed ghcide via the haskell.nix expression.
  • I have configured hie.yaml to use the cabal cradle.
  • I have installed all the cabal dependencies via nix and am in my nix-shell.

Now running 'cabal build' works completely fine using all dependencies as provided by the nix-shell. It just needs to compile my project.

Running ghcide I got various different problems like linking problems which I sometimes can solve by throwing away the cabal cache or other desperate (and terribly stateful) measures like that.

As a matter of fact my error message changed while writing this bug report and I don‘t know why. /o\

So error 1:

Step 4/6, Cradle 1/1: Loading GHC Session
ghcide: <command line>: can't load .so/.DLL for: /nix/store/hz3nwwc0k32ygvjn63gw8gm0nf9gprd8-ghc-8.6.5/lib/ghc-8.6.5/ghc-prim-0.5.3/libHSghc-prim-0.5.3-ghc8.6.5.so (/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib/libm.so.6: version `GLIBC_2.29' not found (required by /nix/store/hz3nwwc0k32ygvjn63gw8gm0nf9gprd8-ghc-8.6.5/lib/ghc-8.6.5/ghc-prim-0.5.3/libHSghc-prim-0.5.3-ghc8.6.5.so))

error 2:

Step 4/6, Cradle 1/1: Loading GHC Session
ghcide: <command line>: cannot satisfy -package-id relude-0.5.0-NlfLSbCBQXGvBVuRHbLbX (Relude as Prelude)
    (use -v for more information)

Since the exact solution to my problems are probably out of scope I have two concrete questions:

  1. What are the general reasons that cabal build works just fine but ghcide fails to build the dependencies? Shouldn‘t the hie-bios setup lead to them doing exactly the same?

  2. (I fear this is actually a bit out of scope here.) I often get error messages from ghcide which say (use -v for more information). Any chance to actually do that? Passing it to ghcide does obviously not work.

Thank you so much for ghcide, I love programing with it. That‘s why I get so desperate when it doesn‘t work …

@mpickering
Copy link
Contributor

I have run into the first error and it's because you have built a package against a different version of glibc than the one you are currently using. This can arise because cabal doesn't take the glibc version into account when creating the package hash (because it's not nix). You need to ensure that the same glibc version is used to build ghc, ghcide and all your packages.

The second error is usually because you have a GHC version mismatch between the ghcide version and your project version.

@maralorn
Copy link
Contributor Author

maralorn commented May 2, 2020

Thanks for the quick reply!

I have run into the first error and it's because you have built a package against a different version of glibc than the one you are currently using. This can arise because cabal doesn't take the glibc version into account when creating the package hash (because it's not nix). You need to ensure that the same glibc version is used to build ghc, ghcide and all your packages.

So throwing away my .cabal should fix that, right?

The second error is usually because you have a GHC version mismatch between the ghcide version and your project version.

I wonder how this can happen. It worked just the other day and everything is and was ghc 8.6.5 …

@mpickering
Copy link
Contributor

@maralorn If you are getting your ghcide from haskell.nix and ghc form normal nixpkgs then the glibc version could be different which will cause carnage.

Without further information about the second issue it is impossible to debug. On my branch ghcide prints out the options that it is using which would be useful to provide but the master version doesn't so not sure we can make progress.

@maralorn
Copy link
Contributor Author

maralorn commented May 2, 2020

Well this sounds like all my problems stem from the same source. ghcide not being installed the same way as the rest. Maybe the best idea would be to find a nixpkgs overlay which succesfully unbreaks the ghcide build there, like I did for obelisk.

@maralorn
Copy link
Contributor Author

maralorn commented May 2, 2020

Okay, with my overlay to just compile ghcide with the normal nixpkgs infrastructure it works. So (to make this issue really off-topic). What do you think about me upstreaming that overlay so that we have a working ghcide in nixpkgs?
Edit: Of course I would try to maintain that overlay in the future.

@mpickering
Copy link
Contributor

Is there an issue installing ghcide from haskellPackages.ghcide? Anyway post your overlay here at least! so other people can take advantage of it.

@maralorn
Copy link
Contributor Author

maralorn commented May 2, 2020

Yes, at least according to my sampling there was never a time when haskellPackages.ghcide was not marked as broken. Yeah, I gladly share my config:

let
      overrides = ghc: _: {
        haddock-library = pkgs.haskell.lib.dontCheck
          (ghc.callHackage "haddock-library" "1.8.0" { });
        haskell-lsp = ghc.callHackage "haskell-lsp" "0.19.0.0" { };
        haskell-lsp-types = ghc.callHackage "haskell-lsp-types" "0.19.0.0" { };
        regex-posix = ghc.callHackage "regex-posix" "0.96.0.0" { };
        test-framework = pkgs.haskell.lib.dontCheck
          (ghc.callHackage "test-framework" "0.8.2.0" { });
        regex-base = ghc.callHackage "regex-base" "0.94.0.0" { };
        regex-tdfa = ghc.callHackage "regex-tdfa" "1.3.1.0" { };
        shake =
          pkgs.haskell.lib.dontCheck (ghc.callHackage "shake" "0.18.4" { });
        hie-bios = pkgs.haskell.lib.dontCheck (ghc.callHackageDirect {
          pkg = "hie-bios";
          ver = "0.4.0";
          sha256 = "19lpg9ymd9656cy17vna8wr1hvzfal94gpm2d3xpnw1d5qr37z7x";
        } { });
        ghcide = pkgs.haskell.lib.dontCheck (ghc.callHackageDirect {
          pkg = "ghcide";
          ver = "0.1.0";
          sha256 = "0vwaaqb74dzsvx5xdfkzbi8zzvbd5w9l1wdhl3rhvi8ibnrchgfs";
        } { });
      };
in (haskellPackages.override { inherit overrides; }).ghcide

But I will have a look at fixing it in nixpkgs.

@maralorn
Copy link
Contributor Author

maralorn commented May 2, 2020

Just a quick takeaway for this issue. When the documentation says that you need to compile ghcide with the same ghc as your project. They mean it.

I’d advise against using ghcide-nix if you are not using haskell.nix anyways.

Compiling ghcide with the above overrides fixed all the above issues for me.

Dear people from the future finding this issue: Please note, that those overrides are working as of now for nixos-20.03 and ghcide-0.1.0. But hopefully you will not need them anyways, because ghcide will be fixed in nixpkgs.

@maralorn maralorn closed this as completed May 2, 2020
@maralorn
Copy link
Contributor Author

maralorn commented May 6, 2020

Just a heads-up: ghcide is now working on nixos-20.03. So on nixos it’s just one

nix-env -iA nixos.haskellpackages.ghcide

away from working. (Or better add it to your shell.nix or something like that.)

Note that it‘s the version for ghc 8.6.5. Which is the current ghc on nixpkgs stable.

nixpkgs-unstable is broken right now, but the fix for ghcide is already merged there. So there you can get a ghcide for ghc 8.10 in the near future.

@mpickering Would you think a PR explaining the caveats and install instructions comparing ghcide-nix and plain nixpkgs in the README is a good idea?

@mpickering
Copy link
Contributor

@maralorn Sounds like a good idea to me. It is much easier to run into these obscure problems with NixOS than other operating systems.

willbush referenced this issue in willbush/system May 24, 2020
Ghcide really should be installed via a `shell.nix` along with the project
because it needs to be build with the same version of GHC and share the same
glibc etc.

see: https://github.com/digital-asset/ghcide/issues/538
@willbush
Copy link
Contributor

Thanks for sharing the fix! This was driving me nuts. I was getting ready to nerd rage table flip.

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

3 participants