From 337afb96cb35fe525c851531fb04fd13989acbe5 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 23 Feb 2025 18:37:06 +0100 Subject: modules/stalwart-mail: Move the package to the `pkgs` subtree --- flake.nix | 2 +- modules/by-name/st/stalwart-mail/module.nix | 50 +------------ ...s-main-Cargo.toml-Activate-appropriate-de.patch | 26 ------- ...directory-Guard-all-enterprise-only-featu.patch | 86 ---------------------- modules/by-name/st/stalwart-mail/spam-filter.nix | 24 ------ pkgs/by-name/st/stalwart-mail-free/package.nix | 44 +++++++++++ ...s-main-Cargo.toml-Activate-appropriate-de.patch | 26 +++++++ ...directory-Guard-all-enterprise-only-featu.patch | 86 ++++++++++++++++++++++ pkgs/by-name/st/stalwart-mail-free/spam-filter.nix | 24 ++++++ pkgs/default.nix | 3 +- 10 files changed, 185 insertions(+), 186 deletions(-) delete mode 100644 modules/by-name/st/stalwart-mail/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch delete mode 100644 modules/by-name/st/stalwart-mail/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch delete mode 100644 modules/by-name/st/stalwart-mail/spam-filter.nix create mode 100644 pkgs/by-name/st/stalwart-mail-free/package.nix create mode 100644 pkgs/by-name/st/stalwart-mail-free/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch create mode 100644 pkgs/by-name/st/stalwart-mail-free/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch create mode 100644 pkgs/by-name/st/stalwart-mail-free/spam-filter.nix diff --git a/flake.nix b/flake.nix index 6f780d0..4d127f1 100644 --- a/flake.nix +++ b/flake.nix @@ -135,7 +135,7 @@ ]; tests = import ./tests {inherit pkgs specialArgs nixLib;}; - vhackPackages = import ./pkgs {inherit pkgs nixLib;}; + vhackPackages = import ./pkgs {inherit pkgs nixLib pkgsUnstable;}; hosts = import ./hosts {inherit pkgs nixLib nixpkgs specialArgs extraModules deployPackage;}; diff --git a/modules/by-name/st/stalwart-mail/module.nix b/modules/by-name/st/stalwart-mail/module.nix index e5a681e..4595c21 100644 --- a/modules/by-name/st/stalwart-mail/module.nix +++ b/modules/by-name/st/stalwart-mail/module.nix @@ -2,8 +2,7 @@ lib, config, pkgs, - pkgsUnstable, - nixLib, + vhackPackages, ... }: let cfg = config.vhack.stalwart-mail; @@ -11,46 +10,6 @@ configFormat = pkgs.formats.toml {}; configFile = configFormat.generate "stalwart-mail.toml" topCfg.settings; - - spamfilter = pkgs.callPackage ./spam-filter.nix {}; - - stalwart-mail = pkgsUnstable.stalwart-mail.overrideAttrs (final: prev: { - passthru = nixLib.warnMerge (prev.passthru or {}) { - inherit spamfilter; - } "stalwart-mail passthru"; - - checkFlags = - (prev.checkFlags or []) - ++ [ - # This started to fail? - # TODO(@bpeetz): Find out why. <2025-02-08> - "--skip=smtp::outbound::lmtp::lmtp_delivery" - ]; - - # `stalwart-mail` does enable their `enterprise` feature per default. - # We want a AGPL only build (i.e., without unfree dependencies), therefore disable the - # `enterprise` feature here. - # We cannot use the `buildFeatures` attribute because it does not actually change the - # correct features. As such we simply patch the correct `Cargo.toml` file. - patches = - (prev.patches or []) - ++ [ - ./patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch - ./patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch - ]; - - # Check that the enterprise feature is really disabled. - postCheck = - (prev.postCheck or "") - + - # bash - '' - if grep "enterprise" ./target/*/release/stalwart-mail.d; then - echo "ERROR: Proprietary 'enterprise' feature active." - exit 1 - fi - ''; - }); in { imports = [ ./settings.nix @@ -59,12 +18,7 @@ in { options.vhack.stalwart-mail = { enable = lib.mkEnableOption "starwart-mail"; - # package = lib.mkPackageOption pkgsUnstable "stalwart-mail" {pkgsText = "pkgsUnstable";}; - package = lib.mkOption { - description = "The stalwart-mail package to use"; - type = lib.types.package; - default = stalwart-mail; - }; + package = lib.mkPackageOption vhackPackages "stalwart-mail-free" {}; fqdn = lib.mkOption { type = lib.types.str; diff --git a/modules/by-name/st/stalwart-mail/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch b/modules/by-name/st/stalwart-mail/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch deleted file mode 100644 index bfea568..0000000 --- a/modules/by-name/st/stalwart-mail/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 42cbd55c21196bdb57ac9795a938b94a781bb1e9 Mon Sep 17 00:00:00 2001 -From: Benedikt Peetz -Date: Sun, 9 Feb 2025 00:17:52 +0100 -Subject: [PATCH] build(crates/main/Cargo.toml): Activate appropriate default - features - ---- - crates/main/Cargo.toml | 14 +++++++------- - 1 file changed, 7 insertions(+), 7 deletions(-) - -diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml -index 036d2dcf..baa320ef 100644 ---- a/crates/main/Cargo.toml -+++ b/crates/main/Cargo.toml -@@ -35,7 +35,7 @@ jemallocator = "0.5.0" - - [features] - #default = ["sqlite", "postgres", "mysql", "rocks", "elastic", "s3", "redis", "azure", "enterprise"] --default = ["rocks", "enterprise"] -+default = ["rocks", "redis"] - sqlite = ["store/sqlite"] - foundationdb = ["store/foundation", "common/foundation"] - postgres = ["store/postgres"] --- -2.47.1 - diff --git a/modules/by-name/st/stalwart-mail/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch b/modules/by-name/st/stalwart-mail/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch deleted file mode 100644 index 80c4b60..0000000 --- a/modules/by-name/st/stalwart-mail/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch +++ /dev/null @@ -1,86 +0,0 @@ -From 3d20702a481bfa4ecc692cd07a7f1fe0a66bb5d9 Mon Sep 17 00:00:00 2001 -From: Benedikt Peetz -Date: Sun, 9 Feb 2025 00:38:13 +0100 -Subject: [PATCH] fix(crates/directory): Guard all enterprise only features - behind a `enterprise` cfg block - ---- - crates/directory/src/core/config.rs | 1 + - crates/directory/src/core/dispatch.rs | 7 +++++++ - 2 files changed, 8 insertions(+) - -diff --git a/crates/directory/src/core/config.rs b/crates/directory/src/core/config.rs -index dfb7bf9b..0c3ce96a 100644 ---- a/crates/directory/src/core/config.rs -+++ b/crates/directory/src/core/config.rs -@@ -84,6 +84,7 @@ impl Directories { - "memory" => MemoryDirectory::from_config(config, prefix, data_store.clone()) - .await - .map(DirectoryInner::Memory), -+ #[cfg(feature = "enterprise")] - "oidc" => OpenIdDirectory::from_config(config, prefix, data_store.clone()) - .map(DirectoryInner::OpenId), - unknown => { -diff --git a/crates/directory/src/core/dispatch.rs b/crates/directory/src/core/dispatch.rs -index a99e54fe..062f29c9 100644 ---- a/crates/directory/src/core/dispatch.rs -+++ b/crates/directory/src/core/dispatch.rs -@@ -24,6 +24,7 @@ impl Directory { - DirectoryInner::Imap(store) => store.query(by).await, - DirectoryInner::Smtp(store) => store.query(by).await, - DirectoryInner::Memory(store) => store.query(by).await, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(store) => store.query(by, return_member_of).await, - } - .caused_by(trc::location!()) -@@ -37,6 +38,7 @@ impl Directory { - DirectoryInner::Imap(store) => store.email_to_id(address).await, - DirectoryInner::Smtp(store) => store.email_to_id(address).await, - DirectoryInner::Memory(store) => store.email_to_id(address).await, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(store) => store.email_to_id(address).await, - } - .caused_by(trc::location!()) -@@ -57,6 +59,7 @@ impl Directory { - DirectoryInner::Imap(store) => store.is_local_domain(domain).await, - DirectoryInner::Smtp(store) => store.is_local_domain(domain).await, - DirectoryInner::Memory(store) => store.is_local_domain(domain).await, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(store) => store.is_local_domain(domain).await, - } - .caused_by(trc::location!())?; -@@ -84,6 +87,7 @@ impl Directory { - DirectoryInner::Imap(store) => store.rcpt(email).await, - DirectoryInner::Smtp(store) => store.rcpt(email).await, - DirectoryInner::Memory(store) => store.rcpt(email).await, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(store) => store.rcpt(email).await, - } - .caused_by(trc::location!())?; -@@ -104,6 +108,7 @@ impl Directory { - DirectoryInner::Imap(store) => store.vrfy(address).await, - DirectoryInner::Smtp(store) => store.vrfy(address).await, - DirectoryInner::Memory(store) => store.vrfy(address).await, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(store) => store.vrfy(address).await, - } - .caused_by(trc::location!()) -@@ -117,6 +122,7 @@ impl Directory { - DirectoryInner::Imap(store) => store.expn(address).await, - DirectoryInner::Smtp(store) => store.expn(address).await, - DirectoryInner::Memory(store) => store.expn(address).await, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(store) => store.expn(address).await, - } - .caused_by(trc::location!()) -@@ -130,6 +136,7 @@ impl Directory { - | DirectoryInner::Imap(_) - | DirectoryInner::Smtp(_) - | DirectoryInner::Memory(_) => false, -+ #[cfg(feature = "enterprise")] - DirectoryInner::OpenId(_) => true, - } - } --- -2.47.1 - diff --git a/modules/by-name/st/stalwart-mail/spam-filter.nix b/modules/by-name/st/stalwart-mail/spam-filter.nix deleted file mode 100644 index ce3466d..0000000 --- a/modules/by-name/st/stalwart-mail/spam-filter.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ - stdenv, - fetchFromGitHub, -}: -stdenv.mkDerivation (finalAttrs: { - pname = "spam-filter"; - version = "2.0.2"; - - src = fetchFromGitHub { - owner = "stalwartlabs"; - repo = "spam-filter"; - tag = "v${finalAttrs.version}"; - hash = "sha256-p2F0bwYBNWeoHjp9csWWaqeOISk9dNQT28OqkhUr7ew="; - }; - - buildPhase = '' - bash ./build.sh - ''; - - installPhase = '' - mkdir --parents "$out" - cp ./spam-filter.toml "$out/" - ''; -}) diff --git a/pkgs/by-name/st/stalwart-mail-free/package.nix b/pkgs/by-name/st/stalwart-mail-free/package.nix new file mode 100644 index 0000000..64fb2d6 --- /dev/null +++ b/pkgs/by-name/st/stalwart-mail-free/package.nix @@ -0,0 +1,44 @@ +{ + pkgsUnstable, + callPackage, + nixLib, +}: let + spamfilter = callPackage ./spam-filter.nix {}; +in + pkgsUnstable.stalwart-mail.overrideAttrs (final: prev: { + passthru = nixLib.warnMerge (prev.passthru or {}) { + inherit spamfilter; + } "stalwart-mail passthru"; + + checkFlags = + (prev.checkFlags or []) + ++ [ + # This started to fail? + # TODO(@bpeetz): Find out why. <2025-02-08> + "--skip=smtp::outbound::lmtp::lmtp_delivery" + ]; + + # `stalwart-mail` does enable their `enterprise` feature per default. + # We want a AGPL only build (i.e., without unfree dependencies), therefore disable the + # `enterprise` feature here. + # We cannot use the `buildFeatures` attribute because it does not actually change the + # correct features. As such we simply patch the correct `Cargo.toml` file. + patches = + (prev.patches or []) + ++ [ + ./patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch + ./patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch + ]; + + # Check that the enterprise feature is really disabled. + postCheck = + (prev.postCheck or "") + + + # bash + '' + if grep "enterprise" ./target/*/release/stalwart-mail.d; then + echo "ERROR: Proprietary 'enterprise' feature active." + exit 1 + fi + ''; + }) diff --git a/pkgs/by-name/st/stalwart-mail-free/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch b/pkgs/by-name/st/stalwart-mail-free/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch new file mode 100644 index 0000000..bfea568 --- /dev/null +++ b/pkgs/by-name/st/stalwart-mail-free/patches/build-crates-main-Cargo.toml-Activate-appropriate-de.patch @@ -0,0 +1,26 @@ +From 42cbd55c21196bdb57ac9795a938b94a781bb1e9 Mon Sep 17 00:00:00 2001 +From: Benedikt Peetz +Date: Sun, 9 Feb 2025 00:17:52 +0100 +Subject: [PATCH] build(crates/main/Cargo.toml): Activate appropriate default + features + +--- + crates/main/Cargo.toml | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml +index 036d2dcf..baa320ef 100644 +--- a/crates/main/Cargo.toml ++++ b/crates/main/Cargo.toml +@@ -35,7 +35,7 @@ jemallocator = "0.5.0" + + [features] + #default = ["sqlite", "postgres", "mysql", "rocks", "elastic", "s3", "redis", "azure", "enterprise"] +-default = ["rocks", "enterprise"] ++default = ["rocks", "redis"] + sqlite = ["store/sqlite"] + foundationdb = ["store/foundation", "common/foundation"] + postgres = ["store/postgres"] +-- +2.47.1 + diff --git a/pkgs/by-name/st/stalwart-mail-free/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch b/pkgs/by-name/st/stalwart-mail-free/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch new file mode 100644 index 0000000..80c4b60 --- /dev/null +++ b/pkgs/by-name/st/stalwart-mail-free/patches/fix-crates-directory-Guard-all-enterprise-only-featu.patch @@ -0,0 +1,86 @@ +From 3d20702a481bfa4ecc692cd07a7f1fe0a66bb5d9 Mon Sep 17 00:00:00 2001 +From: Benedikt Peetz +Date: Sun, 9 Feb 2025 00:38:13 +0100 +Subject: [PATCH] fix(crates/directory): Guard all enterprise only features + behind a `enterprise` cfg block + +--- + crates/directory/src/core/config.rs | 1 + + crates/directory/src/core/dispatch.rs | 7 +++++++ + 2 files changed, 8 insertions(+) + +diff --git a/crates/directory/src/core/config.rs b/crates/directory/src/core/config.rs +index dfb7bf9b..0c3ce96a 100644 +--- a/crates/directory/src/core/config.rs ++++ b/crates/directory/src/core/config.rs +@@ -84,6 +84,7 @@ impl Directories { + "memory" => MemoryDirectory::from_config(config, prefix, data_store.clone()) + .await + .map(DirectoryInner::Memory), ++ #[cfg(feature = "enterprise")] + "oidc" => OpenIdDirectory::from_config(config, prefix, data_store.clone()) + .map(DirectoryInner::OpenId), + unknown => { +diff --git a/crates/directory/src/core/dispatch.rs b/crates/directory/src/core/dispatch.rs +index a99e54fe..062f29c9 100644 +--- a/crates/directory/src/core/dispatch.rs ++++ b/crates/directory/src/core/dispatch.rs +@@ -24,6 +24,7 @@ impl Directory { + DirectoryInner::Imap(store) => store.query(by).await, + DirectoryInner::Smtp(store) => store.query(by).await, + DirectoryInner::Memory(store) => store.query(by).await, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(store) => store.query(by, return_member_of).await, + } + .caused_by(trc::location!()) +@@ -37,6 +38,7 @@ impl Directory { + DirectoryInner::Imap(store) => store.email_to_id(address).await, + DirectoryInner::Smtp(store) => store.email_to_id(address).await, + DirectoryInner::Memory(store) => store.email_to_id(address).await, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(store) => store.email_to_id(address).await, + } + .caused_by(trc::location!()) +@@ -57,6 +59,7 @@ impl Directory { + DirectoryInner::Imap(store) => store.is_local_domain(domain).await, + DirectoryInner::Smtp(store) => store.is_local_domain(domain).await, + DirectoryInner::Memory(store) => store.is_local_domain(domain).await, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(store) => store.is_local_domain(domain).await, + } + .caused_by(trc::location!())?; +@@ -84,6 +87,7 @@ impl Directory { + DirectoryInner::Imap(store) => store.rcpt(email).await, + DirectoryInner::Smtp(store) => store.rcpt(email).await, + DirectoryInner::Memory(store) => store.rcpt(email).await, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(store) => store.rcpt(email).await, + } + .caused_by(trc::location!())?; +@@ -104,6 +108,7 @@ impl Directory { + DirectoryInner::Imap(store) => store.vrfy(address).await, + DirectoryInner::Smtp(store) => store.vrfy(address).await, + DirectoryInner::Memory(store) => store.vrfy(address).await, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(store) => store.vrfy(address).await, + } + .caused_by(trc::location!()) +@@ -117,6 +122,7 @@ impl Directory { + DirectoryInner::Imap(store) => store.expn(address).await, + DirectoryInner::Smtp(store) => store.expn(address).await, + DirectoryInner::Memory(store) => store.expn(address).await, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(store) => store.expn(address).await, + } + .caused_by(trc::location!()) +@@ -130,6 +136,7 @@ impl Directory { + | DirectoryInner::Imap(_) + | DirectoryInner::Smtp(_) + | DirectoryInner::Memory(_) => false, ++ #[cfg(feature = "enterprise")] + DirectoryInner::OpenId(_) => true, + } + } +-- +2.47.1 + diff --git a/pkgs/by-name/st/stalwart-mail-free/spam-filter.nix b/pkgs/by-name/st/stalwart-mail-free/spam-filter.nix new file mode 100644 index 0000000..ce3466d --- /dev/null +++ b/pkgs/by-name/st/stalwart-mail-free/spam-filter.nix @@ -0,0 +1,24 @@ +{ + stdenv, + fetchFromGitHub, +}: +stdenv.mkDerivation (finalAttrs: { + pname = "spam-filter"; + version = "2.0.2"; + + src = fetchFromGitHub { + owner = "stalwartlabs"; + repo = "spam-filter"; + tag = "v${finalAttrs.version}"; + hash = "sha256-p2F0bwYBNWeoHjp9csWWaqeOISk9dNQT28OqkhUr7ew="; + }; + + buildPhase = '' + bash ./build.sh + ''; + + installPhase = '' + mkdir --parents "$out" + cp ./spam-filter.toml "$out/" + ''; +}) diff --git a/pkgs/default.nix b/pkgs/default.nix index e665eb2..5456ad4 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,6 +1,7 @@ { pkgs, nixLib, + pkgsUnstable, }: let inherit (pkgs) lib; @@ -10,7 +11,7 @@ lib.callPackageWith (nixLib.warnMerge pkgs - vhackPkgs + (nixLib.warnMerge vhackPkgs {inherit nixLib pkgsUnstable;} wMM) wMM); vhackPkgs = nixLib.mkByName { -- cgit 1.4.1