-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation - Working with Nix #79
Comments
That sounds crazy heavyweight, is this commonly done in the nix world? |
@gelisam when I said a "ghc binary" what I really meant was a ghc environment, basically ghc and a package database with everything in the correct place etc, most things are symlinks to the nix store anyway. |
@shmish111 We can fix the hard-coded ghc version by extracting it from the
I also added |
I spent a couple of days trying to get Hint working on Nix and I've finally managed it with the help of @mchakravarty. Below is what was required, could you document this somewhere obvious, maybe in the README.md?
Using hint with nix
Hint relies on certain GHC paths being set up correctly to function, these are the path to the library of packages and the path to the package database. If you are running hint with
stack exec
then this works without any modification. This is because stack sets the env varGHC_PACKAGE_PATH
as well as GHC libraries being in the expected places. If you run the binary produced bystack build
by itself you will need to setGHC_PACKAGE_PATH
to the value you can find withstack exec -- env | grep GHC_PACKAGE_PATH
.Unfortunately when you build your project with nix you will find that although your program runs, the hint interpreter can't find the package library files or the package db. There are two things you must do to solve these problems.
Set GHC_PACKAGE_PATH
You will need to build a ghc binary that has all the packages that hint will need when interpreting code:
You will then need to wrap up your binary in a shell script that will set the env var:
Now hint will be able to find the package database, however it still can't find the library files and you will probably get an error
can't find Prelude
.Set library directory
Hint provides
unsafeRunInterpreterWithArgsLibdir
to do this. You will need to set an env var (or pass in on the cli prompt) with the location ofmyGhc
library directory. In order to allow stack to work as well as nix, I put in a bit of boiler plate:I then need to set
GHC_LIB_DIR
in the nix wrapper script by adding an extra--set
flag, the final invoker wrapper will look like this:After doing this, nix will build a GHC with all the correct libraries and a wrapper script which you can then use to run your program and hint should work correctly.
The text was updated successfully, but these errors were encountered: