summaryrefslogtreecommitdiff
path: root/modules/haskell.nix
blob: 1b8bc4568ed281b696024f526baf39549214f73c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ config, lib, pkgs, ... }:

with lib;
with builtins;
let
  cfg = config.haskell;

  spacemacsPackages = haskellPackages:
    with haskellPackages; [
      apply-refact
      hlint
      stylish-haskell
      hasktags
    ];
  haskellBuildInput = (if cfg.hoogle.enable then
    cfg.haskellPackages.ghcWithHoogle
  else
    cfg.haskellPackages.ghcWithPackages) (haskellPackages:
      (cfg.packages haskellPackages)
      ++ optionals cfg.spacemacs.enable (spacemacsPackages haskellPackages)
      ++ optional cfg.cabal.enable pkgs.cabal-install);
in {
  options.haskell = {
    enable = mkEnableOption { name = "haskell"; };
    haskellPackages = mkOption {
      type = with types;
        addCheck (lazyAttrsOf anything)
        (packages: lib.hasAttr "ghcWithPackages" packages);
      default = pkgs.haskellPackages;
      defaultText = literalExample "pkgs.haskellPackages";
      description = ''
        The set of Haskell packages from which to get GHC and its packages.
        Use this option to set the version of GHC.
      '';
      example = literalExample "pkgs.haskell.packages.ghcjs";
    };
    packages = mkOption {
      type = with types; functionTo (listOf package);
      default = _: [ ];
      defaultText = literalExample "_ : []";
      description = ''
        Haskell packages that will be made available to the environment.
      '';
      example = literalExample ''
        haskellPackages: with haskellPackages; [ async cabal-install ];
      '';
    };
    # Whether to load packages required by Spacemacs layer.
    spacemacs.enable = mkEnableOption "spacemacs";

    hoogle.enable = mkEnableOption "hoogle";

    cabal = {
      enable = mkEnableOption "cabal";
      package = mkOption {
        type = types.package;
        default = pkgs.cabal-install;
        defaultText = defaultText "pkgs.cabal-install";
        description = "The package for cabal.";
      };
      # TODO: add ability to set path to binaries
      # TODO: explain that here cabal is not loaded with ghc, but as an external package
    };
  };

  config = mkIf cfg.enable {
    buildInputs = [ haskellBuildInput ];
    envVars.PATH.value = mkIf cfg.cabal.enable "~/.cabal/bin"; # only on linux
  };
}