From 5f40e9e178ca5ab04e7342c35193990ca638dd0f Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Tue, 3 Jan 2023 23:16:35 +0100 Subject: [PATCH] samba: add darwin support (#207465) --- pkgs/servers/samba/4.x.nix | 29 ++++++++++++++++++----------- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkgs/servers/samba/4.x.nix b/pkgs/servers/samba/4.x.nix index 46867aa19e7..df235abe98c 100644 --- a/pkgs/servers/samba/4.x.nix +++ b/pkgs/servers/samba/4.x.nix @@ -18,7 +18,6 @@ , zlib , liburing , gnutls -, libunwind , systemd , samba , jansson @@ -41,6 +40,7 @@ , enableCephFS ? false, ceph , enableGlusterFS ? false, glusterfs, libuuid , enableAcl ? (!stdenv.isDarwin), acl +, enableLibunwind ? (!stdenv.isDarwin), libunwind , enablePam ? (!stdenv.isDarwin), pam }: @@ -75,11 +75,12 @@ stdenv.mkDerivation rec { perl.pkgs.ParseYapp perl.pkgs.JSON libxslt - buildPackages.stdenv.cc docbook_xsl docbook_xml_dtd_45 cmocka rpcsvc-proto + ] ++ optionals stdenv.isLinux [ + buildPackages.stdenv.cc ] ++ optional (stdenv.buildPlatform != stdenv.hostPlatform) samba # asn1_compile/compile_et ++ optionals stdenv.isDarwin [ fixDarwinDylibNames @@ -98,7 +99,6 @@ stdenv.mkDerivation rec { libbsd libarchive zlib - libunwind gnutls libtasn1 tdb @@ -113,6 +113,7 @@ stdenv.mkDerivation rec { ++ optional (enableCephFS && stdenv.isLinux) (lib.getDev ceph) ++ optionals (enableGlusterFS && stdenv.isLinux) [ glusterfs libuuid ] ++ optional enableAcl acl + ++ optional enableLibunwind libunwind ++ optional enablePam pam; postPatch = '' @@ -133,7 +134,6 @@ stdenv.mkDerivation rec { wafConfigureFlags = [ "--with-static-modules=NONE" "--with-shared-modules=ALL" - "--with-libunwind" "--enable-fhs" "--sysconfdir=/etc" "--localstatedir=/var" @@ -143,7 +143,8 @@ stdenv.mkDerivation rec { ++ optionals (!enableLDAP) [ "--without-ldap" "--without-ads" - ] ++ optional enableProfiling "--with-profiling-data" + ] ++ optional enableLibunwind "--with-libunwind" + ++ optional enableProfiling "--with-profiling-data" ++ optional (!enableAcl) "--without-acl-support" ++ optional (!enablePam) "--without-pam" ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ @@ -175,16 +176,25 @@ stdenv.mkDerivation rec { # Use find -type f -executable -exec echo {} \; -exec sh -c 'ldd {} | grep "not found"' \; # Looks like a bug in installer scripts. postFixup = '' - export SAMBA_LIBS="$(find $out -type f -regex '.*\.so\(\..*\)?' -exec dirname {} \; | sort | uniq)" + export SAMBA_LIBS="$(find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec dirname {} \; | sort | uniq)" read -r -d "" SCRIPT << EOF || true [ -z "\$SAMBA_LIBS" ] && exit 1; BIN='{}'; + '' + lib.optionalString stdenv.isLinux '' OLD_LIBS="\$(patchelf --print-rpath "\$BIN" 2>/dev/null | tr ':' '\n')"; ALL_LIBS="\$(echo -e "\$SAMBA_LIBS\n\$OLD_LIBS" | sort | uniq | tr '\n' ':')"; patchelf --set-rpath "\$ALL_LIBS" "\$BIN" 2>/dev/null || exit $?; patchelf --shrink-rpath "\$BIN"; + '' + lib.optionalString stdenv.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 + done + '' + '' EOF - find $out -type f -regex '.*\.so\(\..*\)?' -exec $SHELL -c "$SCRIPT" \; + find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec $SHELL -c "$SCRIPT" \; + find $out/bin -type f -exec $SHELL -c "$SCRIPT" \; # Fix PYTHONPATH for some tools wrapPythonPrograms @@ -209,10 +219,7 @@ stdenv.mkDerivation rec { description = "The standard Windows interoperability suite of programs for Linux and Unix"; license = licenses.gpl3; platforms = platforms.unix; - # N.B. enableGlusterFS does not build - # TODO: darwin support needs newer SDK for "_futimens" and "_utimensat" - # see https://github.com/NixOS/nixpkgs/issues/101229 - broken = stdenv.isDarwin || enableGlusterFS; + broken = enableGlusterFS; maintainers = with maintainers; [ aneeshusa ]; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 41bc81d0a2a..2729c770182 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24794,7 +24794,7 @@ with pkgs; deadpixi-sam-unstable = callPackage ../applications/editors/deadpixi-sam { }; - samba4 = callPackage ../servers/samba/4.x.nix { }; + samba4 = darwin.apple_sdk_11_0.callPackage ../servers/samba/4.x.nix { }; samba = samba4;