summary refs log tree commit diff
path: root/pkgs/build-support/coq/default.nix
diff options
context:
space:
mode:
authorCyril Cohen <cohen@crans.org>2020-08-28 23:05:46 +0200
committerVincent Laporte <vbgl@users.noreply.github.com>2021-01-09 11:56:17 +0100
commit9ffd16b3850536094ca36bc31520bb15a6d5a9ef (patch)
treea837e242f85684e721a9d5fa65d1de869a559e11 /pkgs/build-support/coq/default.nix
parent04065a73547d3c93a25225531ee1e9d9642ff761 (diff)
downloadnixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.tar
nixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.tar.gz
nixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.tar.bz2
nixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.tar.lz
nixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.tar.xz
nixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.tar.zst
nixpkgs-9ffd16b3850536094ca36bc31520bb15a6d5a9ef.zip
coqPackages: refactor
Diffstat (limited to 'pkgs/build-support/coq/default.nix')
-rw-r--r--pkgs/build-support/coq/default.nix92
1 files changed, 92 insertions, 0 deletions
diff --git a/pkgs/build-support/coq/default.nix b/pkgs/build-support/coq/default.nix
new file mode 100644
index 00000000000..7e925e2473e
--- /dev/null
+++ b/pkgs/build-support/coq/default.nix
@@ -0,0 +1,92 @@
+{ lib, stdenv, coqPackages, coq, fetchzip }@args:
+let lib = import ./extra-lib.nix {inherit (args) lib;}; in
+with builtins; with lib;
+let
+  isGitHubDomain = d: match "^github.*" d != null;
+  isGitLabDomain = d: match "^gitlab.*" d != null;
+in
+{ pname,
+  version ? null,
+  fetcher ? null,
+  owner ? "coq-community",
+  domain ? "github.com",
+  repo ? pname,
+  defaultVersion ? null,
+  releaseRev ? (v: v),
+  displayVersion ? {},
+  release ? {},
+  extraBuildInputs ? [],
+  namePrefix ? [],
+  enableParallelBuilding ? true,
+  extraInstallFlags ? [],
+  setCOQBIN ? true,
+  mlPlugin ? false,
+  useMelquiondRemake ? null,
+  dropAttrs ? [],
+  keepAttrs ? [],
+  dropDerivationAttrs ? [],
+  ...
+}@args:
+let
+  args-to-remove = foldl (flip remove) ([
+    "version" "fetcher" "repo" "owner" "domain" "releaseRev"
+    "displayVersion" "defaultVersion" "useMelquiondRemake"
+    "release" "extraBuildInputs" "extraPropagatedBuildInputs" "namePrefix" "meta"
+    "extraInstallFlags" "setCOQBIN" "mlPlugin"
+    "dropAttrs" "dropDerivationAttrs" "keepAttrs" ] ++ dropAttrs) keepAttrs;
+  fetch = import ../coq/meta-fetch/default.nix
+    { inherit stdenv fetchzip; } ({
+      inherit release releaseRev;
+      location = { inherit domain owner repo; };
+    } // optionalAttrs (args?fetcher) {inherit fetcher;});
+  fetched = fetch (if !isNull version then version else defaultVersion);
+  namePrefix = args.namePrefix or [ "coq" ];
+  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;
+  var-coqlib-install = (optionalString (versions.isGe "8.7" coq.coq-version) "COQMF_") + "COQLIB";
+in
+
+stdenv.mkDerivation (removeAttrs ({
+
+  name = prefix-name + (display-pkg pname "-" fetched.version);
+
+  inherit (fetched) version src;
+
+  buildInputs = [ coq ] ++ optionals mlPlugin coq.ocamlBuildInputs ++ extraBuildInputs;
+  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 {}) ;
+
+} //
+(optionalAttrs setCOQBIN { COQBIN = "${coq}/bin/"; }) //
+(optionalAttrs (!args?installPhase && !args?useMelquiondRemake) {
+  installFlags =
+    [ "${var-coqlib-install}=$(out)/lib/coq/${coq.coq-version}/" ] ++
+    optional (match ".*doc$" (args.installTargets or "") != null)
+      "DOCDIR=$(out)/share/coq/${coq.coq-version}/" ++
+    extraInstallFlags;
+}) //
+(optionalAttrs (args?useMelquiondRemake) rec {
+  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";
+}) //
+(removeAttrs args args-to-remove)) dropDerivationAttrs)