ghc-mod icon indicating copy to clipboard operation
ghc-mod copied to clipboard

Explicit nix-shell support

Open dalaing opened this issue 9 years ago • 10 comments

Currently ghc-mod is unaware of the package database used in a nix-shell.

There is a PR for this (#760), but a more general approach is needed than just fixing things for Emacs users :)

dalaing avatar Apr 14 '16 00:04 dalaing

Looks to me like all the ghc-mod commands need to be invoked from within the nix shell, which is hard since it's a ghc-mod command that we would use to figure out where shell.nix is (ghc-mod root).

EDIT: We would also want ghc-mod itself to come from that nix shell, in order to be built by the correct GHC, poking another hole...

ElvishJerricco avatar Jan 19 '17 20:01 ElvishJerricco

The ghc-mod you call ghc-mod root on wouldn't actually need to be built by the project's GHC version FYI.

DanielG avatar Jan 19 '17 20:01 DanielG

Sure. But then something still needs to decide to enter the nix shell.

ElvishJerricco avatar Jan 19 '17 20:01 ElvishJerricco

ghc-mod could just re-exec itself inside the nix-shell, no?

DanielG avatar Jan 19 '17 20:01 DanielG

Yes. I'm just wondering how it would go about doing that. It could be done either in elisp or in ghc-mod itself. It would be weird if users had to have some arbitrary ghc-mod on their path, as well as a ghc-mod in their project's Nix shell. I'm currently experimenting with having the elisp find ghc-mod in the nix shell rather than on the path.

ElvishJerricco avatar Jan 19 '17 20:01 ElvishJerricco

I would really like to have the Haskell bits handle this as then all frontends would work on Nix and not just the Emacs frontend. I agree that it would be awkward to need a random ghc-mod on the PATH but at least that way it would work at all :)

DanielG avatar Jan 19 '17 20:01 DanielG

Fair point. Well then luckily this seems to be not so hard. Just relaunch ghc-mod from within a nix-shell if a shell.nix is found and nix-shell is installed.

ElvishJerricco avatar Jan 19 '17 20:01 ElvishJerricco

A stop-gap measure would be to use a proxying script like this one and have ghc-mod just proxy to a nix-shell running ghc-mod. The same would be done for cabal, ghc, ghc-modi, etc. I've used this successfully with Atom.

3noch avatar Jan 19 '17 21:01 3noch

That stop-gap script is working well for me with Emacs.

In some circumstances it might be nice to have it fall back to just running the commands if shell.nix isn't found, but all of my projects currently have a shell.nix so that doesn't really effect me at the moment.

dalaing avatar Jan 22 '17 09:01 dalaing

@dalaing Great. I had the same thought about a fall-back. Should be easy to add.

3noch avatar Jan 23 '17 13:01 3noch