python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / applications / office / paperless-ngx / default.nix
blobf5de1d65184ca5f49d8fd3f6425f55330a54753d
1 { lib
2 , fetchurl
3 , nixosTests
4 , python3
5 , ghostscript
6 , imagemagickBig
7 , jbig2enc
8 , optipng
9 , pngquant
10 , qpdf
11 , tesseract5
12 , unpaper
13 , liberation_ttf
14 , fetchFromGitHub
17 let
18   # Use specific package versions required by paperless-ngx
19   python = python3.override {
20     packageOverrides = self: super: {
21       django = super.django_4;
23       # use paperless-ngx version of django-q
24       # see https://github.com/paperless-ngx/paperless-ngx/pull/1014
25       django-q = super.django-q.overridePythonAttrs (oldAttrs: {
26         src = fetchFromGitHub {
27           owner = "paperless-ngx";
28           repo = "django-q";
29           hash = "sha256-alu7tZwUn77xhUF9c/aGmwRwO//mR/FucXjvXUl/6ek=";
30           rev = "8b5289d8caf36f67fb99448e76ead20d5b498c1b";
31         };
32         # due to paperless-ngx modification of the pyproject.toml file
33         # the patch is not needed any more
34         patches = [ ];
35       });
37       aioredis = super.aioredis.overridePythonAttrs (oldAttrs: rec {
38         version = "1.3.1";
39         src = oldAttrs.src.override {
40           inherit version;
41           sha256 = "0fi7jd5hlx8cnv1m97kv9hc4ih4l8v15wzkqwsp73is4n0qazy0m";
42         };
43       });
45       # downgrade redis due to https://github.com/paperless-ngx/paperless-ngx/pull/1802
46       # and https://github.com/django/channels_redis/issues/332
47       channels-redis = super.channels-redis.overridePythonAttrs (oldAttrs: rec {
48         version = "3.4.1";
49         src = fetchFromGitHub {
50           owner = "django";
51           repo = "channels_redis";
52           rev = version;
53           hash = "sha256-ZQSsE3pkM+nfDhWutNuupcyC5MDikUu6zU4u7Im6bRQ=";
54         };
55       });
57       channels = super.channels.overridePythonAttrs (oldAttrs: rec {
58         version = "3.0.5";
59         pname = "channels";
60         src = fetchFromGitHub {
61           owner = "django";
62           repo = pname;
63           rev = version;
64           sha256 = "sha256-bKrPLbD9zG7DwIYBst1cb+zkDsM8B02wh3D80iortpw=";
65         };
66         propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ [ self.daphne ];
67       });
69       daphne = super.daphne.overridePythonAttrs (oldAttrs: rec {
70         version = "3.0.2";
71         pname = "daphne";
72         src = fetchFromGitHub {
73           owner = "django";
74           repo = pname;
75           rev = version;
76           hash = "sha256-KWkMV4L7bA2Eo/u4GGif6lmDNrZAzvYyDiyzyWt9LeI=";
77         };
78       });
79     };
80   };
82   path = lib.makeBinPath [
83     ghostscript
84     imagemagickBig
85     jbig2enc
86     optipng
87     pngquant
88     qpdf
89     tesseract5
90     unpaper
91   ];
93 python.pkgs.pythonPackages.buildPythonApplication rec {
94   pname = "paperless-ngx";
95   version = "1.9.2";
97   # Fetch the release tarball instead of a git ref because it contains the prebuilt fontend
98   src = fetchurl {
99     url = "https://github.com/paperless-ngx/paperless-ngx/releases/download/v${version}/${pname}-v${version}.tar.xz";
100     hash = "sha256-fafjVXRfzFrINzI/Ivfm1VY4YpemHkHwThBP54XoXM4=";
101   };
103   format = "other";
105   propagatedBuildInputs = with python.pkgs.pythonPackages; [
106     aioredis
107     arrow
108     asgiref
109     async-timeout
110     attrs
111     autobahn
112     automat
113     blessed
114     certifi
115     cffi
116     channels-redis
117     channels
118     chardet
119     click
120     coloredlogs
121     concurrent-log-handler
122     constantly
123     cryptography
124     daphne
125     dateparser
126     django-cors-headers
127     django-extensions
128     django-filter
129     django-picklefield
130     django-q
131     django
132     djangorestframework
133     filelock
134     fuzzywuzzy
135     gunicorn
136     h11
137     hiredis
138     httptools
139     humanfriendly
140     hyperlink
141     idna
142     imap-tools
143     img2pdf
144     incremental
145     inotify-simple
146     inotifyrecursive
147     joblib
148     langdetect
149     lxml
150     msgpack
151     numpy
152     ocrmypdf
153     pathvalidate
154     pdf2image
155     pdfminer-six
156     pikepdf
157     pillow
158     pluggy
159     portalocker
160     psycopg2
161     pyasn1-modules
162     pyasn1
163     pycparser
164     pyopenssl
165     python-dateutil
166     python-dotenv
167     python-gnupg
168     python-Levenshtein
169     python-magic
170     pytz
171     pyyaml
172     pyzbar
173     redis
174     regex
175     reportlab
176     requests
177     scikit-learn
178     scipy
179     service-identity
180     six
181     sortedcontainers
182     sqlparse
183     threadpoolctl
184     tika
185     tqdm
186     twisted.optional-dependencies.tls
187     txaio
188     tzlocal
189     urllib3
190     uvicorn
191     uvloop
192     watchdog
193     watchgod
194     wcwidth
195     websockets
196     whitenoise
197     whoosh
198     zope_interface
199   ];
201   # paperless-ngx includes the bundled django-q version. This will
202   # conflict with the tests and is not needed since we overrode the
203   # django-q version with the paperless-ngx version
204   postPatch = ''
205     rm -rf src/django-q
206   '';
208   # Compile manually because `pythonRecompileBytecodeHook` only works for
209   # files in `python.sitePackages`
210   postBuild = ''
211     ${python.interpreter} -OO -m compileall src
212   '';
214   installPhase = ''
215     mkdir -p $out/lib
216     cp -r . $out/lib/paperless-ngx
217     chmod +x $out/lib/paperless-ngx/src/manage.py
218     makeWrapper $out/lib/paperless-ngx/src/manage.py $out/bin/paperless-ngx \
219       --prefix PYTHONPATH : "$PYTHONPATH" \
220       --prefix PATH : "${path}"
221   '';
223   checkInputs = with python.pkgs.pythonPackages; [
224     pytest-django
225     pytest-env
226     pytest-sugar
227     pytest-xdist
228     factory_boy
229     pytestCheckHook
230   ];
232   pytestFlagsArray = [
233     "src"
234   ];
236   # The tests require:
237   # - PATH with runtime binaries
238   # - A temporary HOME directory for gnupg
239   # - XDG_DATA_DIRS with test-specific fonts
240   preCheck = ''
241     export PATH="${path}:$PATH"
242     export HOME=$(mktemp -d)
243     export XDG_DATA_DIRS="${liberation_ttf}/share:$XDG_DATA_DIRS"
245     # Disable unneeded code coverage test
246     substituteInPlace src/setup.cfg \
247       --replace "--cov --cov-report=html" ""
248   '';
251   passthru = {
252     inherit python path;
253     tests = { inherit (nixosTests) paperless; };
254   };
256   meta = with lib; {
257     description = "Tool to scan, index, and archive all of your physical documents";
258     homepage = "https://paperless-ngx.readthedocs.io/";
259     license = licenses.gpl3Only;
260     maintainers = with maintainers; [ lukegb gador erikarvstedt ];
261   };