First-time setup
If this is your first time using Nix or haskell-template
(or a project based on it) you will initially need to setup a few things on your system.
Nix
-
Install Nix (version must be 2.8 or greater)
- If you are using Windows, you may install Nix under WSL2
-
In the project directory, run
nix develop -i -c haskell-language-server
to sanity check your environment.- This will download the required dependencies and cache them to the local Nix store. If it succeeds, it means everythingβs good.
-
Install direnv
-
NOTE: If you choose not to use direnv, you must launch VSCode from inside of
nix develop
shell.
-
NOTE: If you choose not to use direnv, you must launch VSCode from inside of
VSCode
While you may use any text editor with language-server support, we will use VSCode because it is generally the easiest way to get started.
-
Launch VSCode, and open the
git clone
βed project directory as single-folder workspace- NOTE: If you are on Windows, you must use the Remote - WSL extension to open the folder in WSL.
-
When prompted by VSCode, install the workspace recommended extensions.
- The direnv extension will load the nix shell.
- The extension will ask you to restart VSCode at the end. Do it.
Running in VSCode
Once the project has been reloaded in VSCode, you are ready to start developing it. But first, it is useful to sanity check a few things:
Test that haskell-language-server works
-
Open
src/Main.hs
.- Notice haskell-language-server launching in the footer (you should see βProcessing (1/2)β), and wait for it finish.
-
Hover your mouse over something, say
putTextLn
, and see the hover tooltip giving you the type signature.- This means the IDE support works!
Test that ghcid works
- Launch the terminal inside VSCode
-
Run
nix develop
shell and runjust run
.-
This will launch ghcid to run the
main
entrypoint insrc/Main.hs
.
-
This will launch ghcid to run the
-
Modify
src/Main.hs
and save it.
This should have just run
instantly re-compile and re-run the program.
Note: you can also press Ctrl+Shift+B to run just run
.
Rename the project
Finally, if you are going to be using this template for a real project, you should rename it.
NAME=myproject
# First, click the green "Use this template" button on GitHub to create your copy
# You may name the new repository to be the same as $NAME
git clone <your-clone-url> $NAME
cd $NAME
# Copy-paste these 4 lines at the same time
git mv haskell-template.cabal ${NAME}.cabal
nix run nixpkgs\#sd -- haskell-template ${NAME} * */*
echo "# ${NAME}\n\n" > README.md
git add . && git commit -m rename
Next steps
See haskell-template
for further documentation.