hie-bios
hie-bios copied to clipboard
Nix support
I'd like to propose Nix support.
By default, it would use shell.nix to enter the environment.
An example default configuration (mostly inspired by stack):
nix:
enable: true
shell-file: shell.nix
Just for reference, in order to fix compatibility between IOHK's haskell.nix infrastructure and ghcide-nix, I'm using a shell script like the following inside of a nix shell to make sure ghcide finds things correctly:
export NIX_GHC="$(which ghc)"
export NIX_GHCPKG="$(which ghc-pkg)"
export NIX_GHC_DOCDIR="$NIX_GHC/../../share/doc/ghc/html"
export NIX_GHC_LIBDIR="$(ghc --print-libdir)"
see digital-asset/ghcide#116
Hopefully this can be taken care of by nix integration at the hie-bios level?
@matthewess An alternative approach that I've been doing for HIE integration with direnv and emacs is setting those environment variables in a shellHook defined in the shell.nix for each project so that the paths can be constructed from nix values (I also set HIE_HOOGLE_DATABASE in this way). When I gave ghcide a try, I found the same approach worked. I don't think this buys you much if anything, but it's automatic.
I similarly re-use the variables from the nix haskell package ghcide is supposed to be used to hack on. Maybe the proposed bit of yaml configuration can allow providing a nix attribute to take the environment variables from.
shellHook = ''
export NIX_GHC="${haskellPackages.packagename.env.NIX_GHC}"
export NIX_GHCPKG="${haskellPackages.packagename.env.NIX_GHCPKG}"
export NIX_GHC_DOCDIR="${haskellPackages.packagename.env.NIX_GHC_DOCDIR}"
export NIX_GHC_LIBDIR="${haskellPackages.packagename.env.NIX_GHC_LIBDIR}"
'';
https://github.com/freuk/very-opinionated-haskell-skeleton/blob/dac5f3ff6b45366e5f4053098dda6d866f7bd0fa/default.nix#L94
How do the cradle test interplay with nix? I'm currently trying to integrate hie-bios-0.3 into nixpkgs and I get a lot of errors like:
multi-cabal: FAIL (0.07s)
Finding Cradle
Loading Cradle
Initialise Flags (0.07s)
cabal: streamingProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
@turion What does "integrate hie-bios into nix" mean?
This sounds like a very different issue to this ticket.
Right, let's continue in #107.
You can always use nix-shell --command "hie-wrapper --lsp" shell.nix
Sadly nix-shell --command "ghcide --lsp" won't work if its evoked by the editor since (I think) the editor is trying to talk to the nix-shell process instead of ghcide. It would be a godsend to have have hie-bios call nix itself (or even better lorri shell --cached) and only reload on nix file changes. That way your editor can still evoke the server itself and you won't have to exit your editor to get a access to the libraries/documentation you just added.
Its also a royal pain that ghcide restarts whenever you edit your cabal file if you have cradle: {cabal: {component: "lib:haskell-ide-engine"}} when developing inside a nix-shell. It means your completions just stop working until you exit your editor and reload your environment. This is because cabal new-repl won't work since you have just added new dependencies and those dependencies won't be there until you reload the underlying shell. I'm not sure if hie-bios is what's telling ghcide to restart on changes to cabal or its a ghcide thing, but either way it means you cannot continue development until you have finished building your new shell. To fix all of the above issues hie-bios needs a way to get its flags by calling nix-shell itself, before calling cabal new-repl or the like.
If there is a way to do this already or someone has figured out a hack around these pain points, let me know.
@Skyfold Invoking nix-shell --command "ghcide --lsp" is how I always invoke ghcide so it does work.
The reloading behaviour is coming from ghcide so you should open an issue about that there.
There is a UI issue because there is a difference between getting the flags in a nix-shell and running ghcide in the shell. You need to do both if you are using things like C dependencies.
@mpickering I assume you are running nix-shell --command "ghcide --lsp" in a separate shell, not using your editor, and then setting up your editor to communicate with that ghcide instance. What was failing for me was getting coc (vim plugin) to run nix-shell --command "ghcide --lsp" itself (would just crash).
Thanks for the explanation, I'll create an issue on ghcide to see if there is a way to disable auto-restart.
Now I understand, getting ghcide to get flags from nix is not enough. Sounds like I need to get coc talking to an external ghcide instance.
@Skyfold My editor invokes a wrapper script which contains that command.
Since there hasn't been any new development here, and no one tried to convince us this is necessary, I consider the nix support from hie-bios (basically none) to be adequate at the moment.