freeman42x / haskell-editor-setup

Easy instructions for setting up Haskell editors / IDEs on any major operating system.
GNU General Public License v3.0
101 stars 15 forks source link
haskell haskell-editor haskell-ide-engine hie ide ide-features nix

Instructions for setting up Haskell editors / IDE

HIE together with compatible plugins usually offers more features than the average Haskell multi-feature plugin + compatible plugins. Some exceptions are: IntelliJ IDEA which has a very good set of features (and HIE does not have an IDEA plugin yet) and Leksah (which also does not have a HIE plugin but offers quite a lot of features itself).

To see a list of Haskell IDE Engine features see: HIE features

For a list of editor / IDE features see: rainbyte/haskell-ide-chart

Choose your operating system and continue the steps required for it:

Windows

Install Git

Enable Win32 long paths

On Windows Professional

On Windows Home or Starter

Install the Haskell Tool Stack

Install Haskell IDE Engine

Continue with installing the editor / IDE of your choice

Install Nix on your operating system

Nix is a package manager that is very good at doing successful installs.

If you require any system level libraries to use in the project you are working on it is recommended to use Nix to provide them and then do your development inside a nix-shell.

Doing Haskell development on Windows is not recommended since many Haskell packages have issues building on Windows. For doing development while using Widnows as your OS the recommended options are to use either a VMWare virtual machine (preferred) or Windows Subsystem for Linux (unrecommended since the build times are much slower).

Developing on Linux or MacOS should work fine.

To install Nix in your OS run:

curl https://nixos.org/nix/install | sh

Install GHC and cabal-install

Create the file ~/.config/nixpkgs/config.nix and copy paste this into it:

with import <nixpkgs> {};

{
  allowUnfree = true;

  packageOverrides = pkgs: rec {
    all = pkgs.buildEnv {
      name = "all";

      paths = [
        haskell.compiler.ghc865
        haskellPackages.cabal-install
        binutils.bintools # required on WSL
      ];
    };
  };
}

And run following command to install the GHC and cabal-install packages:

nix-env -i all

Install the editor / IDE of your choice

Editors that are easy to set up are Atom, Visual Studio Code, IntelliJ IDEA Community or Sublime Text 3.

Editors / IDEs list and their Nix package name:

To install:

Continue with:

Install Haskell IDE Engine executable

In ~/.config/nixpkgs/config.nix add to the let variables:

all-hies = import (fetchTarball "https://github.com/infinisil/all-hies/tarball/master") {};

and add following to the list of packages - change the GHC list to the ones you will want to have available (eg. ghc865 or ghc865 ghc864 ghc843):

(all-hies.selection { selector = p: { inherit (p) ghc865; }; })

if you wish to install HIE for all GHC versions because you switch between projects with different GHC versions a lot then you can use this instead:

(all-hies.selection { selector = p: p; })

installing all HIE versions will take a long time to install

after adding HIE your configuration should look something like the following:

with import <nixpkgs> {};

let
  all-hies = import (fetchTarball "https://github.com/infinisil/all-hies/tarball/master") {};
  unstable = import <nixpkgs> { inherit config; };
in
  {
    allowUnfree = true;

    packageOverrides = pkgs: rec {
      all = pkgs.buildEnv {
        name = "all";

        paths = [
          binutils.bintools # required on WSL
          haskell.compiler.ghc865
          haskellPackages.cabal-install
          unstable.haskellPackages.stack
          unstable.haskellPackages.cabal2nix
          haskellPackages.hoogle
          haskellPackages.ghcid
          (all-hies.selection { selector = p: { inherit (p) ghc865; }; })
        ];
      };
    };
  }

run nix-env -i all to install HIE

Install the extensions for your editor / IDE that help with Haskell development

Atom (setup difficulty trivial)

Visual Studio Code (VSCode) (setup difficulty trivial)

Installing Hasklig fonts on Windows:

Enabling Hasklig fonts:

Alternatives to HIE:

Emacs (setup difficulty hard)

Alternatives to HIE:

Spacemacs

Alternatives to HIE:

Neovim (setup difficulty hard)

Alternatives to HIE:

Vim (setup difficulty hard)

Alternatives to HIE:

Leksah (setup difficulty hard)

IntelliJ IDEA Community (setup difficulty easy)

Sublime Text 3 (setup difficulty normal)

Alternatives to HIE: