99 sqlite ,
1010 foundationdb ,
1111 zstd ,
12+ rust-jemalloc-sys-unprefixed ,
1213 stdenv ,
1314 nix-update-script ,
1415 nixosTests ,
1819 stalwartEnterprise ? false ,
1920} :
2021
22+ let
23+ rocksdbJemalloc = rocksdb . override { enableJemalloc = true ; } ;
24+ in
2125rustPlatform . buildRustPackage ( finalAttrs : {
2226 pname = "stalwart-mail" + ( lib . optionalString stalwartEnterprise "-enterprise" ) ;
2327 version = "0.11.8" ;
@@ -29,6 +33,17 @@ rustPlatform.buildRustPackage (finalAttrs: {
2933 hash = "sha256-VqGosbSQxNeOS+kGtvXAmz6vyz5mJlXvKZM57B1Xue4=" ;
3034 } ;
3135
36+ # rocksdb does not properly distinguish between pointers it has allocated itself
37+ # and pointers which were passed in and might be registered with a different
38+ # allocator, so we enable the unprefixed_malloc_on_supported_platforms to use
39+ # jemalloc implicitly in the entire process.
40+ postPatch = ''
41+ for file in crates/main/Cargo.toml tests/Cargo.toml; do
42+ substituteInPlace $file --replace-fail \
43+ 'jemallocator = "0.5.0"' 'jemallocator = { version = "0.5.0", features = ["unprefixed_malloc_on_supported_platforms"] }'
44+ done
45+ '' ;
46+
3247 useFetchCargoVendor = true ;
3348 cargoHash = "sha256-iheURWxO0cOvO+FV01l2Vmo0B+S2mXzue6mx3gapftQ=" ;
3449
@@ -43,6 +58,8 @@ rustPlatform.buildRustPackage (finalAttrs: {
4358 openssl
4459 sqlite
4560 zstd
61+ rust-jemalloc-sys-unprefixed
62+ rocksdbJemalloc
4663 ] ++ lib . optionals ( stdenv . hostPlatform . isLinux && withFoundationdb ) [ foundationdb ] ;
4764
4865 # Issue: https://github.com/stalwartlabs/mail-server/issues/1104
@@ -63,8 +80,8 @@ rustPlatform.buildRustPackage (finalAttrs: {
6380 env = {
6481 OPENSSL_NO_VENDOR = true ;
6582 ZSTD_SYS_USE_PKG_CONFIG = true ;
66- ROCKSDB_INCLUDE_DIR = "${ rocksdb } /include" ;
67- ROCKSDB_LIB_DIR = "${ rocksdb } /lib" ;
83+ ROCKSDB_INCLUDE_DIR = "${ rocksdbJemalloc } /include" ;
84+ ROCKSDB_LIB_DIR = "${ rocksdbJemalloc } /lib" ;
6885 } ;
6986
7087 postInstall = ''
@@ -151,7 +168,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
151168 __darwinAllowLocalNetworking = true ;
152169
153170 passthru = {
154- inherit rocksdb ; # make used rocksdb version available (e.g., for backup scripts)
171+ rocksdb = rocksdbJemalloc ; # make used rocksdb version available (e.g., for backup scripts)
155172 webadmin = callPackage ./webadmin.nix { } ;
156173 updateScript = nix-update-script { } ;
157174 tests . stalwart-mail = nixosTests . stalwart-mail ;
0 commit comments