Rust / ffi call to `dispatch_async` crashes when built with nix

I realize this is pretty niche, but I’m still tinkering on this old issue: espanso: runtime crash on aarch64-darwin · Issue #247162 · NixOS/nixpkgs · GitHub

espanso code works fine when compiled via cargo on my mac (aarch64-darwin), but crashes when I run a version compiled through nix (verified on a second machine).

As per my comment here, I think I’ve finally narrowed the crash down; rust makes an unsafe call to this objective c code, which crashes on dispatch_async at this line.

Is there some reason that nix would present a problem using FFI in this way? It seems to load the FFI module fine (verified with inserting some debug prints) and runs all the way up to the dispatch_async line, but a debug print even at the first line of that block fails to print (in contrast it prints fine from inside this block when compiled as usual on the host with cargo build).

I realize nix + darwin is already pretty niche, and the intersection of nix + darwin + rust + ffi + objc is probably relatively small, but if anyone has ideas or pointers I’d greatly appreciate it, I think I’m out of ideas at this point.

Looks like an upstream issue due to missing return value in a void * function: espanso: runtime crash on aarch64-darwin · Issue #247162 · NixOS/nixpkgs · GitHub

Does anyone know why this doesn’t seem to produce an issue when compiled with cargo build, but gives a runtime crash when compiled with nix?