Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 367 lines 10 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPackages, 5 fetchurl, 6 fetchpatch, 7 wafHook, 8 pkg-config, 9 bison, 10 flex, 11 perl, 12 libxslt, 13 docbook_xsl, 14 fixDarwinDylibNames, 15 docbook_xml_dtd_45, 16 readline, 17 popt, 18 dbus, 19 libbsd, 20 libarchive, 21 zlib, 22 liburing, 23 gnutls, 24 systemd, 25 samba, 26 talloc, 27 jansson, 28 ldb, 29 libtasn1, 30 tdb, 31 tevent, 32 libxcrypt, 33 libxcrypt-legacy, 34 cmocka, 35 rpcsvc-proto, 36 bash, 37 python3Packages, 38 nixosTests, 39 libiconv, 40 testers, 41 pkgsCross, 42 43 enableLDAP ? false, 44 openldap, 45 enablePrinting ? false, 46 cups, 47 enableProfiling ? true, 48 enableMDNS ? false, 49 avahi, 50 enableDomainController ? false, 51 gpgme, 52 lmdb, 53 enableRegedit ? true, 54 ncurses, 55 enableCephFS ? false, 56 ceph, 57 enableGlusterFS ? false, 58 glusterfs, 59 libuuid, 60 enableAcl ? stdenv.hostPlatform.isLinux, 61 acl, 62 enableLibunwind ? (!stdenv.hostPlatform.isDarwin), 63 libunwind, 64 enablePam ? (!stdenv.hostPlatform.isDarwin), 65 pam, 66}: 67 68let 69 # samba-tool requires libxcrypt-legacy algorithms 70 python = python3Packages.python.override { 71 self = python; 72 libxcrypt = libxcrypt-legacy; 73 }; 74 wrapPython = python3Packages.wrapPython.override { 75 inherit python; 76 }; 77 78 inherit (lib) optional optionals; 79 80 needsAnswers = 81 stdenv.hostPlatform != stdenv.buildPlatform 82 && !(stdenv.hostPlatform.emulatorAvailable buildPackages); 83 answers = 84 { 85 x86_64-freebsd = ./answers-x86_64-freebsd; 86 } 87 .${stdenv.hostPlatform.system} 88 or (throw "Need pre-generated answers file to compile for ${stdenv.hostPlatform.system}"); 89in 90stdenv.mkDerivation (finalAttrs: { 91 pname = "samba"; 92 version = "4.20.8"; 93 94 src = fetchurl { 95 url = "https://download.samba.org/pub/samba/stable/samba-${finalAttrs.version}.tar.gz"; 96 hash = "sha256-db4OjTH0UBPpsmD+fPMEo20tgSg5GRR3JXchXsFzqAc="; 97 }; 98 99 outputs = [ 100 "out" 101 "dev" 102 "man" 103 ]; 104 105 patches = [ 106 ./4.x-no-persistent-install.patch 107 ./patch-source3__libads__kerberos_keytab.c.patch 108 ./4.x-no-persistent-install-dynconfig.patch 109 ./4.x-fix-makeflags-parsing.patch 110 ./build-find-pre-built-heimdal-build-tools-in-case-of-.patch 111 (fetchpatch { 112 # workaround for https://github.com/NixOS/nixpkgs/issues/303436 113 name = "samba-reproducible-builds.patch"; 114 url = "https://gitlab.com/raboof/samba/-/commit/9995c5c234ece6888544cdbe6578d47e83dea0b5.patch"; 115 hash = "sha256-TVKK/7wGsfP1pVf8o1NwazobiR8jVJCCMj/FWji3f2A="; 116 }) 117 (fetchpatch { 118 name = "cross-compile.patch"; 119 url = "https://gitlab.com/samba-team/samba/-/merge_requests/3990/diffs.patch?commit_id=52af20db81f24cbfaa6fef8233584fc40fc72d34"; 120 hash = "sha256-GMPxM6KMtMPRljhRI+dDD2fOp+y5kpRqbjqkj19Du4Q="; 121 }) 122 ]; 123 124 nativeBuildInputs = [ 125 python3Packages.python 126 wafHook 127 pkg-config 128 bison 129 flex 130 perl 131 perl.pkgs.ParseYapp 132 perl.pkgs.JSON 133 libxslt 134 docbook_xsl 135 docbook_xml_dtd_45 136 cmocka 137 rpcsvc-proto 138 ] 139 ++ optionals stdenv.hostPlatform.isLinux [ 140 buildPackages.stdenv.cc 141 ] 142 ++ optional (stdenv.buildPlatform != stdenv.hostPlatform) samba # asn1_compile/compile_et 143 ++ optionals stdenv.hostPlatform.isDarwin [ 144 fixDarwinDylibNames 145 ]; 146 147 wafPath = "buildtools/bin/waf"; 148 149 buildInputs = [ 150 bash 151 wrapPython 152 python 153 readline 154 popt 155 dbus 156 jansson 157 libarchive 158 zlib 159 gnutls 160 libtasn1 161 tdb 162 libxcrypt 163 ] 164 ++ optionals (!stdenv.hostPlatform.isBSD) [ 165 libbsd 166 ] 167 ++ optionals stdenv.hostPlatform.isLinux [ 168 liburing 169 systemd 170 ] 171 ++ optionals stdenv.hostPlatform.isDarwin [ libiconv ] 172 ++ optionals enableLDAP [ 173 openldap.dev 174 python3Packages.markdown 175 ] 176 ++ optionals (!enableLDAP && stdenv.hostPlatform.isLinux) [ 177 ldb 178 talloc 179 tevent 180 ] 181 ++ optional enablePrinting cups 182 ++ optional enableMDNS avahi 183 ++ optionals enableDomainController [ 184 gpgme 185 lmdb 186 python3Packages.dnspython 187 ] 188 ++ optional enableRegedit ncurses 189 ++ optional (enableCephFS && stdenv.hostPlatform.isLinux) (lib.getDev ceph) 190 ++ optionals (enableGlusterFS && stdenv.hostPlatform.isLinux) [ 191 glusterfs 192 libuuid 193 ] 194 ++ optional enableAcl acl 195 ++ optional enableLibunwind libunwind 196 ++ optional enablePam pam; 197 198 postPatch = '' 199 # Removes absolute paths in scripts 200 sed -i 's,/sbin/,,g' ctdb/config/functions 201 202 # Fix the XML Catalog Paths 203 sed -i "s,\(XML_CATALOG_FILES=\"\),\1$XML_CATALOG_FILES ,g" buildtools/wafsamba/wafsamba.py 204 205 patchShebangs ./buildtools/bin 206 '' 207 + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 208 substituteInPlace wscript source3/wscript nsswitch/wscript_build lib/replace/wscript source4/ntvfs/sysdep/wscript_configure --replace-fail 'sys.platform' '"${stdenv.hostPlatform.parsed.kernel.name}"' 209 ''; 210 211 preConfigure = '' 212 export PKGCONFIG="$PKG_CONFIG" 213 export PYTHONHASHSEED=1 214 '' 215 + lib.optionalString needsAnswers '' 216 cp ${answers} answers 217 chmod +w answers 218 ''; 219 220 env.NIX_LDFLAGS = lib.optionalString ( 221 stdenv.cc.bintools.isLLVM && lib.versionAtLeast stdenv.cc.bintools.version "17" 222 ) "--undefined-version"; 223 224 wafConfigureFlags = [ 225 "--with-static-modules=NONE" 226 "--with-shared-modules=ALL" 227 "--enable-fhs" 228 "--sysconfdir=/etc" 229 "--localstatedir=/var" 230 "--disable-rpath" 231 # otherwise third_party/waf/waflib/Tools/python.py would 232 # get the wrong pythondir from build platform python 233 "--pythondir=${placeholder "out"}/${python.sitePackages}" 234 (lib.enableFeature enablePrinting "cups") 235 ] 236 ++ optional (!enableDomainController) "--without-ad-dc" 237 ++ optionals (!enableLDAP) [ 238 "--without-ldap" 239 "--without-ads" 240 ] 241 ++ optionals (!enableLDAP && stdenv.hostPlatform.isLinux) [ 242 "--bundled-libraries=!ldb,!pyldb-util!talloc,!pytalloc-util,!tevent,!tdb,!pytdb" 243 ] 244 ++ optional enableLibunwind "--with-libunwind" 245 ++ optional enableProfiling "--with-profiling-data" 246 ++ optional (!enableAcl) "--without-acl-support" 247 ++ optional (!enablePam) "--without-pam" 248 ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) ([ 249 "--bundled-libraries=!asn1_compile,!compile_et" 250 "--cross-compile" 251 ( 252 if (stdenv.hostPlatform.emulatorAvailable buildPackages) then 253 "--cross-execute=${stdenv.hostPlatform.emulator buildPackages}" 254 else 255 "--cross-answers=answers" 256 ) 257 ]) 258 ++ optionals stdenv.buildPlatform.is32bit [ 259 # By default `waf configure` spawns as many as available CPUs. On 260 # 32-bit systems with many CPUs (like `i686` chroot on `x86_64` 261 # kernel) it can easily exhaust 32-bit address space and hang up: 262 # https://github.com/NixOS/nixpkgs/issues/287339#issuecomment-1949462057 263 # https://bugs.gentoo.org/683148 264 # Limit the job count down to the minimal on system with limited address 265 # space. 266 "--jobs 1" 267 ]; 268 269 # python-config from build Python gives incorrect values when cross-compiling. 270 # If python-config is not found, the build falls back to using the sysconfig 271 # module, which works correctly in all cases. 272 PYTHON_CONFIG = "/invalid"; 273 274 pythonPath = [ 275 python3Packages.dnspython 276 python3Packages.markdown 277 tdb 278 ]; 279 280 preBuild = '' 281 export MAKEFLAGS="-j $NIX_BUILD_CORES" 282 ''; 283 284 # Save asn1_compile and compile_et so they are available to run on the build 285 # platform when cross-compiling 286 postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' 287 mkdir -p "$dev/bin" 288 cp bin/asn1_compile bin/compile_et "$dev/bin" 289 ''; 290 291 # Some libraries don't have /lib/samba in RPATH but need it. 292 # Use find -type f -executable -exec echo {} \; -exec sh -c 'ldd {} | grep "not found"' \; 293 # Looks like a bug in installer scripts. 294 postFixup = '' 295 export SAMBA_LIBS="$(find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec dirname {} \; | sort | uniq)" 296 read -r -d "" SCRIPT << EOF || true 297 [ -z "\$SAMBA_LIBS" ] && exit 1; 298 BIN='{}'; 299 '' 300 + lib.optionalString stdenv.hostPlatform.isLinux '' 301 OLD_LIBS="\$(patchelf --print-rpath "\$BIN" 2>/dev/null | tr ':' '\n')"; 302 ALL_LIBS="\$(echo -e "\$SAMBA_LIBS\n\$OLD_LIBS" | sort | uniq | tr '\n' ':')"; 303 patchelf --set-rpath "\$ALL_LIBS" "\$BIN" 2>/dev/null || exit $?; 304 patchelf --shrink-rpath "\$BIN"; 305 '' 306 + lib.optionalString stdenv.hostPlatform.isDarwin '' 307 install_name_tool -id \$BIN \$BIN 308 for old_rpath in \$(otool -L \$BIN | grep /private/tmp/ | awk '{print \$1}'); do 309 new_rpath=\$(find \$SAMBA_LIBS -name \$(basename \$old_rpath) | head -n 1) 310 install_name_tool -change \$old_rpath \$new_rpath \$BIN 311 done 312 '' 313 + '' 314 EOF 315 find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec $SHELL -c "$SCRIPT" \; 316 find $out/bin -type f -exec $SHELL -c "$SCRIPT" \; 317 318 # Fix PYTHONPATH for some tools 319 wrapPythonPrograms 320 321 # Samba does its own shebang patching, but uses build Python 322 find $out/bin -type f -executable | while read file; do 323 isScript "$file" || continue 324 sed -i 's^${lib.getBin buildPackages.python3Packages.python}^${lib.getBin python}^' "$file" 325 done 326 ''; 327 328 disallowedReferences = lib.optionals ( 329 buildPackages.python3Packages.python != python3Packages.python 330 ) [ buildPackages.python3Packages.python ]; 331 332 passthru.tests = { 333 samba = nixosTests.samba; 334 cross = pkgsCross.aarch64-multiplatform.samba; 335 pkg-config = testers.hasPkgConfigModules { 336 package = finalAttrs.finalPackage; 337 }; 338 version = testers.testVersion { 339 command = "${finalAttrs.finalPackage}/bin/smbd -V"; 340 package = finalAttrs.finalPackage; 341 }; 342 }; 343 344 meta = with lib; { 345 homepage = "https://www.samba.org"; 346 description = "Standard Windows interoperability suite of programs for Linux and Unix"; 347 license = licenses.gpl3; 348 platforms = platforms.unix; 349 broken = enableGlusterFS; 350 maintainers = with maintainers; [ aneeshusa ]; 351 pkgConfigModules = [ 352 "dcerpc_samr" 353 "dcerpc" 354 "ndr_krb5pac" 355 "ndr_nbt" 356 "ndr_standard" 357 "ndr" 358 "netapi" 359 "samba-credentials" 360 "samba-hostconfig" 361 "samba-util" 362 "samdb" 363 "smbclient" 364 "wbclient" 365 ]; 366 }; 367})