1 { lib, stdenv, coqPackages, coq, fetchzip }@args:
2 let lib = import ./extra-lib.nix {inherit (args) lib;}; in
3 with builtins; with lib;
5 isGitHubDomain = d: match "^github.*" d != null;
6 isGitLabDomain = d: match "^gitlab.*" d != null;
11 owner ? "coq-community",
12 domain ? "github.com",
14 defaultVersion ? null,
18 extraBuildInputs ? [],
20 enableParallelBuilding ? true,
21 extraInstallFlags ? [],
24 useMelquiondRemake ? null,
27 dropDerivationAttrs ? [],
28 useDune2ifVersion ? (x: false),
33 args-to-remove = foldl (flip remove) ([
34 "version" "fetcher" "repo" "owner" "domain" "releaseRev"
35 "displayVersion" "defaultVersion" "useMelquiondRemake"
36 "release" "extraBuildInputs" "extraPropagatedBuildInputs" "namePrefix"
37 "meta" "useDune2ifVersion" "useDune2"
38 "extraInstallFlags" "setCOQBIN" "mlPlugin"
39 "dropAttrs" "dropDerivationAttrs" "keepAttrs" ] ++ dropAttrs) keepAttrs;
40 fetch = import ../coq/meta-fetch/default.nix
41 { inherit lib stdenv fetchzip; } ({
42 inherit release releaseRev;
43 location = { inherit domain owner repo; };
44 } // optionalAttrs (args?fetcher) {inherit fetcher;});
45 fetched = fetch (if !isNull version then version else defaultVersion);
46 namePrefix = args.namePrefix or [ "coq" ];
47 display-pkg = n: sep: v:
48 let d = displayVersion.${n} or (if sep == "" then ".." else true); in
49 n + optionalString (v != "" && v != null) (switch d [
50 { case = true; out = sep + v; }
51 { case = "."; out = sep + versions.major v; }
52 { case = ".."; out = sep + versions.majorMinor v; }
53 { case = "..."; out = sep + versions.majorMinorPatch v; }
54 { case = isFunction; out = optionalString (d v != "") (sep + d v); }
55 { case = isString; out = optionalString (d != "") (sep + d); }
56 ] "") + optionalString (v == null) "-broken";
57 append-version = p: n: p + display-pkg n "" coqPackages.${n}.version + "-";
58 prefix-name = foldl append-version "" namePrefix;
59 var-coqlib-install = (optionalString (versions.isGe "8.7" coq.coq-version) "COQMF_") + "COQLIB";
60 useDune2 = args.useDune2 or useDune2ifVersion fetched.version;
63 stdenv.mkDerivation (removeAttrs ({
65 name = prefix-name + (display-pkg pname "-" fetched.version);
67 inherit (fetched) version src;
70 ++ optionals mlPlugin coq.ocamlBuildInputs
71 ++ optionals useDune2 [coq.ocaml coq.ocamlPackages.dune_2]
73 inherit enableParallelBuilding;
75 meta = ({ platforms = coq.meta.platforms; } //
77 case = pred.union isGitHubDomain isGitLabDomain;
78 out = { homepage = "https://${domain}/${owner}/${repo}"; };
80 optionalAttrs (fetched.broken or false) { coqFilter = true; broken = true; }) //
84 // (optionalAttrs setCOQBIN { COQBIN = "${coq}/bin/"; })
85 // (optionalAttrs (!args?installPhase && !args?useMelquiondRemake) {
87 [ "${var-coqlib-install}=$(out)/lib/coq/${coq.coq-version}/" ] ++
88 optional (match ".*doc$" (args.installTargets or "") != null)
89 "DOCDIR=$(out)/share/coq/${coq.coq-version}/" ++
92 // (optionalAttrs useDune2 {
95 dune install --prefix=$out
96 mv $out/lib/coq $out/lib/TEMPORARY
98 mv $out/lib/TEMPORARY $out/lib/coq/${coq.coq-version}
102 // (optionalAttrs (args?useMelquiondRemake) rec {
103 COQUSERCONTRIB = "$out/lib/coq/${coq.coq-version}/user-contrib";
104 preConfigurePhases = "autoconf";
105 configureFlags = [ "--libdir=${COQUSERCONTRIB}/${useMelquiondRemake.logpath or ""}" ];
106 buildPhase = "./remake -j$NIX_BUILD_CORES";
107 installPhase = "./remake install";
109 // (removeAttrs args args-to-remove)) dropDerivationAttrs)