nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 python3,
4 python3Packages,
5 fetchFromGitLab,
6 fetchpatch,
7 rspamd,
8 nixosTests,
9}:
10
11python3Packages.buildPythonApplication {
12 pname = "rspamd-trainer";
13 version = "unstable-2023-11-27";
14 format = "pyproject";
15
16 src = fetchFromGitLab {
17 owner = "onlime";
18 repo = "rspamd-trainer";
19 rev = "eb6639a78a019ade6781f3a8418eddc030f8fa14";
20 hash = "sha256-Me6WZhQ6SvDGGBQQtSA/7bIfKtsz6D5rvQeU12sVzgY=";
21 };
22
23 patches = [
24 # Refactor pyproject.toml
25 # https://gitlab.com/onlime/rspamd-trainer/-/merge_requests/2
26 (fetchpatch {
27 url = "https://gitlab.com/onlime/rspamd-trainer/-/commit/8824bfb9a9826988a90a401b8e51c20f5366ed70.patch";
28 hash = "sha256-qiXfwMUfM/iV+fHba8xdwQD92RQz627+HdUTgwgRZdc=";
29 name = "refactor_pyproject.patch";
30 })
31 ];
32
33 postPatch = ''
34 # Fix module path not applied by patch
35 mv helper src/
36 touch src/helper/__init__.py
37 mv settings.py src/rspamd_trainer/
38 sed -i 's/from settings/from .settings/' src/rspamd_trainer/run.py
39
40 # Fix rspamc path
41 sed -i "s|/usr/bin/rspamc|${rspamd}/bin/rspamc|" src/rspamd_trainer/run.py
42 '';
43
44 nativeBuildInputs = with python3.pkgs; [
45 setuptools-scm
46 ];
47
48 propagatedBuildInputs = with python3.pkgs; [
49 python-dotenv
50 imapclient
51 ];
52
53 passthru.tests = { inherit (nixosTests) rspamd-trainer; };
54
55 meta = {
56 homepage = "https://gitlab.com/onlime/rspamd-trainer";
57 description = "Grabs messages from a spam mailbox via IMAP and feeds them to Rspamd for training";
58 mainProgram = "rspamd-trainer";
59 license = lib.licenses.gpl3Only;
60 maintainers = with lib.maintainers; [ onny ];
61 };
62}