Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / coq-modules / metacoq / default.nix
blobb61b729eb4753f803e893e92fc49214cd845ca9b
1 { lib, fetchzip,
2   mkCoqDerivation, recurseIntoAttrs,  single ? false,
3   coqPackages, coq, equations, version ? null }@args:
4 with builtins // lib;
5 let
6   repo  = "metacoq";
7   owner = "MetaCoq";
8   defaultVersion = with versions; lib.switch coq.coq-version [
9       { case = "8.11"; out = "1.0-beta2-8.11"; }
10       { case = "8.12"; out = "1.0-beta2-8.12"; }
11       # Do not provide 8.13 because it does not compile with equations 1.3 provided by default (only 1.2.3)
12       # { case = "8.13"; out = "1.0-beta2-8.13"; }
13       { case = "8.14"; out = "1.1-8.14"; }
14       { case = "8.15"; out = "1.1-8.15"; }
15       { case = "8.16"; out = "1.1-8.16"; }
16     ] null;
17   release = {
18     "1.0-beta2-8.11".sha256 = "sha256-I9YNk5Di6Udvq5/xpLSNflfjRyRH8fMnRzbo3uhpXNs=";
19     "1.0-beta2-8.12".sha256 = "sha256-I8gpmU9rUQJh0qfp5KOgDNscVvCybm5zX4TINxO1TVA=";
20     "1.0-beta2-8.13".sha256 = "sha256-IC56/lEDaAylUbMCfG/3cqOBZniEQk8jmI053DBO5l8=";
21     "1.0-8.14".sha256 = "sha256-iRnaNeHt22JqxMNxOGPPycrO9EoCVjusR2s0GfON1y0=";
22     "1.0-8.15".sha256 = "sha256-8RUC5dHNfLJtJh+IZG4nPTAVC8ZKVh2BHedkzjwLf/k=";
23     "1.0-8.16".sha256 = "sha256-7rkCAN4PNnMgsgUiiLe2TnAliknN75s2SfjzyKCib/o=";
24     "1.1-8.14".sha256 = "sha256-6vViCNQl6BnGgOHX3P/OLfFXN4aUfv4RbDokfz2BgQI=";
25     "1.1-8.15".sha256 = "sha256-qCD3wFW4E+8vSVk4XoZ0EU4PVya0al+JorzS9nzmR/0=";
26     "1.1-8.16".sha256 = "sha256-cTK4ptxpPPlqxAhasZFX3RpSlsoTZwhTqs2A3BZy9sA=";
27   };
28   releaseRev = v: "v${v}";
30   # list of core metacoq packages sorted by dependency order
31   packages = [ "template-coq" "pcuic" "safechecker" "erasure" "all" ];
33   template-coq = metacoq_ "template-coq";
35   metacoq_ = package: let
36       metacoq-deps = lib.optionals (package != "single") (map metacoq_ (head (splitList (lib.pred.equal package) packages)));
37       pkgpath = if package == "single" then "./" else "./${package}";
38       pname = if package == "all" then "metacoq" else "metacoq-${package}";
39       pkgallMake = ''
40           mkdir all
41           echo "all:" > all/Makefile
42           echo "install:" >> all/Makefile
43         '' ;
44       derivation = (mkCoqDerivation ({
45         inherit version pname defaultVersion release releaseRev repo owner;
47         mlPlugin = true;
48         propagatedBuildInputs = [ equations coq.ocamlPackages.zarith ] ++ metacoq-deps;
50         patchPhase =  ''
51           patchShebangs ./configure.sh
52           patchShebangs ./template-coq/update_plugin.sh
53           patchShebangs ./template-coq/gen-src/to-lower.sh
54           patchShebangs ./pcuic/clean_extraction.sh
55           patchShebangs ./safechecker/clean_extraction.sh
56           patchShebangs ./erasure/clean_extraction.sh
57           echo "CAMLFLAGS+=-w -60 # Unused module" >> ./safechecker/Makefile.plugin.local
58           sed -i -e 's/mv $i $newi;/mv $i tmp; mv tmp $newi;/' ./template-coq/gen-src/to-lower.sh ./pcuic/clean_extraction.sh ./safechecker/clean_extraction.sh ./erasure/clean_extraction.sh
59         '' ;
61         configurePhase = optionalString (package == "all") pkgallMake + ''
62           touch ${pkgpath}/metacoq-config
63         '' + optionalString (elem package ["safechecker" "erasure"]) ''
64           echo  "-I ${template-coq}/lib/coq/${coq.coq-version}/user-contrib/MetaCoq/Template/" > ${pkgpath}/metacoq-config
65         '' + optionalString (package == "single") ''
66           ./configure.sh local
67         '';
69         preBuild = ''
70           cd ${pkgpath}
71         '' ;
73         meta = {
74           homepage    = "https://metacoq.github.io/";
75           license     = licenses.mit;
76           maintainers = with maintainers; [ cohencyril ];
77         };
78       } // optionalAttrs (package != "single")
79         { passthru = genAttrs packages metacoq_; })
80       ).overrideAttrs (o:
81         let requiresOcamlStdlibShims = versionAtLeast o.version "1.0-8.16" ||
82                                        (o.version == "dev" && (versionAtLeast coq.coq-version "8.16" || coq.coq-version == "dev")) ;
83         in
84           {
85             propagatedBuildInputs = o.propagatedBuildInputs ++ optional requiresOcamlStdlibShims coq.ocamlPackages.stdlib-shims;
86           });
87   in derivation;
89 metacoq_ (if single then "single" else "all")