Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nix build on OSX #1340

Merged
merged 1 commit into from
Jan 27, 2021
Merged

Fix nix build on OSX #1340

merged 1 commit into from
Jan 27, 2021

Conversation

jmatsushita
Copy link
Contributor

cryptobox and zauth wouldn't build on OSX because the wrong path was included in the dylib.

The symptom was that the cryptobox-c haskell library build would fail with:

cryptobox-haskell                > running .stack-work/dist/x86_64-osx-nix/Cabal-3.0.1.0/build/System/CryptoBox_hsc_make failed (exit code -6)
cryptobox-haskell                > rsp file was: ".stack-work/dist/x86_64-osx-nix/Cabal-3.0.1.0/build/System/hsc2hscall42850-3.rsp"           
cryptobox-haskell                > output file:".stack-work/dist/x86_64-osx-nix/Cabal-3.0.1.0/build/System/CryptoBox.hs"                      
cryptobox-haskell                > command was: .stack-work/dist/x86_64-osx-nix/Cabal-3.0.1.0/build/System/CryptoBox_hsc_make  >.stack-work/dist/x86_64-osx-nix/Cabal-3.0.1.0/build/System/CryptoBox.hs
cryptobox-haskell                > error: dyld: Library not loaded: /private/tmp/nix-build-cryptobox-c-2019-06-17.drv-0/source/target/x86_64-apple-darwin/release/deps/libcryptobox.dylib
cryptobox-haskell                >   Referenced from: /private/tmp/stack-3f8b56a5eca0af97/cryptobox-haskell-0.1.1/.stack-work/dist/x86_64-osx-nix/Cabal-3.0.1.0/build/System/CryptoBox_hsc_make
cryptobox-haskell                >   Reason: image not found
$ otool -l /nix/store/hzj1xl80qq3xg7fxd6l3adx0ahil3pyb-cryptobox-c-2019-06-17/lib/libcryptobox.dylib
...
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 144
         name /private/tmp/nix-build-cryptobox-c-2019-06-17.drv-0/source/target/x86_64-apple-darwin/release/deps/libcryptobox.dylib (offset 24)
   time stamp 1 Thu Jan  1 01:00:01 1970
...

The fix proposed in this post fixed the problem.

$ otool -l /nix/store/w71z1pnxxx6wi69brl5pdzssdpa54yam-cryptobox-c-2019-06-17/lib/libcryptobox.dylib
...
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 120
         name /nix/store/w71z1pnxxx6wi69brl5pdzssdpa54yam-cryptobox-c-2019-06-17/lib/libcryptobox.dylib (offset 24)
   time stamp 1 Thu Jan  1 01:00:01 1970
      current version 0.0.0
...

Copy link
Member

@akshaymankar akshaymankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to my noob eyes.

@jmatsushita jmatsushita requested a review from lucendio January 26, 2021 15:08
@jmatsushita
Copy link
Contributor Author

Adding @lucendio as I heard you tried OSX Nix things before.

@@ -14,7 +14,13 @@ self: super: {
sha256 = "1i9dlhw0xk1viglyhail9fb36v1awrypps8jmhrkz8k1bhx98ci3";
};
cargoSha256 = "0zs8ibv7rinrrzp9naxd7yak7kn1gp3pjb3g8i4wf7xw2hkkq81z";

patchLibs = super.lib.optionalString super.stdenv.isDarwin ''
install_name_tool -id $out/lib/libcryptobox.dylib $out/lib/libcryptobox.dylib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this was absolutely needed? I thought it fixed itself by just bumping nixpkgs no?

The fact that buildRustPackage outputs binaries with broken paths sounds like something we should report as a bug upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was PBUK. Paths looked ok.... but not when I scrolled up. And it didn't build until I made that change.

It's a known issue apparently https://discourse.nixos.org/t/patchelf-for-mach-o-shared-libraries/562/6 there's even a hook for it fixDarwinDylibNames.

@lucendio
Copy link
Contributor

Adding @lucendio as I heard you tried OSX Nix things before.

due to my lack of experience with nix and Haskell on macos (and in general), I'm not equipped to review and give feedback.

@jmatsushita
Copy link
Contributor Author

All good @lucendio thanks!

@jmatsushita jmatsushita merged commit 30a203a into develop Jan 27, 2021
@jmatsushita jmatsushita deleted the nix-osx branch January 27, 2021 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants