3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/build-support/ocaml/dune.nix
2021-03-07 12:07:14 +01:00

41 lines
1.1 KiB
Nix

{ lib, stdenv, ocaml, findlib, dune_1, dune_2 }:
{ pname, version, buildInputs ? [], enableParallelBuilding ? true, ... }@args:
let Dune = if args.useDune2 or false then dune_2 else dune_1; in
if args ? minimumOCamlVersion &&
! lib.versionAtLeast ocaml.version args.minimumOCamlVersion
then throw "${pname}-${version} is not available for OCaml ${ocaml.version}"
else
stdenv.mkDerivation ({
inherit enableParallelBuilding;
buildPhase = ''
runHook preBuild
dune build -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';
checkPhase = ''
runHook preCheck
dune runtest -p ${pname} ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postCheck
'';
installPhase = ''
runHook preInstall
dune install --prefix $out --libdir $OCAMLFIND_DESTDIR ${pname}
runHook postInstall
'';
} // args // {
name = "ocaml${ocaml.version}-${pname}-${version}";
buildInputs = [ ocaml Dune findlib ] ++ buildInputs;
meta = (args.meta or {}) // { platforms = args.meta.platforms or ocaml.meta.platforms; };
})