emacs-lsp / lsp-haskell

lsp-mode :heart: haskell
https://emacs-lsp.github.io/lsp-haskell
GNU General Public License v3.0
227 stars 56 forks source link

Path to HLS under nix-shell #138

Closed yaitskov closed 2 years ago

yaitskov commented 2 years ago

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.

michaelpj commented 2 years ago

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

yaitskov commented 2 years ago

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.

yaitskov commented 2 years ago

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.
michaelpj commented 2 years ago

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 :)

yaitskov commented 2 years ago

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? ;)

yaitskov commented 2 years ago

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