Skip to content

Latest commit

 

History

History

haskell-simple

Haskell

  • VSCodium with extensions and executables for Haskell.
  • A sample Haskell project.

Prerequisites

Spoiler

Quick start

  1. Install Nix - see how.

  2. 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
  3. Write settings.json and start VSCodium.

    nix run .#writeSettings
    nix run .#codium .
  4. Open a Haskell file app/Main.hs and hover over a function.

  5. Wait until Haskell Language Server (HLS) starts giving you type info.

Default devshell

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.

  1. Enter the devShell.

    nix develop
  2. Run the app.

    cabal run
  3. Next, access the hello executable in a repl.

    cabal repl
    ghci> :?
    ...
    :!<command> run the shell command <command>
    ...
    ghci> :! hello
    Hello, world!
  4. ghcid uses the cabal repl command. That's why, when running ghcid, hello will be available to the app.

    ghcid
  5. ghcid will run not only the main function, but also the code in magic comments (See app/Main.hs).

  6. Sometimes, cabal doesn't use the Nix-supplied packages (issue). In this case, use cabal v1-* - commands.

GHC

Available versions

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

Change version

To switch to a specific GHC version (let's call it <ghc>):

  1. In flake.nix, change the ghcVersion value to <ghc>.

Configs