emacs-lsp/lsp-haskell

Path to HLS under nix-shell

yaitskov opened this issue · 6 comments

Hi,

I am looking for a proper way to specify path to haskell-language-server in a nix project.

I found workaround with following snippet in my .bashrc:

export PATH=/nix/store/h0vnzzhb93vjmvp4sx9z8q14k1j7c538-haskell-language-server-1.2.0.0/bin:$PATH
export PATH=/nix/store/92mc6jk3bw1yjg28jksxwiidgfw07gdi-ghc-8.10.6-with-packages/bin:$PATH
export PATH=/nix/store/gi951rnsh7gfqklyxvz49ibafpbvxqzm-cabal-install-3.4.0.0/bin:$PATH

I get paths by hand from nix-shell

$ nix-shell
$ type ghc
$ type haskell-language-server
$ type cabal

This is very rigid and not convenient.

(use-package lsp-mode
  :hook (prog-mode . lsp-mode)

  :init
  (with-eval-after-load 'lsp-mode
    (evil-leader/set-key
      "l" lsp-command-map))

  :config
  ;(advice-add 'lsp :before #'direnv-update-environment)
  (setq lsp-haskell-server-path "haskell-language-server")
  (setq lsp-haskell-process-path-hie "haskell-language-server")
  (setq lsp-modeline-code-actions-enable nil))

I tried to use following script but it is not working

/home/user/hls.sh

#!/bin/bash
exec nix-shell --run haskell-language-server-wrapper "$@"

chmod +x /home/user/hls.sh

  (setq lsp-haskell-process-path-hie "/home/user/hls.sh")

Emacs messages that hls exists.
Launching hls.sh manually from terminal is working though.

The best way is IMO to use direnv-mode and one of the many Nix/direnv integrations.

The best way is IMO to use direnv-mode and one of the many Nix/direnv integrations.

direnv just runs local .bashrc for the project, right?
I still have to generate proper PATH by "hand".

Second more stable version of my workaround would be

.envrc

export PATH=$(nix-shell --run 'bash -c "echo $PATH"')

It is more stable, but looks like a superhack.

doh. direnv times out with the second workaround:

direnv: ([/usr/bin/direnv export bash]) is taking a while to execute. Use CTRL-C to give up.

There are many ways to use direnv with nix. E.g. https://direnv.net/man/direnv-stdlib.1.html#codeuse-nix-code

Anyway, this isn't an Emacs issue any more :)

Thanks. I've got use is a magic command defined by direnv.

HLS 1.4 eats different amount of RAM depending on the way it is bound to Emacs.

use nix - 2.5 gb
export GHC, cabal and hls to PATH - 2.2 gb

where 300mb? ;)

direnv slows down noticeably regular nix-shell launch in a terminal - I see it prints to log.