summaryrefslogtreecommitdiff
path: root/modules/coq.nix
blob: 21d1b718035c06b507d401fdd4c95b7537246370 (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
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.coq;
  # coqBuildInputs = (with cfg.coqPackages; [ coq ])
  #   ++ (cfg.packages cfg.coqPackages);
  coqBuildInputs = [ cfg.coq ]
    ++ (map (package: package.override { coq = cfg.coq; })
      (cfg.packages pkgs.coqPackages));
  coqrc = pkgs.writeText "coqrc" cfg.rc;
  coqFlags = concatStringsSep " " ([ "-init-file ${coqrc}" ]);
in {
  options.coq = {
    enable = mkEnableOption { name = "coq"; };
    coq = mkOption {
      type = types.package;
      default = pkgs.coq;
      defaultText = literalExample "pkgs.coq";
      description = ''
        The package providing Coq. Use this option to set the version of Coq.
      '';
    };
    # coqPackages = mkOption {
    #   type = types.lazyAttrsOf types.package;
    #   default = pkgs.coqPackages;
    #   defaultText = literalExample "pkgs.coqPackages";
    #   description = ''
    #     The set of Coq packages from which to get Coq and its packages.
    #     Use this option to set the version of Coq.
    #   '';
    # };
    packages = mkOption {
      type = with types; functionTo (listOf package);
      default = _: [ ];
      defaultText = literalExample "_: [ ]";
      description = ''
        Coq packages that will be made available to the environment.
      '';
      example = literalExample ''
        coqPackages: with coqPackages; [ autosubst ];
      '';
    };
    rc = mkOption {
      type = types.lines;
      default = "";
      description = ''
        Commands to be prepended to any document read by Coq.
      '';
      example = ''
        Add Rec LoadPath "../my-module/" as MyModule.
      '';
    };

    # This option isn't available yet as disabling buildIde is actually heavier
    # on the user (the version without IDE is not cached by Hydra).
    # ide.enable = mkEnableOption "IDE";
  };
  config = mkIf cfg.enable {
    buildInputs = coqBuildInputs;
    aliases = {
      coqc = "${cfg.coq}/bin/coqc ${coqFlags} \\$@";
      coqide = "${cfg.coq}/bin/coqide ${coqFlags} \\$@";
      coqtop = "${cfg.coq}/bin/coqtop ${coqFlags} \\$@";
    };
  };
}