1diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs
2index 73a533b5..408ab815 100644
3--- a/src/dist/component/package.rs
4+++ b/src/dist/component/package.rs
5@@ -113,6 +113,7 @@ fn install<'a>(
6 } else {
7 builder.move_file(path.clone(), &src_path)?
8 }
9+ nix_patchelf_if_needed(&target.prefix().path().join(path.clone()), &src_path)
10 }
11 "dir" => {
12 if self.copy {
13@@ -135,6 +136,29 @@ fn components(&self) -> Vec<String> {
14 }
15 }
16
17+fn nix_patchelf_if_needed(dest_path: &Path, src_path: &Path) {
18+ let (is_bin, is_lib) = if let Some(p) = src_path.parent() {
19+ (p.ends_with("bin") || p.ends_with("libexec"), p.ends_with("lib"))
20+ } else {
21+ (false, false)
22+ };
23+
24+ if is_bin {
25+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
26+ .arg("--set-interpreter")
27+ .arg("@dynamicLinker@")
28+ .arg(dest_path)
29+ .output();
30+ }
31+ else if is_lib {
32+ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf")
33+ .arg("--set-rpath")
34+ .arg("@libPath@")
35+ .arg(dest_path)
36+ .output();
37+ }
38+}
39+
40 #[derive(Debug)]
41 pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
42