aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/applications/office/paperless
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
committerMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
commitc4625b175f8200f643fd6e11010932ea44c78433 (patch)
treebce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/pkgs/applications/office/paperless
parent49f735974dd103039ddc4cb576bb76555164a9e7 (diff)
parentd661aa56a8843e991261510c1bb28fdc2f6975ae (diff)
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7 git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/applications/office/paperless')
-rw-r--r--infra/libkookie/nixpkgs/pkgs/applications/office/paperless/default.nix174
-rw-r--r--infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/default.nix30
-rw-r--r--infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-crispy-forms.nix36
-rw-r--r--infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-filter.nix26
-rw-r--r--infra/libkookie/nixpkgs/pkgs/applications/office/paperless/withConfig.nix68
5 files changed, 334 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/default.nix b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/default.nix
new file mode 100644
index 000000000000..ebd057da5ce1
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/default.nix
@@ -0,0 +1,174 @@
+{ stdenv
+, lib
+, fetchFromGitHub
+, makeWrapper
+, callPackage
+
+, python3
+, imagemagick7
+, ghostscript
+, optipng
+, 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 {
+ pname = "paperless";
+ 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
+ '';
+
+ postPatch = ''
+ # django-cors-headers 3.x requires a scheme for allowed hosts
+ substituteInPlace $out/share/paperless/paperless/settings.py \
+ --replace "localhost:8080" "http://localhost:8080"
+ '';
+
+ 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: let
+ customPkgs = import ./python-modules super fetchFromGitHub; in
+ {
+ pyocr = pyocrWithUserTesseract super;
+
+ # Paperless only supports Django 2.0
+ django = customPkgs.django_2_0;
+
+ # Paperless is incompatible with factory_boy >= 3
+ factory_boy = customPkgs.factory_boy_2_12_0;
+
+ # The current version of django_extensions is incompatible with django 2.0
+ django_extensions = customPkgs.django_extensions_2_2_8;
+
+ # 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 {};
+ };
+ };
+
+ 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
diff --git a/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/default.nix b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/default.nix
new file mode 100644
index 000000000000..40a496312fa9
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/default.nix
@@ -0,0 +1,30 @@
+pyPkgs: fetchFromGitHub:
+{
+ django_2_0 = pyPkgs.django_2_2.overridePythonAttrs (old: rec {
+ version = "2.0.12";
+ src = pyPkgs.fetchPypi {
+ inherit (old) pname;
+ inherit version;
+ sha256 = "15s8z54k0gf9brnz06521bikm60ddw5pn6v3nbvnl47j1jjsvwz2";
+ };
+ });
+
+ django_extensions_2_2_8 = pyPkgs.django_extensions.overridePythonAttrs (old: rec {
+ version = "2.2.8";
+ src = fetchFromGitHub {
+ owner = old.pname;
+ repo = old.pname;
+ rev = version;
+ sha256 = "1gd3nykwzh3azq1p9cvgkc3l5dwrv7y86sfjxd9llbyj8ky71iaj";
+ };
+ });
+
+ factory_boy_2_12_0 = pyPkgs.factory_boy.overridePythonAttrs (old: rec {
+ version = "2.12.0";
+ src = pyPkgs.fetchPypi {
+ inherit (old) pname;
+ inherit version;
+ sha256 = "0w53hjgag6ad5i2vmrys8ysk54agsqvgbjy9lg8g0d8pi9h8vx7s";
+ };
+ });
+}
diff --git a/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-crispy-forms.nix b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-crispy-forms.nix
new file mode 100644
index 000000000000..c470a56b8a11
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-crispy-forms.nix
@@ -0,0 +1,36 @@
+{ lib, buildPythonPackage, fetchFromGitHub
+, pytest_4, pytest-django, django }:
+
+buildPythonPackage {
+ 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_4 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 ];
+ };
+}
diff --git a/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-filter.nix b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-filter.nix
new file mode 100644
index 000000000000..d7f20bd9d37d
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/python-modules/django-filter.nix
@@ -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 ];
+ };
+}
diff --git a/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/withConfig.nix b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/withConfig.nix
new file mode 100644
index 000000000000..652d1478c0ca
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/applications/office/paperless/withConfig.nix
@@ -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;
+ }