40 , enableLDAP ? false, openldap
41 , enablePrinting ? false, cups
42 , enableProfiling ? true
43 , enableMDNS ? false, avahi
44 , enableDomainController ? false, gpgme, lmdb
45 , enableRegedit ? true, ncurses
46 , enableCephFS ? false, ceph
47 , enableGlusterFS ? false, glusterfs, libuuid
48 , enableAcl ? (!stdenv.isDarwin), acl
49 , enableLibunwind ? (!stdenv.isDarwin), libunwind
50 , enablePam ? (!stdenv.isDarwin), pam
56 # samba-tool requires libxcrypt-legacy algorithms
57 python = python3Packages.python.override {
58 libxcrypt = libxcrypt-legacy;
60 wrapPython = python3Packages.wrapPython.override {
64 stdenv.mkDerivation (finalAttrs: {
69 url = "mirror://samba/pub/samba/stable/samba-${finalAttrs.version}.tar.gz";
70 hash = "sha256-+Tw69SlTQNCBBsfA3PuF5PhQV9/RRYeqiBe+sxr/iPc=";
73 outputs = [ "out" "dev" "man" ];
76 ./4.x-no-persistent-install.patch
77 ./patch-source3__libads__kerberos_keytab.c.patch
78 ./4.x-no-persistent-install-dynconfig.patch
79 ./4.x-fix-makeflags-parsing.patch
80 ./build-find-pre-built-heimdal-build-tools-in-case-of-.patch
82 # workaround for https://github.com/NixOS/nixpkgs/issues/303436
83 name = "samba-reproducible-builds.patch";
84 url = "https://gitlab.com/raboof/samba/-/commit/9995c5c234ece6888544cdbe6578d47e83dea0b5.patch";
85 hash = "sha256-TVKK/7wGsfP1pVf8o1NwazobiR8jVJCCMj/FWji3f2A=";
90 python3Packages.python
103 ] ++ optionals stdenv.isLinux [
104 buildPackages.stdenv.cc
105 ] ++ optional (stdenv.buildPlatform != stdenv.hostPlatform) samba # asn1_compile/compile_et
106 ++ optionals stdenv.isDarwin [
110 wafPath = "buildtools/bin/waf";
127 ] ++ optionals stdenv.isLinux [ liburing systemd ]
128 ++ optionals stdenv.isDarwin [ libiconv ]
129 ++ optionals enableLDAP [ openldap.dev python3Packages.markdown ]
130 ++ optionals (!enableLDAP && stdenv.isLinux) [ ldb talloc tevent ]
131 ++ optional (enablePrinting && stdenv.isLinux) cups
132 ++ optional enableMDNS avahi
133 ++ optionals enableDomainController [ gpgme lmdb python3Packages.dnspython ]
134 ++ optional enableRegedit ncurses
135 ++ optional (enableCephFS && stdenv.isLinux) (lib.getDev ceph)
136 ++ optionals (enableGlusterFS && stdenv.isLinux) [ glusterfs libuuid ]
137 ++ optional enableAcl acl
138 ++ optional enableLibunwind libunwind
139 ++ optional enablePam pam;
142 # Removes absolute paths in scripts
143 sed -i 's,/sbin/,,g' ctdb/config/functions
145 # Fix the XML Catalog Paths
146 sed -i "s,\(XML_CATALOG_FILES=\"\),\1$XML_CATALOG_FILES ,g" buildtools/wafsamba/wafsamba.py
148 patchShebangs ./buildtools/bin
152 export PKGCONFIG="$PKG_CONFIG"
153 export PYTHONHASHSEED=1
156 wafConfigureFlags = [
157 "--with-static-modules=NONE"
158 "--with-shared-modules=ALL"
161 "--localstatedir=/var"
163 ] ++ optional (!enableDomainController)
165 ++ optionals (!enableLDAP) [
168 ] ++ optionals (!enableLDAP && stdenv.isLinux) [
169 "--bundled-libraries=!ldb,!pyldb-util!talloc,!pytalloc-util,!tevent,!tdb,!pytdb"
170 ] ++ optional enableLibunwind "--with-libunwind"
171 ++ optional enableProfiling "--with-profiling-data"
172 ++ optional (!enableAcl) "--without-acl-support"
173 ++ optional (!enablePam) "--without-pam"
174 ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
175 "--bundled-libraries=!asn1_compile,!compile_et"
177 "--cross-execute=${stdenv.hostPlatform.emulator buildPackages}"
178 ] ++ optionals stdenv.buildPlatform.is32bit [
179 # By default `waf configure` spawns as many as available CPUs. On
180 # 32-bit systems with many CPUs (like `i686` chroot on `x86_64`
181 # kernel) it can easily exhaust 32-bit address space and hang up:
182 # https://github.com/NixOS/nixpkgs/issues/287339#issuecomment-1949462057
183 # https://bugs.gentoo.org/683148
184 # Limit the job count down to the minimal on system with limited address
189 # python-config from build Python gives incorrect values when cross-compiling.
190 # If python-config is not found, the build falls back to using the sysconfig
191 # module, which works correctly in all cases.
192 PYTHON_CONFIG = "/invalid";
194 pythonPath = [ python3Packages.dnspython python3Packages.markdown tdb ];
197 export MAKEFLAGS="-j $NIX_BUILD_CORES"
200 # Save asn1_compile and compile_et so they are available to run on the build
201 # platform when cross-compiling
202 postInstall = optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
204 cp bin/asn1_compile bin/compile_et "$dev/bin"
207 # Some libraries don't have /lib/samba in RPATH but need it.
208 # Use find -type f -executable -exec echo {} \; -exec sh -c 'ldd {} | grep "not found"' \;
209 # Looks like a bug in installer scripts.
211 export SAMBA_LIBS="$(find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec dirname {} \; | sort | uniq)"
212 read -r -d "" SCRIPT << EOF || true
213 [ -z "\$SAMBA_LIBS" ] && exit 1;
215 '' + lib.optionalString stdenv.isLinux ''
216 OLD_LIBS="\$(patchelf --print-rpath "\$BIN" 2>/dev/null | tr ':' '\n')";
217 ALL_LIBS="\$(echo -e "\$SAMBA_LIBS\n\$OLD_LIBS" | sort | uniq | tr '\n' ':')";
218 patchelf --set-rpath "\$ALL_LIBS" "\$BIN" 2>/dev/null || exit $?;
219 patchelf --shrink-rpath "\$BIN";
220 '' + lib.optionalString stdenv.isDarwin ''
221 install_name_tool -id \$BIN \$BIN
222 for old_rpath in \$(otool -L \$BIN | grep /private/tmp/ | awk '{print \$1}'); do
223 new_rpath=\$(find \$SAMBA_LIBS -name \$(basename \$old_rpath) | head -n 1)
224 install_name_tool -change \$old_rpath \$new_rpath \$BIN
228 find $out -type f -regex '.*\${stdenv.hostPlatform.extensions.sharedLibrary}\(\..*\)?' -exec $SHELL -c "$SCRIPT" \;
229 find $out/bin -type f -exec $SHELL -c "$SCRIPT" \;
231 # Fix PYTHONPATH for some tools
234 # Samba does its own shebang patching, but uses build Python
235 find $out/bin -type f -executable | while read file; do
236 isScript "$file" || continue
237 sed -i 's^${lib.getBin buildPackages.python3Packages.python}^${lib.getBin python}^' "$file"
241 disallowedReferences =
242 lib.optionals (buildPackages.python3Packages.python != python3Packages.python)
243 [ buildPackages.python3Packages.python ];
246 samba = nixosTests.samba;
247 pkg-config = testers.hasPkgConfigModules {
248 package = finalAttrs.finalPackage;
250 version = testers.testVersion {
251 command = "${finalAttrs.finalPackage}/bin/smbd -V";
252 package = finalAttrs.finalPackage;
257 homepage = "https://www.samba.org";
258 description = "Standard Windows interoperability suite of programs for Linux and Unix";
259 license = licenses.gpl3;
260 platforms = platforms.unix;
261 broken = enableGlusterFS;
262 maintainers = with maintainers; [ aneeshusa ];