From 6043e3af4ec34a42d1f45620527eb3081e5b564a Mon Sep 17 00:00:00 2001 From: Guillaume Girol Date: Sun, 11 Dec 2022 12:00:00 +0000 Subject: [PATCH] ocamlPackages.findlib: detect conflicts of version early just like pythonCatchConflictHook --- doc/languages-frameworks/ocaml.section.md | 5 +++++ pkgs/development/tools/ocaml/findlib/default.nix | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/languages-frameworks/ocaml.section.md b/doc/languages-frameworks/ocaml.section.md index 347b2ea2eca..1e5a5cb4536 100644 --- a/doc/languages-frameworks/ocaml.section.md +++ b/doc/languages-frameworks/ocaml.section.md @@ -129,3 +129,8 @@ packaged libraries may still use the old spelling: maintainers are invited to fix this when updating packages. Massive renaming is strongly discouraged as it would be challenging to review, difficult to test, and will cause unnecessary rebuild. + +The build will automatically fail if two distinct versions of the same library +are added to `buildInputs` (which usually happens transitively because of +`propagatedBuildInputs`). Set `dontDetectOcamlConflicts` to true to disable this +behavior. diff --git a/pkgs/development/tools/ocaml/findlib/default.nix b/pkgs/development/tools/ocaml/findlib/default.nix index 51df81cea5e..f48ce5abf3f 100644 --- a/pkgs/development/tools/ocaml/findlib/default.nix +++ b/pkgs/development/tools/ocaml/findlib/default.nix @@ -44,6 +44,15 @@ stdenv.mkDerivation rec { mkdir -p $OCAMLFIND_DESTDIR fi } + detectOcamlConflicts () { + local conflict + conflict="$(ocamlfind list |& grep "has multiple definitions" || true)" + if [[ -n "$conflict" ]]; then + echo "Conflicting ocaml packages detected"; + echo "$conflict" + exit 1 + fi + } # run for every buildInput addEnvHooks "$targetOffset" addOCamlPath @@ -51,6 +60,10 @@ stdenv.mkDerivation rec { preInstallHooks+=(createOcamlDestDir) # run even in nix-shell, and even without buildInputs addEnvHooks "$hostOffset" exportOcamlDestDir + # runs after all calls to addOCamlPath + if [[ -z "''${dontDetectOcamlConflicts-}" ]]; then + postHooks+=("detectOcamlConflicts") + fi ''; meta = {