nixpkgs/pkgs/applications/office/paperless-ngx/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

326 lines
7.3 KiB
Nix
Raw Normal View History

2022-04-04 18:30:41 +00:00
{ lib
, fetchFromGitHub
, buildNpmPackage
2022-04-04 18:30:41 +00:00
, nixosTests
, gettext
2022-04-04 18:30:41 +00:00
, python3
, ghostscript
, imagemagickBig
2022-04-04 18:30:41 +00:00
, jbig2enc
, optipng
, pngquant
, qpdf
, tesseract5
2022-04-04 18:30:41 +00:00
, unpaper
, poppler_utils
2022-04-04 18:30:41 +00:00
, liberation_ttf
}:
let
version = "1.12.2";
src = fetchFromGitHub {
owner = "paperless-ngx";
repo = "paperless-ngx";
rev = "refs/tags/v${version}";
hash = "sha256-1QufnRD2Nbc4twRZ4Yrf3ae1BRGves8tJ/M7coWnRPI=";
};
2022-04-28 13:48:06 +00:00
# Use specific package versions required by paperless-ngx
python = python3.override {
2022-04-04 18:30:41 +00:00
packageOverrides = self: super: {
2022-04-28 13:48:06 +00:00
django = super.django_4;
2022-04-04 18:30:41 +00:00
aioredis = super.aioredis.overridePythonAttrs (oldAttrs: rec {
version = "1.3.1";
src = oldAttrs.src.override {
inherit version;
sha256 = "0fi7jd5hlx8cnv1m97kv9hc4ih4l8v15wzkqwsp73is4n0qazy0m";
};
});
# downgrade redis due to https://github.com/paperless-ngx/paperless-ngx/pull/1802
# and https://github.com/django/channels_redis/issues/332
channels-redis = super.channels-redis.overridePythonAttrs (oldAttrs: rec {
version = "3.4.1";
src = fetchFromGitHub {
owner = "django";
repo = "channels_redis";
rev = version;
hash = "sha256-ZQSsE3pkM+nfDhWutNuupcyC5MDikUu6zU4u7Im6bRQ=";
};
});
channels = super.channels.overridePythonAttrs (oldAttrs: rec {
version = "3.0.5";
pname = "channels";
src = fetchFromGitHub {
owner = "django";
repo = pname;
rev = version;
sha256 = "sha256-bKrPLbD9zG7DwIYBst1cb+zkDsM8B02wh3D80iortpw=";
};
propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ [ self.daphne ];
pytestFlagsArray = [ "--asyncio-mode=auto" ];
});
daphne = super.daphne.overridePythonAttrs (oldAttrs: rec {
version = "3.0.2";
pname = "daphne";
src = fetchFromGitHub {
owner = "django";
repo = pname;
rev = version;
hash = "sha256-KWkMV4L7bA2Eo/u4GGif6lmDNrZAzvYyDiyzyWt9LeI=";
};
});
2022-04-04 18:30:41 +00:00
};
};
2022-09-11 19:55:12 +00:00
path = lib.makeBinPath [
ghostscript
imagemagickBig
2022-09-11 19:55:12 +00:00
jbig2enc
optipng
pngquant
qpdf
tesseract5
2022-09-11 19:55:12 +00:00
unpaper
poppler_utils
2022-09-11 19:55:12 +00:00
];
frontend = buildNpmPackage {
pname = "paperless-ngx-frontend";
inherit version src;
npmDepsHash = "sha256-fp0Gy3018u2y6jaUM9bmXU0SVjyEJdsvkBqbmb8S10Y=";
nativeBuildInputs = [
python3
];
postPatch = ''
cd src-ui
'';
CYPRESS_INSTALL_BINARY = "0";
NG_CLI_ANALYTICS = "false";
npmBuildFlags = [
"--" "--configuration" "production"
];
installPhase = ''
runHook preInstall
mkdir -p $out/lib/paperless-ui
mv ../src/documents/static/frontend $out/lib/paperless-ui/
runHook postInstall
'';
};
2022-04-04 18:30:41 +00:00
in
python.pkgs.buildPythonApplication rec {
2022-04-04 18:30:41 +00:00
pname = "paperless-ngx";
format = "other";
2022-04-04 18:30:41 +00:00
inherit version src;
2022-04-04 18:30:41 +00:00
nativeBuildInputs = [
gettext
];
2022-04-04 18:30:41 +00:00
propagatedBuildInputs = with python.pkgs; [
2022-04-04 18:30:41 +00:00
aioredis
amqp
anyio
2022-04-04 18:30:41 +00:00
asgiref
async-timeout
attrs
autobahn
automat
billiard
2023-01-07 23:15:47 +00:00
bleach
2022-12-19 10:30:44 +00:00
celery
2022-04-04 18:30:41 +00:00
certifi
cffi
channels-redis
channels
charset-normalizer
2022-04-04 18:30:41 +00:00
click
click-didyoumean
click-plugins
click-repl
2022-04-04 18:30:41 +00:00
coloredlogs
concurrent-log-handler
constantly
cryptography
daphne
dateparser
2022-12-19 10:30:44 +00:00
django-celery-results
2022-04-04 18:30:41 +00:00
django-cors-headers
django-extensions
django-filter
django
djangorestframework
filelock
gunicorn
h11
hiredis
httptools
humanfriendly
humanize
2022-04-04 18:30:41 +00:00
hyperlink
idna
imap-tools
img2pdf
incremental
inotify-simple
inotifyrecursive
joblib
langdetect
lxml
msgpack
mysqlclient
2023-01-07 23:15:47 +00:00
nltk
2022-04-04 18:30:41 +00:00
numpy
ocrmypdf
packaging
2022-04-04 18:30:41 +00:00
pathvalidate
2022-04-28 13:48:06 +00:00
pdf2image
pdfminer-six
2022-04-04 18:30:41 +00:00
pikepdf
pillow
pluggy
portalocker
prompt-toolkit
2022-04-04 18:30:41 +00:00
psycopg2
pyasn1-modules
pyasn1
pycparser
pyopenssl
python-dateutil
python-dotenv
python-gnupg
python-magic
2022-04-04 18:30:41 +00:00
pytz
pyyaml
2022-04-28 13:48:06 +00:00
pyzbar
2022-12-19 10:30:44 +00:00
rapidfuzz
2022-04-04 18:30:41 +00:00
redis
regex
reportlab
requests
scikit-learn
scipy
service-identity
setproctitle
sniffio
2022-04-04 18:30:41 +00:00
sqlparse
threadpoolctl
tika
tornado
2022-04-04 18:30:41 +00:00
tqdm
twisted
2022-04-04 18:30:41 +00:00
txaio
tzdata
2022-04-04 18:30:41 +00:00
tzlocal
urllib3
uvicorn
uvloop
vine
2022-04-04 18:30:41 +00:00
watchdog
watchfiles
2022-04-04 18:30:41 +00:00
wcwidth
webencodings
2022-04-04 18:30:41 +00:00
websockets
whitenoise
whoosh
zipp
2022-04-04 18:30:41 +00:00
zope_interface
]
++ redis.optional-dependencies.hiredis
++ twisted.optional-dependencies.tls
++ uvicorn.optional-dependencies.standard;
2022-04-04 18:30:41 +00:00
postBuild = ''
# Compile manually because `pythonRecompileBytecodeHook` only works
# for files in `python.sitePackages`
${python.interpreter} -OO -m compileall src
# Collect static files
${python.interpreter} src/manage.py collectstatic --clear --no-input
# Compile string translations using gettext
${python.interpreter} src/manage.py compilemessages
2022-04-04 18:30:41 +00:00
'';
installPhase = ''
mkdir -p $out/lib/paperless-ngx
cp -r {src,static,LICENSE,gunicorn.conf.py} $out/lib/paperless-ngx
ln -s ${frontend}/lib/paperless-ui/frontend $out/lib/paperless-ngx/static/
2022-04-04 18:30:41 +00:00
chmod +x $out/lib/paperless-ngx/src/manage.py
makeWrapper $out/lib/paperless-ngx/src/manage.py $out/bin/paperless-ngx \
--prefix PYTHONPATH : "$PYTHONPATH" \
--prefix PATH : "${path}"
2022-12-25 23:06:52 +00:00
makeWrapper ${python.pkgs.celery}/bin/celery $out/bin/celery \
--prefix PYTHONPATH : "$PYTHONPATH:$out/lib/paperless-ngx/src" \
--prefix PATH : "${path}"
2022-04-04 18:30:41 +00:00
'';
postFixup = ''
# Remove tests with samples (~14M)
find $out/lib/paperless-ngx -type d -name tests -exec rm -rv {} +
'';
nativeCheckInputs = with python.pkgs; [
factory_boy
imagehash
2022-04-04 18:30:41 +00:00
pytest-django
pytest-env
pytest-xdist
pytestCheckHook
];
2022-10-21 09:23:42 +00:00
pytestFlagsArray = [
"src"
];
2022-04-04 18:30:41 +00:00
# The tests require:
# - PATH with runtime binaries
# - A temporary HOME directory for gnupg
# - XDG_DATA_DIRS with test-specific fonts
preCheck = ''
export PATH="${path}:$PATH"
export HOME=$(mktemp -d)
export XDG_DATA_DIRS="${liberation_ttf}/share:$XDG_DATA_DIRS"
# Disable unneeded code coverage test
substituteInPlace src/setup.cfg \
--replace "--cov --cov-report=html" ""
2022-12-19 10:30:44 +00:00
# OCR on NixOS recognizes the space in the picture, upstream CI doesn't.
# See https://github.com/paperless-ngx/paperless-ngx/pull/2216
substituteInPlace src/paperless_tesseract/tests/test_parser.py \
--replace "this is awebp document" "this is a webp document"
2022-04-04 18:30:41 +00:00
'';
2022-12-19 10:30:44 +00:00
disabledTests = [
# FileNotFoundError(2, 'No such file or directory'): /build/tmp...
"test_script_with_output"
# AssertionError: 10 != 4 (timezone/time issue)
# Due to getting local time from modification date in test_consumer.py
"testNormalOperation"
];
2022-10-21 09:23:42 +00:00
2022-04-04 18:30:41 +00:00
passthru = {
inherit python path frontend;
tests = { inherit (nixosTests) paperless; };
2022-04-04 18:30:41 +00:00
};
meta = with lib; {
2022-10-21 09:23:42 +00:00
description = "Tool to scan, index, and archive all of your physical documents";
homepage = "https://paperless-ngx.readthedocs.io/";
changelog = "https://github.com/paperless-ngx/paperless-ngx/releases/tag/v${version}";
2022-04-04 18:30:41 +00:00
license = licenses.gpl3Only;
maintainers = with maintainers; [ lukegb gador erikarvstedt ];
2022-04-04 18:30:41 +00:00
};
}