VSCodium
with extensions and executables forHaskell
.- A sample
Haskell
project.
Spoiler
- NixOS wiki - Haskell
- flake.nix - code in this flake is extensively commented.
- codium-haskell - template for this flake.
- Haskell - general info about
Haskell
tools. - language-tools/haskell - a flake that provides
Haskell
tools. - codium-generic - info just about
VSCodium
with extensions. - Troubleshooting
- flakes - my Nix flakes that may be useful for you.
- Conventions
- Prerequisites
-
Install Nix - see how.
-
In a new terminal, start a devshell and run the app.
nix flake new my-project -t github:deemp/flakes#codium-haskell-simple cd my-project git init && git add nix develop cabal run
-
Write
settings.json
and startVSCodium
.nix run .#writeSettings nix run .#codium .
-
Open a
Haskell
fileapp/Main.hs
and hover over a function. -
Wait until
Haskell Language Server
(HLS
) starts giving you type info.
The nix-managed
package (package in this flake) has several non-Haskell
dependencies.
First, as nix-managed
uses an lzma
package, it needs a C
library liblzma
. This library is delivered via Nix
as pkgs.lzma
.
Second, nix-managed
calls the hello
command at runtime (see someFunc
in src/Lib.hs
). This command comes from a hello
executable which is delivered via Nix
as pkgs.hello
.
cabal
from devShells.default
has on its PATH
that hello
executable.
Let's inspect what's available.
-
Enter the
devShell
.nix develop
-
Run the app.
cabal run
-
Next, access the
hello
executable in a repl.cabal repl ghci> :? ... :!<command> run the shell command <command> ... ghci> :! hello Hello, world!
-
ghcid
uses thecabal repl
command. That's why, when runningghcid
,hello
will be available to the app.ghcid
-
ghcid
will run not only themain
function, but also the code in magic comments (Seeapp/Main.hs
). -
Sometimes,
cabal
doesn't use theNix
-supplied packages (issue). In this case, usecabal v1-*
- commands.
This flake uses GHC of a specific version (ghcVersion
).
nixpkgs
provides other GHC
versions.
Explore them in a repl:
nix repl
:lf .
-- use your system
ghcVersions.x86_64-linux
To switch to a specific GHC
version (let's call it <ghc>
):
- In
flake.nix
, change theghcVersion
value to<ghc>
.
- package.yaml - used by
stack
orhpack
to generate a.cabal
- .markdownlint.jsonc - for
markdownlint
from the extensiondavidanson.vscode-markdownlint
- .ghcid - for ghcid
- .envrc - for direnv
- fourmolu.yaml - for fourmolu
- ci.yaml - a generated
GitHub Actions
workflow. See workflows. Generate a workflow vianix run .#writeWorkflows
. - [hie.yaml] - a config for hie-bios. Can be generated via implicit-hie to check the
Haskell Language Server
setup.