Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

How to provide NIX_GHC_LIBDIR for a haskell.nix project #26

Open
masaeedu opened this issue Nov 30, 2019 · 3 comments
Open

How to provide NIX_GHC_LIBDIR for a haskell.nix project #26

masaeedu opened this issue Nov 30, 2019 · 3 comments

Comments

@masaeedu
Copy link

I'm not sure whether this is an issue to file in the haskell.nix repo or here, please feel free to redirect me.

I've got a haskell project setup with the following default.nix and shell.nix:

# default.nix
let
  sources = import ./nix/sources.nix;
  compilerVersion = "ghc865";
  pkgs = (import sources.iohk-nixpkgs) (import sources.iohk-hnix);
in
pkgs.haskell-nix.cabalProject {
  src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
  ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.${compilerVersion};
}
# shell.nix
let
  sources = import ./nix/sources.nix;
  compilerVersion = "ghc865";
  ghcide = (import sources.ghcide-nix {})."ghcide-${compilerVersion}";
  pkgs = import sources.nixpkgs {};
  hspkgs = import ./default.nix;
in
hspkgs.shellFor {
  withHoogle = true;
  buildInputs = [ ghcide pkgs.haskellPackages.ghcid ];
}

The sources expression comes from niv, to which I've added a bunch of different remote repos.

Now when I run ghcide I run into the following issue:

Starting ghcide (GHC v8.6)
/mnt/data/depot/git/haskell/repos/filterable
[1/6] Finding hie-bios cradle
Cradle {cradleRootDir = "/mnt/data/depot/git/haskell/repos/filterable", cradleOptsProg = CradleAction: cabal}

[2/6] Converting Cradle to GHC session
ghcide: <command line>: cannot satisfy -package-id QuickCheck-2.13.2-8nV7osDGiuU4p27xQv2fwB
    (use -v for more information)

This is explained nicely in the Setup.md file in the ghcide repo:

If you are using packages installed by Nix, then often Nix will set NIX_GHC_LIBDIR to say where the libraries are installed. ghcide can cope with that. However, sometimes the ghc on your shell will actually be a shell script that sets NIX_GHC_LIBDIR, which ghcide can't find. If that happens, you need to either set NIX_GHC_LIBDIR (so ghcide can see it) or use a proper Nix compatible wrapper over ghcide.

So if I cat $(which ghc) inside a nix-shell in project, I do indeed see:

#! /nix/store/kzv56yx369j0jvcza2cphj2pv8xmqga4-bash-4.4-p23/bin/bash -e
export NIX_GHC='/nix/store/j7l3g2bis82qvwjxrq61410pny08xj6p-ghc-shell-for-filterable-ghc-8.6.5/bin/ghc'
export NIX_GHCPKG='/nix/store/j7l3g2bis82qvwjxrq61410pny08xj6p-ghc-shell-for-filterable-ghc-8.6.5/bin/ghc-pkg'
export NIX_GHC_DOCDIR='/nix/store/j7l3g2bis82qvwjxrq61410pny08xj6p-ghc-shell-for-filterable-ghc-8.6.5/share/doc/ghc/html'
export NIX_GHC_LIBDIR='/nix/store/j7l3g2bis82qvwjxrq61410pny08xj6p-ghc-shell-for-filterable-ghc-8.6.5/lib/ghc-8.6.5'
exec "/nix/store/r23xw9gndvlx0pj8r4xia66ihj7g288s-ghc-8.6.5/bin/ghc"  "-B$NIX_GHC_LIBDIR" "${extraFlagsArray[@]}" "$@"

The problem is that the ghcide binary itself doesn't seem to have access to these variables.

At the moment, my workaround is to first cd into a directory where I've got direnv etc. all set up, do cat $(which ghc), then manually export the NIX_GHC_LIBDIR variable I see. I might automate this further once I get tired enough of this.

But leaving aside the workaround, what would be the correct way to get the ghcide binary to use the same NIX_GHC_LIBDIR value so that it can see all the libraries? Would you happen to know how that value is being produced for the ghc wrapper itself?

@masaeedu
Copy link
Author

My gross workaround for now is to change my .envrc to this:

use nix
source <(grep 'export NIX_' $(which ghc))

@domenkozar
Copy link
Member

See haskell/hie-bios#151

@fiadliel
Copy link

fiadliel commented Jun 5, 2020

Isn't this fixed by input-output-hk/haskell.nix#559 ?

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

No branches or pull requests

3 participants