You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a go binary that is built in Baze using rules_nixpkgs Go and CC toolchains. The Go binary uses cgo to link cryptsetup from nixpkgs.
The resulting binary uses an RPATH to link the top level libcryptsetup.so.12, while all transitive deps are linked with their absolute store path.
To Reproduce
Wrap a C library from nix in a cc_library
Link it with any native code (could be a cc_binary or go_binary or something else)
Run ldd on the result
Expected behavior
The resulting binary should have only absolute paths in the ldd output, since a nix store is required at runtime anyways.
Actual behavior
The top level library that I link against (libcryptsetup.so.12) uses a location relative to the binary (requiring runfiles to be shipped with the binary itself):
I'm currently thinking about using `patchelf as a postprocessing step to normalize library paths (and always use absolute paths into the nix store). Not sure if that's a good idea but it is the best I came up with so far.
As an example, I tried "repairing" the binary, by setting a working rpath:
The text was updated successfully, but these errors were encountered:
malt3
changed the title
Binaries created by using rules_nixpkgs use rpath for libraries from nix store
Binaries created using rules_nixpkgs have rpath for libraries from nix store
Nov 21, 2023
The story for deploying binaries created with rules_nixpkgs to other machines isn't great at the moment. As you say, they often depend on libraries in the Nix store. We have an open issue to document solutions to this.
Your patchelf rule is an interesting approach, but it seems like it still requires the Nix store on the target machine to have all the necessary paths? My concern is there is no way to know what these store paths are. In the past we've discussed adding an aspect to nixpkgs_package to collect the transitive closure of the store paths and write it to an output file, e.g. required-nix-paths.txt. This could then be used either to bundle all those paths as a single deployable artifact, or as an indication of what packages need to be installed on the target machine as prerequisite.
Your patchelf rule is an interesting approach, but it seems like it still requires the Nix store on the target machine to have all the necessary paths?
Yes. That's correct. I'm creating a tar of the transitive closure of required nix store paths that I can ship with the binary.
Describe the bug
I have a go binary that is built in Baze using rules_nixpkgs Go and CC toolchains. The Go binary uses cgo to link
cryptsetup
from nixpkgs.The resulting binary uses an RPATH to link the top level
libcryptsetup.so.12
, while all transitive deps are linked with their absolute store path.To Reproduce
cc_library
cc_binary
orgo_binary
or something else)ldd
on the resultExpected behavior
The resulting binary should have only absolute paths in the ldd output, since a nix store is required at runtime anyways.
Actual behavior
The top level library that I link against (
libcryptsetup.so.12
) uses a location relative to the binary (requiring runfiles to be shipped with the binary itself):rpath looks like this:
Environment
Additional context
I'm currently thinking about using `patchelf as a postprocessing step to normalize library paths (and always use absolute paths into the nix store). Not sure if that's a good idea but it is the best I came up with so far.
As an example, I tried "repairing" the binary, by setting a working rpath:
The text was updated successfully, but these errors were encountered: