2021-02-19 19:34:30 +01:00
|
|
|
{ lib, stdenv, coqPackages, coq, which, fetchzip }@args:
|
2024-03-14 16:59:54 +01:00
|
|
|
|
2020-08-28 23:05:46 +02:00
|
|
|
let
|
2024-03-14 16:59:54 +01:00
|
|
|
lib = import ./extra-lib.nix {
|
|
|
|
inherit (args) lib;
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit (lib)
|
|
|
|
concatStringsSep
|
|
|
|
flip
|
|
|
|
foldl
|
|
|
|
isFunction
|
|
|
|
isString
|
|
|
|
optional
|
|
|
|
optionalAttrs
|
|
|
|
optionals
|
|
|
|
optionalString
|
|
|
|
pred
|
|
|
|
remove
|
|
|
|
switch
|
|
|
|
versions
|
|
|
|
;
|
|
|
|
|
|
|
|
inherit (lib.attrsets) removeAttrs;
|
|
|
|
inherit (lib.strings) match;
|
|
|
|
|
2020-08-28 23:05:46 +02:00
|
|
|
isGitHubDomain = d: match "^github.*" d != null;
|
|
|
|
isGitLabDomain = d: match "^gitlab.*" d != null;
|
|
|
|
in
|
2024-03-14 16:59:54 +01:00
|
|
|
|
2020-08-28 23:05:46 +02:00
|
|
|
{ pname,
|
|
|
|
version ? null,
|
|
|
|
fetcher ? null,
|
|
|
|
owner ? "coq-community",
|
|
|
|
domain ? "github.com",
|
|
|
|
repo ? pname,
|
|
|
|
defaultVersion ? null,
|
|
|
|
releaseRev ? (v: v),
|
|
|
|
displayVersion ? {},
|
|
|
|
release ? {},
|
2021-02-19 19:34:30 +01:00
|
|
|
buildInputs ? [],
|
|
|
|
nativeBuildInputs ? [],
|
2020-08-28 23:05:46 +02:00
|
|
|
extraBuildInputs ? [],
|
2022-02-24 15:01:15 +01:00
|
|
|
extraNativeBuildInputs ? [],
|
2021-02-19 19:34:30 +01:00
|
|
|
overrideBuildInputs ? [],
|
|
|
|
overrideNativeBuildInputs ? [],
|
2021-09-07 14:44:40 +02:00
|
|
|
namePrefix ? [ "coq" ],
|
2020-08-28 23:05:46 +02:00
|
|
|
enableParallelBuilding ? true,
|
|
|
|
extraInstallFlags ? [],
|
|
|
|
setCOQBIN ? true,
|
|
|
|
mlPlugin ? false,
|
|
|
|
useMelquiondRemake ? null,
|
|
|
|
dropAttrs ? [],
|
|
|
|
keepAttrs ? [],
|
|
|
|
dropDerivationAttrs ? [],
|
2022-10-01 16:42:29 +02:00
|
|
|
useDuneifVersion ? (x: false),
|
|
|
|
useDune ? false,
|
2021-09-07 14:44:40 +02:00
|
|
|
opam-name ? (concatStringsSep "-" (namePrefix ++ [ pname ])),
|
2020-08-28 23:05:46 +02:00
|
|
|
...
|
|
|
|
}@args:
|
|
|
|
let
|
|
|
|
args-to-remove = foldl (flip remove) ([
|
|
|
|
"version" "fetcher" "repo" "owner" "domain" "releaseRev"
|
|
|
|
"displayVersion" "defaultVersion" "useMelquiondRemake"
|
2021-02-19 19:34:30 +01:00
|
|
|
"release"
|
|
|
|
"buildInputs" "nativeBuildInputs"
|
|
|
|
"extraBuildInputs" "extraNativeBuildInputs"
|
|
|
|
"overrideBuildInputs" "overrideNativeBuildInputs"
|
|
|
|
"namePrefix"
|
2022-10-01 16:42:29 +02:00
|
|
|
"meta" "useDuneifVersion" "useDune" "opam-name"
|
2020-08-28 23:05:46 +02:00
|
|
|
"extraInstallFlags" "setCOQBIN" "mlPlugin"
|
|
|
|
"dropAttrs" "dropDerivationAttrs" "keepAttrs" ] ++ dropAttrs) keepAttrs;
|
|
|
|
fetch = import ../coq/meta-fetch/default.nix
|
2021-01-27 11:21:31 +01:00
|
|
|
{ inherit lib stdenv fetchzip; } ({
|
2020-08-28 23:05:46 +02:00
|
|
|
inherit release releaseRev;
|
|
|
|
location = { inherit domain owner repo; };
|
|
|
|
} // optionalAttrs (args?fetcher) {inherit fetcher;});
|
2023-03-05 22:08:45 +01:00
|
|
|
fetched = fetch (if version != null then version else defaultVersion);
|
2020-08-28 23:05:46 +02:00
|
|
|
display-pkg = n: sep: v:
|
|
|
|
let d = displayVersion.${n} or (if sep == "" then ".." else true); in
|
|
|
|
n + optionalString (v != "" && v != null) (switch d [
|
|
|
|
{ case = true; out = sep + v; }
|
|
|
|
{ case = "."; out = sep + versions.major v; }
|
|
|
|
{ case = ".."; out = sep + versions.majorMinor v; }
|
|
|
|
{ case = "..."; out = sep + versions.majorMinorPatch v; }
|
|
|
|
{ case = isFunction; out = optionalString (d v != "") (sep + d v); }
|
|
|
|
{ case = isString; out = optionalString (d != "") (sep + d); }
|
|
|
|
] "") + optionalString (v == null) "-broken";
|
|
|
|
append-version = p: n: p + display-pkg n "" coqPackages.${n}.version + "-";
|
|
|
|
prefix-name = foldl append-version "" namePrefix;
|
2022-10-01 16:42:29 +02:00
|
|
|
useDune = args.useDune or (useDuneifVersion fetched.version);
|
2021-02-19 19:34:30 +01:00
|
|
|
coqlib-flags = switch coq.coq-version [
|
|
|
|
{ case = v: versions.isLe "8.6" v && v != "dev" ;
|
|
|
|
out = [ "COQLIB=$(out)/lib/coq/${coq.coq-version}/" ]; }
|
|
|
|
] [ "COQLIBINSTALL=$(out)/lib/coq/${coq.coq-version}/user-contrib"
|
|
|
|
"COQPLUGININSTALL=$(OCAMLFIND_DESTDIR)" ];
|
|
|
|
docdir-flags = switch coq.coq-version [
|
|
|
|
{ case = v: versions.isLe "8.6" v && v != "dev";
|
|
|
|
out = [ "DOCDIR=$(out)/share/coq/${coq.coq-version}/" ]; }
|
|
|
|
] [ "COQDOCINSTALL=$(out)/share/coq/${coq.coq-version}/user-contrib" ];
|
2020-08-28 23:05:46 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation (removeAttrs ({
|
|
|
|
|
|
|
|
name = prefix-name + (display-pkg pname "-" fetched.version);
|
|
|
|
|
|
|
|
inherit (fetched) version src;
|
|
|
|
|
2021-02-19 19:34:30 +01:00
|
|
|
nativeBuildInputs = args.overrideNativeBuildInputs
|
2023-02-01 20:43:16 +01:00
|
|
|
or ([ which ]
|
2022-10-01 16:42:29 +02:00
|
|
|
++ optional useDune coq.ocamlPackages.dune_3
|
2023-02-01 20:43:16 +01:00
|
|
|
++ optionals (useDune || mlPlugin) [ coq.ocamlPackages.ocaml coq.ocamlPackages.findlib ]
|
2021-02-19 19:34:30 +01:00
|
|
|
++ (args.nativeBuildInputs or []) ++ extraNativeBuildInputs);
|
|
|
|
buildInputs = args.overrideBuildInputs
|
|
|
|
or ([ coq ] ++ (args.buildInputs or []) ++ extraBuildInputs);
|
2020-08-28 23:05:46 +02:00
|
|
|
inherit enableParallelBuilding;
|
|
|
|
|
|
|
|
meta = ({ platforms = coq.meta.platforms; } //
|
|
|
|
(switch domain [{
|
|
|
|
case = pred.union isGitHubDomain isGitLabDomain;
|
|
|
|
out = { homepage = "https://${domain}/${owner}/${repo}"; };
|
|
|
|
}] {}) //
|
|
|
|
optionalAttrs (fetched.broken or false) { coqFilter = true; broken = true; }) //
|
|
|
|
(args.meta or {}) ;
|
|
|
|
|
2021-03-10 16:25:32 +01:00
|
|
|
}
|
|
|
|
// (optionalAttrs setCOQBIN { COQBIN = "${coq}/bin/"; })
|
|
|
|
// (optionalAttrs (!args?installPhase && !args?useMelquiondRemake) {
|
2020-08-28 23:05:46 +02:00
|
|
|
installFlags =
|
2022-06-18 10:56:48 +02:00
|
|
|
coqlib-flags ++ docdir-flags ++
|
2020-08-28 23:05:46 +02:00
|
|
|
extraInstallFlags;
|
2021-03-10 16:25:32 +01:00
|
|
|
})
|
2022-10-01 16:42:29 +02:00
|
|
|
// (optionalAttrs useDune {
|
2021-08-16 22:38:17 +02:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
dune build -p ${opam-name} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
2021-03-10 16:25:32 +01:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2021-08-16 22:38:17 +02:00
|
|
|
dune install ${opam-name} --prefix=$out
|
2021-03-10 16:25:32 +01:00
|
|
|
mv $out/lib/coq $out/lib/TEMPORARY
|
|
|
|
mkdir $out/lib/coq/
|
|
|
|
mv $out/lib/TEMPORARY $out/lib/coq/${coq.coq-version}
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
// (optionalAttrs (args?useMelquiondRemake) rec {
|
2020-08-28 23:05:46 +02:00
|
|
|
COQUSERCONTRIB = "$out/lib/coq/${coq.coq-version}/user-contrib";
|
|
|
|
preConfigurePhases = "autoconf";
|
|
|
|
configureFlags = [ "--libdir=${COQUSERCONTRIB}/${useMelquiondRemake.logpath or ""}" ];
|
|
|
|
buildPhase = "./remake -j$NIX_BUILD_CORES";
|
|
|
|
installPhase = "./remake install";
|
2021-03-10 16:25:32 +01:00
|
|
|
})
|
|
|
|
// (removeAttrs args args-to-remove)) dropDerivationAttrs)
|