From 2320cdc59b51e9ec24d3e05b449fe9c3bfbd429a Mon Sep 17 00:00:00 2001 From: Rine Amakawa Date: Wed, 26 Aug 2026 00:15:07 +0900 Subject: [PATCH] samba: fix dylib linking on Darwin On Darwin, Samba embeds temporary build directory paths in the dylib install names and load commands. Previously, postFixup hardcoded a match for '/private/tmp/', which fails when sandboxing or daemon builds use different build top directories such as '/nix/var/nix/builds/...'. Fix this by: - Dynamically matching $NIX_BUILD_TOP and its canonical path. - Including Python C-extension .so modules in the search. - Only setting install_name_tool -id on shared libraries. Assisted-by: Antigravity (Gemini 3.7 Flash) --- pkgs/servers/samba/4.x.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/servers/samba/4.x.nix b/pkgs/servers/samba/4.x.nix index 7e3454207f77..6611970fb204 100644 --- a/pkgs/servers/samba/4.x.nix +++ b/pkgs/servers/samba/4.x.nix @@ -321,16 +321,27 @@ stdenv.mkDerivation (finalAttrs: { patchelf --shrink-rpath "\$BIN"; '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - install_name_tool -id \$BIN \$BIN - for old_rpath in \$(otool -L \$BIN | grep /private/tmp/ | awk '{print \$1}'); do - new_rpath=\$(find \$SAMBA_LIBS -name \$(basename \$old_rpath) | head -n 1) - install_name_tool -change \$old_rpath \$new_rpath \$BIN + if [[ "\$BIN" == *.dylib || "\$BIN" == *.so ]]; then + install_name_tool -id "\$BIN" "\$BIN" || true + fi + BUILD_TOP_CANONICAL="\$(realpath "\$NIX_BUILD_TOP" 2>/dev/null || echo "\$NIX_BUILD_TOP")" + for old_rpath in \$(otool -L "\$BIN" 2>/dev/null | awk '{print \$1}' | grep -F -e "\$NIX_BUILD_TOP" -e "\$BUILD_TOP_CANONICAL"); do + new_rpath=\$(find \$SAMBA_LIBS -name "\$(basename "\$old_rpath")" | head -n 1) + if [ -n "\$new_rpath" ]; then + install_name_tool -change "\$old_rpath" "\$new_rpath" "\$BIN" + fi done '' + '' EOF find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec $SHELL -c "$SCRIPT" \; find $out/bin -type f -exec $SHELL -c "$SCRIPT" \; + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + find $out -type f -name '*.so' -exec $SHELL -c "$SCRIPT" \; + find $out/libexec -type f -exec $SHELL -c "$SCRIPT" \; + '' + + '' # Fix PYTHONPATH for some tools wrapPythonPrograms