tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
111 stars 33 forks source link

Failed to build the dune template on macOS: `symbols not found` #83

Closed mistzzt closed 8 months ago

mistzzt commented 8 months ago

Hi,

I configured a freshly initialized dune project (by dune init proj) with opam-nix. I can build it successfully in an arm NixOS VM, but I failed building it under an apple silicon mac (I tried both architectures, x86_64 and aarch64). I've uploaded the dune project and flake here: https://github.com/mistzzt/minimal-opam-nix-example

Also, below are the relevant error messages. I have no idea what to try next -- any suggestion would be appreciated.

$ nix build
error: builder for '/nix/store/99jv7xb5skyg4m1vh7lh369517dgp63g-opam-2.1.5.drv' failed with exit code 2;
       last 10 log lines:
       >       ml2c_property(Virtual_packages*, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, CUDFProperty*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, CUDFProperty*>>>*, long) in libmccs_stubs.a(mccs_stubs.o)
       >       ml2c_package(Virtual_packages*, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, CUDFProperty*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, CUDFProperty*>>>*, int&, long) in libmccs_stubs.a(mccs_stubs.o)
       >       ml2c_propertydef(Virtual_packages*, long) in libmccs_stubs.a(mccs_stubs.o)
       >       ml2c_propertydeflist(Virtual_packages*, long) in libmccs_stubs.a(mccs_stubs.o)
       >       ...
       > ld: symbol(s) not found for architecture arm64
       > clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       > File "caml_startup", line 1:
       > Error: Error during linking (exit code 1)
       > make: *** [Makefile:135: build-opam] Error 1
       For full logs, run 'nix log /nix/store/99jv7xb5skyg4m1vh7lh369517dgp63g-opam-2.1.5.drv'.
error:
       … while evaluating the attribute 'packages.aarch64-darwin.test2'

         at /nix/store/fcnzp53fbzryz8igkx787vp1zfp0nfac-source/flake.nix:30:7:

           29|     in {
           30|       test2 =
             |       ^
           31|         (buildDuneProject {} "test2" ./. {

       … while calling the 'foldl'' builtin

         at /nix/store/dqf6f40n3dxhx1cxbdza1lalncpyy8cl-source/lib/trivial.nix:63:8:

           62|     let reverseApply = x: f: f x;
           63|     in builtins.foldl' reverseApply val functions;
             |        ^
           64|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: 1 dependencies of derivation '/nix/store/vgmj1z4dl2n3wwq5hvvrs9ssx5a9vxxf-resolve.drv' failed to build
$ nix log /nix/store/99jv7xb5skyg4m1vh7lh369517dgp63g-opam-2.1.5.drv
...
  "___gxx_personality_v0", referenced from:
      ml2c_vpkg(Virtual_packages*, long) in libmccs_stubs.a(mccs_stubs.o)
      Virtual_packages::get(char const*) in libmccs_stubs.a(mccs_stubs.o)
      ml2c_vpkglist(Virtual_packages*, long) in libmccs_stubs.a(mccs_stubs.o)
      ml2c_property(Virtual_packages*, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, CUDFProperty*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, >
      ml2c_package(Virtual_packages*, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, CUDFProperty*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, s>
      ml2c_propertydef(Virtual_packages*, long) in libmccs_stubs.a(mccs_stubs.o)
      ml2c_propertydeflist(Virtual_packages*, long) in libmccs_stubs.a(mccs_stubs.o)
      ...
ld: symbol(s) not found for architecture arm64
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking (exit code 1)
$ nix --version
nix (Nix) 2.18.1

$ uname -a
Darwin symmetry 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64 arm Darwin

Thanks!

balsoft commented 8 months ago

I'll check it out. My suspicion is that the opam build might be broken on macOS in nixpkgs? I don't see any other reason for this to fail.

balsoft commented 8 months ago

Looks like this is indeed the case, as nix build github:nixos/nixpkgs/ebbe1c1299faf63fffdf1e2a6ebfe43c56b2e691#opam fails with the same error. Removing the overrides like this:

diff --git a/flake.nix b/flake.nix
index 9b8d389..ee98fb1 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,10 +2,11 @@
   description = "minimal opam-nix example";

   inputs = {
-    nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
+#    nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
+    nixpkgs.follows = "opam-nix/nixpkgs";
     opam-nix = {
       url = "github:tweag/opam-nix";
-      inputs.nixpkgs.follows = "nixpkgs";
+#      inputs.nixpkgs.follows = "nixpkgs";
     };
   };

Results in a different error

balsoft commented 8 months ago

... And that error should be fixed in 0f771d647c0dd2b2880533646e8d86a422895b17. Could you check?

mistzzt commented 8 months ago

It works great now. @balsoft Thank you!