Skip to content

Commit 24b70d6

Browse files
authored
stalwart-mail: build against system jemalloc [second try] (#411265)
2 parents 9270558 + 1768010 commit 24b70d6

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

nixos/tests/stalwart-mail.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,20 @@ in
4848
session.auth.directory = "'in-memory'";
4949
storage.directory = "in-memory";
5050

51+
storage.data = "rocksdb";
52+
storage.fts = "rocksdb";
53+
storage.blob = "rocksdb";
54+
storage.lookup = "rocksdb";
55+
5156
session.rcpt.directory = "'in-memory'";
5257
queue.outbound.next-hop = "'local'";
5358

59+
store."rocksdb" = {
60+
type = "rocksdb";
61+
path = "/var/lib/stalwart-mail/data";
62+
compression = "lz4";
63+
};
64+
5465
directory."in-memory" = {
5566
type = "memory";
5667
principals = [
@@ -116,6 +127,12 @@ in
116127
main.wait_for_open_port(143)
117128
118129
main.succeed("test-smtp-submission")
130+
131+
# restart stalwart to test rocksdb compaction of existing database
132+
main.succeed("systemctl restart stalwart-mail.service")
133+
main.wait_for_open_port(587)
134+
main.wait_for_open_port(143)
135+
119136
main.succeed("test-imap-read")
120137
'';
121138

pkgs/by-name/st/stalwart-mail/package.nix

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sqlite,
1010
foundationdb,
1111
zstd,
12+
rust-jemalloc-sys-unprefixed,
1213
stdenv,
1314
nix-update-script,
1415
nixosTests,
@@ -18,6 +19,9 @@
1819
stalwartEnterprise ? false,
1920
}:
2021

22+
let
23+
rocksdbJemalloc = rocksdb.override { enableJemalloc = true; };
24+
in
2125
rustPlatform.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

Comments
 (0)