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.

265 lines
6.1 KiB
Nix
Raw Normal View History

2022-04-04 18:30:41 +00:00
{ lib
2023-02-08 20:45:25 +00:00
, stdenv
, fetchFromGitHub
, buildNpmPackage
2022-04-04 18:30:41 +00:00
, nixosTests
, gettext
2022-04-04 18:30:41 +00:00
, python3
, giflib
, darwin
2022-04-04 18:30:41 +00:00
, 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
2023-02-08 20:45:25 +00:00
, xcbuild
2023-12-06 22:35:40 +00:00
, pango
, pkg-config
, nltk-data
2022-04-04 18:30:41 +00:00
}:
let
version = "2.7.2";
src = fetchFromGitHub {
owner = "paperless-ngx";
repo = "paperless-ngx";
rev = "refs/tags/v${version}";
hash = "sha256-vXW2d45Mth3Y95xPPH8bFjVLWVdUl+WuvSXJyPD3FyU=";
};
# subpath installation is broken with uvicorn >= 0.26
# https://github.com/NixOS/nixpkgs/issues/298719
# https://github.com/paperless-ngx/paperless-ngx/issues/5494
python = python3.override {
packageOverrides = final: prev: {
# tesseract5 may be overwritten in the paperless module and we need to propagate that to make the closure reduction effective
ocrmypdf = prev.ocrmypdf.override { tesseract = tesseract5; };
uvicorn = prev.uvicorn.overridePythonAttrs (_: {
version = "0.25.0";
src = fetchFromGitHub {
owner = "encode";
repo = "uvicorn";
rev = "0.25.0";
hash = "sha256-ng98DTw49zyFjrPnEwfnPfONyjKKZYuLl0qduxSppYk=";
};
});
};
};
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;
2023-12-06 22:35:40 +00:00
postPatch = ''
cd src-ui
'';
npmDepsHash = "sha256-MJ5pnQChghZBfVN6Lbz6VcMtbe8QadiFLTsMF5TlebQ=";
nativeBuildInputs = [
2023-12-06 22:35:40 +00:00
pkg-config
python3
2023-02-08 20:45:25 +00:00
] ++ lib.optionals stdenv.isDarwin [
xcbuild
];
2023-12-06 22:35:40 +00:00
buildInputs = [
pango
] ++ lib.optionals stdenv.isDarwin [
giflib
darwin.apple_sdk.frameworks.CoreText
2023-12-06 22:35:40 +00:00
];
CYPRESS_INSTALL_BINARY = "0";
NG_CLI_ANALYTICS = "false";
npmBuildFlags = [
"--" "--configuration" "production"
];
2023-06-22 18:16:50 +00:00
doCheck = true;
checkPhase = ''
runHook preCheck
npm run test
runHook postCheck
'';
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; [
2023-01-07 23:15:47 +00:00
bleach
2022-04-04 18:30:41 +00:00
channels
2024-02-25 03:08:08 +00:00
channels-redis
2022-04-04 18:30:41 +00:00
concurrent-log-handler
dateparser
2024-02-25 03:08:08 +00:00
django
django-allauth
2023-11-29 20:08:10 +00:00
django-auditlog
2022-12-19 10:30:44 +00:00
django-celery-results
2023-02-27 18:28:45 +00:00
django-compression-middleware
2023-11-29 20:08:10 +00:00
django-cors-headers
2022-04-04 18:30:41 +00:00
django-extensions
django-filter
django-guardian
2023-11-29 20:08:10 +00:00
django-multiselectfield
2022-04-04 18:30:41 +00:00
djangorestframework
2024-02-25 03:08:08 +00:00
djangorestframework-guardian2
2023-11-29 20:08:10 +00:00
drf-writable-nested
2022-04-04 18:30:41 +00:00
filelock
2023-11-29 20:08:10 +00:00
flower
gotenberg-client
2022-04-04 18:30:41 +00:00
gunicorn
imap-tools
inotifyrecursive
langdetect
mysqlclient
2023-01-07 23:15:47 +00:00
nltk
2022-04-04 18:30:41 +00:00
ocrmypdf
pathvalidate
2022-04-28 13:48:06 +00:00
pdf2image
2022-04-04 18:30:41 +00:00
psycopg2
python-dateutil
python-dotenv
2024-02-25 03:08:08 +00:00
python-gnupg
python-ipware
python-magic
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
scikit-learn
setproctitle
tika-client
2022-04-04 18:30:41 +00:00
tqdm
uvicorn
watchdog
whitenoise
whoosh
zxing-cpp
]
++ redis.optional-dependencies.hiredis
++ 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.pythonOnBuildForHost.interpreter} -OO -m compileall src
# Collect static files
${python.pythonOnBuildForHost.interpreter} src/manage.py collectstatic --clear --no-input
# Compile string translations using gettext
${python.pythonOnBuildForHost.interpreter} src/manage.py compilemessages
2022-04-04 18:30:41 +00:00
'';
installPhase = let
pythonPath = python.pkgs.makePythonPath propagatedBuildInputs;
in ''
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}" \
2022-04-04 18:30:41 +00:00
--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" \
2022-12-25 23:06:52 +00:00
--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; [
daphne
factory-boy
imagehash
2022-04-04 18:30:41 +00:00
pytest-django
pytest-env
pytest-httpx
2023-08-25 09:19:08 +00:00
pytest-rerunfailures
2022-04-04 18:30:41 +00:00
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 \
2024-02-25 03:06:45 +00:00
--replace-fail "--cov --cov-report=html --cov-report=xml" ""
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
2023-02-08 20:45:25 +00:00
doCheck = !stdenv.isDarwin;
2022-04-04 18:30:41 +00:00
passthru = {
inherit python path frontend tesseract5;
nltkData = with nltk-data; [ punkt snowball_data stopwords ];
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";
2023-02-12 15:31:50 +00:00
homepage = "https://docs.paperless-ngx.com/";
changelog = "https://github.com/paperless-ngx/paperless-ngx/releases/tag/v${version}";
2022-04-04 18:30:41 +00:00
license = licenses.gpl3Only;
2023-02-08 20:45:25 +00:00
platforms = platforms.unix;
2023-06-27 23:44:20 +00:00
maintainers = with maintainers; [ lukegb gador erikarvstedt leona ];
2022-04-04 18:30:41 +00:00
};
}