paperless: init at 2.7.0
This commit is contained in:
parent
76218fdc3a
commit
0231273a57
170
pkgs/applications/office/paperless/default.nix
Normal file
170
pkgs/applications/office/paperless/default.nix
Normal file
|
@ -0,0 +1,170 @@
|
|||
{ stdenv
|
||||
, lib
|
||||
, fetchFromGitHub
|
||||
, makeWrapper
|
||||
, callPackage
|
||||
|
||||
, python3
|
||||
, file
|
||||
, imagemagick7
|
||||
, ghostscript
|
||||
, optipng
|
||||
, poppler
|
||||
, tesseract
|
||||
, unpaper
|
||||
}:
|
||||
|
||||
## Usage
|
||||
|
||||
# ${paperless}/bin/paperless wraps manage.py
|
||||
|
||||
# ${paperless}/share/paperless/setup-env.sh can be sourced from a
|
||||
# shell script to setup a Paperless environment
|
||||
|
||||
# paperless.withConfig is a convenience function to setup a
|
||||
# configured Paperless instance. (See ./withConfig.nix)
|
||||
|
||||
# For WSGI with gunicorn, use a shell script like this:
|
||||
# let
|
||||
# pythonEnv = paperless.python.withPackages (ps: paperless.runtimePackages ++ [ ps.gunicorn ]);
|
||||
# in
|
||||
# writers.writeBash "run-gunicorn" ''
|
||||
# source ${paperless}/share/paperless/setup-env.sh
|
||||
# PYTHONPATH=$paperlessSrc ${pythonEnv}/bin/gunicorn paperless.wsgi
|
||||
# ''
|
||||
|
||||
let
|
||||
paperless = stdenv.mkDerivation rec {
|
||||
name = "paperless-${version}";
|
||||
version = "2.7.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "the-paperless-project";
|
||||
repo = "paperless";
|
||||
rev = version;
|
||||
sha256 = "0pkmyky1crjnsg7r0gfk0fadisfsgzlsq6afpz16wx4hp6yvkkf7";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
doCheck = true;
|
||||
dontInstall = true;
|
||||
|
||||
pythonEnv = python.withPackages (_: runtimePackages);
|
||||
pythonCheckEnv = python.withPackages (_: (runtimePackages ++ checkPackages));
|
||||
|
||||
unpackPhase = ''
|
||||
srcDir=$out/share/paperless
|
||||
mkdir -p $srcDir
|
||||
cp -r --no-preserve=mode $src/src/* $src/LICENSE $srcDir
|
||||
'';
|
||||
|
||||
buildPhase = let
|
||||
# Paperless has explicit runtime checks that expect these binaries to be in PATH
|
||||
extraBin = lib.makeBinPath [ imagemagick7 ghostscript optipng tesseract unpaper ];
|
||||
in ''
|
||||
${python.interpreter} -m compileall $srcDir
|
||||
|
||||
makeWrapper $pythonEnv/bin/python $out/bin/paperless \
|
||||
--set PATH ${extraBin} --add-flags $out/share/paperless/manage.py
|
||||
|
||||
# A shell snippet that can be sourced to setup a paperless env
|
||||
cat > $out/share/paperless/setup-env.sh <<EOF
|
||||
export PATH="$pythonEnv/bin:${extraBin}''${PATH:+:}$PATH"
|
||||
export paperlessSrc=$out/share/paperless
|
||||
EOF
|
||||
'';
|
||||
|
||||
checkPhase = ''
|
||||
source $out/share/paperless/setup-env.sh
|
||||
tmpDir=$(realpath testsTmp)
|
||||
mkdir $tmpDir
|
||||
export HOME=$tmpDir
|
||||
export PAPERLESS_MEDIADIR=$tmpDir
|
||||
cd $paperlessSrc
|
||||
# Prevent tests from writing to the derivation output
|
||||
chmod -R -w $out
|
||||
# Disable cache to silence a pytest warning ("could not create cache")
|
||||
$pythonCheckEnv/bin/pytest -p no:cacheprovider
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
withConfig = callPackage ./withConfig.nix {};
|
||||
inherit python runtimePackages checkPackages tesseract;
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
description = "Scan, index, and archive all of your paper documents";
|
||||
homepage = https://github.com/the-paperless-project/paperless;
|
||||
license = licenses.gpl3;
|
||||
maintainers = [ maintainers.earvstedt ];
|
||||
};
|
||||
};
|
||||
|
||||
python = python3.override {
|
||||
packageOverrides = self: super: {
|
||||
# Paperless only supports Django 2.0
|
||||
django = django_2_0 super;
|
||||
pyocr = pyocrWithUserTesseract super;
|
||||
# These are pre-release versions, hence they are private to this pkg
|
||||
django-filter = self.callPackage ./python-modules/django-filter.nix {};
|
||||
django-crispy-forms = self.callPackage ./python-modules/django-crispy-forms.nix {};
|
||||
};
|
||||
};
|
||||
|
||||
django_2_0 = pyPkgs: pyPkgs.django_2_1.overrideDerivation (_: rec {
|
||||
pname = "Django";
|
||||
version = "2.0.12";
|
||||
name = "${pname}-${version}";
|
||||
src = pyPkgs.fetchPypi {
|
||||
inherit pname version;
|
||||
sha256 = "15s8z54k0gf9brnz06521bikm60ddw5pn6v3nbvnl47j1jjsvwz2";
|
||||
};
|
||||
});
|
||||
|
||||
runtimePackages = with python.pkgs; [
|
||||
dateparser
|
||||
dateutil
|
||||
django
|
||||
django-cors-headers
|
||||
django-crispy-forms
|
||||
django-filter
|
||||
django_extensions
|
||||
djangoql
|
||||
djangorestframework
|
||||
factory_boy
|
||||
filemagic
|
||||
fuzzywuzzy
|
||||
langdetect
|
||||
pdftotext
|
||||
pillow
|
||||
psycopg2
|
||||
pyocr
|
||||
python-dotenv
|
||||
python-gnupg
|
||||
pytz
|
||||
termcolor
|
||||
] ++ (lib.optional stdenv.isLinux inotify-simple);
|
||||
|
||||
checkPackages = with python.pkgs; [
|
||||
pytest
|
||||
pytest-django
|
||||
pytest-env
|
||||
pytest_xdist
|
||||
];
|
||||
|
||||
pyocrWithUserTesseract = pyPkgs:
|
||||
let
|
||||
pyocr = pyPkgs.pyocr.override { inherit tesseract; };
|
||||
in
|
||||
if pyocr.outPath == pyPkgs.pyocr.outPath then
|
||||
pyocr
|
||||
else
|
||||
# The user has provided a custom tesseract derivation that might be
|
||||
# missing some languages that are required for PyOCR's tests. Disable them to
|
||||
# avoid build errors.
|
||||
pyocr.overridePythonAttrs (attrs: {
|
||||
doCheck = false;
|
||||
});
|
||||
in
|
||||
paperless
|
|
@ -0,0 +1,36 @@
|
|||
{ lib, buildPythonPackage, fetchFromGitHub
|
||||
, pytest, pytest-django, django }:
|
||||
|
||||
buildPythonPackage rec {
|
||||
pname = "django-crispy-forms";
|
||||
version = "2019.04.21";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "django-crispy-forms";
|
||||
repo = "django-crispy-forms";
|
||||
rev = "e25a5326697e5b545689b3a914e516404a6911bb";
|
||||
sha256 = "12zqa76q6i7j47aqvhilivpbdplgp9zw2q8zfcjzlgclrqafaj39";
|
||||
};
|
||||
|
||||
# For reasons unknown, the source dir must contain a dash
|
||||
# for the tests to run successfully
|
||||
postUnpack = ''
|
||||
mv $sourceRoot source-
|
||||
export sourceRoot=source-
|
||||
'';
|
||||
|
||||
checkInputs = [ pytest pytest-django django ];
|
||||
|
||||
checkPhase = ''
|
||||
PYTHONPATH="$(pwd):$PYTHONPATH" \
|
||||
DJANGO_SETTINGS_MODULE=crispy_forms.tests.test_settings \
|
||||
pytest crispy_forms/tests
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "The best way to have DRY Django forms";
|
||||
homepage = https://github.com/maraujop/django-crispy-forms;
|
||||
license = licenses.mit;
|
||||
maintainers = with maintainers; [ earvstedt ];
|
||||
};
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
{ lib, buildPythonPackage, python, pythonOlder, fetchFromGitHub
|
||||
, django, django-crispy-forms, djangorestframework, mock, pytz }:
|
||||
|
||||
buildPythonPackage rec {
|
||||
pname = "django-filter";
|
||||
version = "2.1.0-pre";
|
||||
disabled = pythonOlder "3.4";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "carltongibson";
|
||||
repo = pname;
|
||||
rev = "24adad8c48bc9e7c7539b6510ffde4ce4effdc29";
|
||||
sha256 = "0hv4w95jnlzp9vdximl6bb27fyi75001jhvsbs0ikkd8amq8iaj7";
|
||||
};
|
||||
|
||||
checkInputs = [ django django-crispy-forms djangorestframework mock pytz ];
|
||||
|
||||
checkPhase = "${python.interpreter} runtests.py";
|
||||
|
||||
meta = with lib; {
|
||||
description = "A reusable Django application for allowing users to filter querysets dynamically.";
|
||||
homepage = https://github.com/carltongibson/django-filter;
|
||||
license = licenses.bsd3;
|
||||
maintainers = with maintainers; [ earvstedt ];
|
||||
};
|
||||
}
|
68
pkgs/applications/office/paperless/withConfig.nix
Normal file
68
pkgs/applications/office/paperless/withConfig.nix
Normal file
|
@ -0,0 +1,68 @@
|
|||
{ paperless, lib, writers }:
|
||||
|
||||
## Usage
|
||||
#
|
||||
# nix-build --out-link ./paperless -E '
|
||||
# (import <nixpkgs> {}).paperless.withConfig {
|
||||
# dataDir = /tmp/paperless-data;
|
||||
# config = {
|
||||
# PAPERLESS_DISABLE_LOGIN = "true";
|
||||
# };
|
||||
# }'
|
||||
#
|
||||
# Setup DB
|
||||
# ./paperless migrate
|
||||
#
|
||||
# Consume documents in ${dataDir}/consume
|
||||
# ./paperless document_consumer --oneshot
|
||||
#
|
||||
# Start web interface
|
||||
# ./paperless runserver --noreload localhost:8000
|
||||
|
||||
{ config ? {}, dataDir ? null, ocrLanguages ? null
|
||||
, paperlessPkg ? paperless, extraCmds ? "" }:
|
||||
with lib;
|
||||
let
|
||||
paperless = if ocrLanguages == null then
|
||||
paperlessPkg
|
||||
else
|
||||
(paperlessPkg.override {
|
||||
tesseract = paperlessPkg.tesseract.override {
|
||||
enableLanguages = ocrLanguages;
|
||||
};
|
||||
}).overrideDerivation (_: {
|
||||
# `ocrLanguages` might be missing some languages required by the tests.
|
||||
doCheck = false;
|
||||
});
|
||||
|
||||
envVars = (optionalAttrs (dataDir != null) {
|
||||
PAPERLESS_CONSUMPTION_DIR = "${dataDir}/consume";
|
||||
PAPERLESS_MEDIADIR = "${dataDir}/media";
|
||||
PAPERLESS_STATICDIR = "${dataDir}/static";
|
||||
PAPERLESS_DBDIR = "${dataDir}";
|
||||
}) // config;
|
||||
|
||||
envVarDefs = mapAttrsToList (n: v: ''export ${n}="${toString v}"'') envVars;
|
||||
setupEnvVars = builtins.concatStringsSep "\n" envVarDefs;
|
||||
|
||||
setupEnv = ''
|
||||
source ${paperless}/share/paperless/setup-env.sh
|
||||
${setupEnvVars}
|
||||
${optionalString (dataDir != null) ''
|
||||
mkdir -p "$PAPERLESS_CONSUMPTION_DIR" \
|
||||
"$PAPERLESS_MEDIADIR" \
|
||||
"$PAPERLESS_STATICDIR" \
|
||||
"$PAPERLESS_DBDIR"
|
||||
''}
|
||||
'';
|
||||
|
||||
runPaperless = writers.writeBash "paperless" ''
|
||||
set -e
|
||||
${setupEnv}
|
||||
${extraCmds}
|
||||
exec python $paperlessSrc/manage.py "$@"
|
||||
'';
|
||||
in
|
||||
runPaperless // {
|
||||
inherit paperless setupEnv;
|
||||
}
|
|
@ -4952,6 +4952,8 @@ in
|
|||
|
||||
paper-gtk-theme = callPackage ../misc/themes/paper { };
|
||||
|
||||
paperless = callPackage ../applications/office/paperless { };
|
||||
|
||||
paperwork = callPackage ../applications/office/paperwork { };
|
||||
|
||||
papertrail = callPackage ../tools/text/papertrail { };
|
||||
|
|
Loading…
Reference in a new issue