treewide: use `addBinToPathHook`, minor cleanups (#379187)
[NixPkgs.git] / pkgs / by-name / st / stalwart-mail / package.nix
blob5ad612ab29bd905c7a0b861b1ce4456e54a400b0
2   lib,
3   rustPlatform,
4   fetchFromGitHub,
5   pkg-config,
6   protobuf,
7   bzip2,
8   openssl,
9   sqlite,
10   foundationdb,
11   zstd,
12   stdenv,
13   darwin,
14   nix-update-script,
15   nixosTests,
16   rocksdb_8_11,
17   callPackage,
20 let
21   # Stalwart depends on rocksdb crate:
22   # https://github.com/stalwartlabs/mail-server/blob/v0.8.0/crates/store/Cargo.toml#L10
23   # which expects a specific rocksdb versions:
24   # https://github.com/rust-rocksdb/rust-rocksdb/blob/v0.22.0/librocksdb-sys/Cargo.toml#L3
25   # See upstream issue for rocksdb 9.X support
26   # https://github.com/stalwartlabs/mail-server/issues/407
27   rocksdb = rocksdb_8_11;
28   version = "0.10.7";
30 rustPlatform.buildRustPackage {
31   pname = "stalwart-mail";
32   inherit version;
34   src = fetchFromGitHub {
35     owner = "stalwartlabs";
36     repo = "mail-server";
37     tag = "v${version}";
38     hash = "sha256-BATkLgfkz94u2M+Xy6PYQi+7EIxBe86VLYTnBI8PzzY=";
39     fetchSubmodules = true;
40   };
42   cargoHash = "sha256-4MUw9nBx4uZgUOGQksiurFuyStmWXwYuOOGT1e9AoLg=";
44   nativeBuildInputs = [
45     pkg-config
46     protobuf
47     rustPlatform.bindgenHook
48   ];
50   buildInputs =
51     [
52       bzip2
53       openssl
54       sqlite
55       zstd
56     ]
57     ++ lib.optionals stdenv.hostPlatform.isLinux [ foundationdb ]
58     ++ lib.optionals stdenv.hostPlatform.isDarwin [
59       darwin.apple_sdk.frameworks.CoreFoundation
60       darwin.apple_sdk.frameworks.Security
61       darwin.apple_sdk.frameworks.SystemConfiguration
62     ];
64   # skip defaults on darwin because foundationdb is not available
65   buildNoDefaultFeatures = stdenv.hostPlatform.isDarwin;
66   buildFeatures = lib.optional (stdenv.hostPlatform.isDarwin) [
67     "sqlite"
68     "postgres"
69     "mysql"
70     "rocks"
71     "elastic"
72     "s3"
73     "redis"
74   ];
76   env = {
77     OPENSSL_NO_VENDOR = true;
78     ZSTD_SYS_USE_PKG_CONFIG = true;
79     ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
80     ROCKSDB_LIB_DIR = "${rocksdb}/lib";
81   };
83   postInstall = ''
84     mkdir -p $out/etc/stalwart
85     cp resources/config/spamfilter.toml $out/etc/stalwart/spamfilter.toml
86     cp -r resources/config/spamfilter $out/etc/stalwart/
88     mkdir -p $out/lib/systemd/system
90     substitute resources/systemd/stalwart-mail.service $out/lib/systemd/system/stalwart-mail.service \
91       --replace "__PATH__" "$out"
92   '';
94   checkFlags = [
95     # Require running mysql, postgresql daemon
96     "--skip=directory::imap::imap_directory"
97     "--skip=directory::internal::internal_directory"
98     "--skip=directory::ldap::ldap_directory"
99     "--skip=directory::sql::sql_directory"
100     "--skip=store::blob::blob_tests"
101     "--skip=store::lookup::lookup_tests"
102     # thread 'directory::smtp::lmtp_directory' panicked at tests/src/store/mod.rs:122:44:
103     # called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
104     "--skip=directory::smtp::lmtp_directory"
105     # thread 'imap::imap_tests' panicked at tests/src/imap/mod.rs:436:14:
106     # Missing store type. Try running `STORE=<store_type> cargo test`: NotPresent
107     "--skip=imap::imap_tests"
108     # thread 'jmap::jmap_tests' panicked at tests/src/jmap/mod.rs:303:14:
109     # Missing store type. Try running `STORE=<store_type> cargo test`: NotPresent
110     "--skip=jmap::jmap_tests"
111     # Failed to read system DNS config: io error: No such file or directory (os error 2)
112     "--skip=smtp::inbound::data::data"
113     # Expected "X-My-Header: true" but got Received: from foobar.net (unknown [10.0.0.123])
114     "--skip=smtp::inbound::scripts::sieve_scripts"
115     # panicked at tests/src/smtp/outbound/smtp.rs:173:5:
116     "--skip=smtp::outbound::smtp::smtp_delivery"
117     # thread 'smtp::queue::retry::queue_retry' panicked at tests/src/smtp/queue/retry.rs:119:5:
118     # assertion `left == right` failed
119     #   left: [1, 2, 2]
120     #  right: [1, 2, 3]
121     "--skip=smtp::queue::retry::queue_retry"
122     # Missing store type. Try running `STORE=<store_type> cargo test`: NotPresent
123     "--skip=store::store_tests"
124     # thread 'config::parser::tests::toml_parse' panicked at crates/utils/src/config/parser.rs:463:58:
125     # called `Result::unwrap()` on an `Err` value: "Expected ['\\n'] but found '!' in value at line 70."
126     "--skip=config::parser::tests::toml_parse"
127     # error[E0432]: unresolved import `r2d2_sqlite`
128     # use of undeclared crate or module `r2d2_sqlite`
129     "--skip=backend::sqlite::pool::SqliteConnectionManager::with_init"
130     # thread 'smtp::reporting::analyze::report_analyze' panicked at tests/src/smtp/reporting/analyze.rs:88:5:
131     # assertion `left == right` failed
132     #   left: 0
133     #  right: 12
134     "--skip=smtp::reporting::analyze::report_analyze"
135     # thread 'smtp::inbound::dmarc::dmarc' panicked at tests/src/smtp/inbound/mod.rs:59:26:
136     # Expected empty queue but got Reload
137     "--skip=smtp::inbound::dmarc::dmarc"
138     # thread 'smtp::queue::concurrent::concurrent_queue' panicked at tests/src/smtp/inbound/mod.rs:65:9:
139     # assertion `left == right` failed
140     "--skip=smtp::queue::concurrent::concurrent_queue"
141     # Failed to read system DNS config: io error: No such file or directory (os error 2)
142     "--skip=smtp::inbound::auth::auth"
143     # Failed to read system DNS config: io error: No such file or directory (os error 2)
144     "--skip=smtp::inbound::antispam::antispam"
145     # Failed to read system DNS config: io error: No such file or directory (os error 2)
146     "--skip=smtp::inbound::vrfy::vrfy_expn"
147   ];
149   doCheck = !(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
151   passthru = {
152     inherit rocksdb; # make used rocksdb version available (e.g., for backup scripts)
153     webadmin = callPackage ./webadmin.nix { };
154     updateScript = nix-update-script { };
155     tests.stalwart-mail = nixosTests.stalwart-mail;
156   };
158   meta = {
159     description = "Secure & Modern All-in-One Mail Server (IMAP, JMAP, SMTP)";
160     homepage = "https://github.com/stalwartlabs/mail-server";
161     changelog = "https://github.com/stalwartlabs/mail-server/blob/main/CHANGELOG.md";
162     license = lib.licenses.agpl3Only;
163     maintainers = with lib.maintainers; [
164       happysalada
165       onny
166       oddlama
167       pandapip1
168     ];
169   };