From 9faba97d247efa0977b9b67d0e8b67fc573b7036 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Mon, 4 Apr 2022 18:30:41 +0000 Subject: [PATCH 1/6] paperless-ngx: init at 1.6.0 --- .../office/paperless-ngx/default.nix | 192 ++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 194 insertions(+) create mode 100644 pkgs/applications/office/paperless-ngx/default.nix diff --git a/pkgs/applications/office/paperless-ngx/default.nix b/pkgs/applications/office/paperless-ngx/default.nix new file mode 100644 index 000000000000..be22ca7c26cd --- /dev/null +++ b/pkgs/applications/office/paperless-ngx/default.nix @@ -0,0 +1,192 @@ +{ lib +, fetchurl +, fetchpatch +, nixosTests +, python3 +, ghostscript +, imagemagick +, jbig2enc +, optipng +, pngquant +, qpdf +, tesseract4 +, unpaper +, liberation_ttf +}: + +let + py = python3.override { + packageOverrides = self: super: { + django = super.django_3; + + # Incompatible with aioredis 2 + aioredis = super.aioredis.overridePythonAttrs (oldAttrs: rec { + version = "1.3.1"; + src = oldAttrs.src.override { + inherit version; + sha256 = "0fi7jd5hlx8cnv1m97kv9hc4ih4l8v15wzkqwsp73is4n0qazy0m"; + }; + }); + }; + }; + + path = lib.makeBinPath [ ghostscript imagemagick jbig2enc optipng pngquant qpdf tesseract4 unpaper ]; +in +py.pkgs.pythonPackages.buildPythonApplication rec { + pname = "paperless-ngx"; + version = "1.6.0"; + + src = fetchurl { + url = "https://github.com/paperless-ngx/paperless-ngx/releases/download/ngx-${version}/${pname}-${version}.tar.xz"; + sha256 = "07mrxbwahkm00n9nvssd6d13p80w333g84cd38bzp0l34nzim5zl"; + }; + + format = "other"; + + propagatedBuildInputs = with py.pkgs.pythonPackages; [ + aioredis + arrow + asgiref + async-timeout + attrs + autobahn + automat + blessed + certifi + cffi + channels-redis + channels + chardet + click + coloredlogs + concurrent-log-handler + constantly + cryptography + daphne + dateparser + django-cors-headers + django-extensions + django-filter + django-picklefield + django-q + django + djangorestframework + filelock + fuzzywuzzy + gunicorn + h11 + hiredis + httptools + humanfriendly + hyperlink + idna + imap-tools + img2pdf + incremental + inotify-simple + inotifyrecursive + joblib + langdetect + lxml + msgpack + numpy + ocrmypdf + pathvalidate + pdfminer + pikepdf + pillow + pluggy + portalocker + psycopg2 + pyasn1-modules + pyasn1 + pycparser + pyopenssl + python-dateutil + python-dotenv + python-gnupg + python-Levenshtein + python_magic + pytz + pyyaml + redis + regex + reportlab + requests + scikit-learn + scipy + service-identity + six + sortedcontainers + sqlparse + threadpoolctl + tika + tqdm + twisted.extras.tls + txaio + tzlocal + urllib3 + uvicorn + uvloop + watchdog + watchgod + wcwidth + websockets + whitenoise + whoosh + zope_interface + ]; + + # Compile manually because `pythonRecompileBytecodeHook` only works for + # files in `python.sitePackages` + postBuild = '' + ${py.interpreter} -OO -m compileall src + ''; + + installPhase = '' + mkdir -p $out/lib + cp -r . $out/lib/paperless-ngx + 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}" + ''; + + checkInputs = with py.pkgs.pythonPackages; [ + pytest-django + pytest-env + pytest-sugar + pytest-xdist + factory_boy + pytestCheckHook + ]; + + pytestFlagsArray = [ "src" ]; + + # 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" "" + ''; + + passthru = { + # PYTHONPATH of all dependencies used by the package + pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs; + inherit path; + }; + + meta = with lib; { + description = "A supercharged version of paperless: scan, index, and archive all of your physical documents"; + homepage = "https://paperless-ngx.readthedocs.io/en/latest/"; + license = licenses.gpl3Only; + maintainers = with maintainers; [ lukegb ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cf2854ac7ed8..223fddea8bdc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8804,6 +8804,8 @@ with pkgs; paperless-ng = callPackage ../applications/office/paperless-ng { }; + paperless-ngx = callPackage ../applications/office/paperless-ngx { }; + paperwork = callPackage ../applications/office/paperwork/paperwork-gtk.nix { }; papertrail = callPackage ../tools/text/papertrail { }; From 99f40c2c13e48dc9c22221462d4d8b06d0930790 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 11 Apr 2022 17:06:01 +0200 Subject: [PATCH 2/6] paperless-ng: delete pkg, add alias to `paperless-ngx` --- .../office/paperless-ng/default.nix | 212 ------------------ pkgs/top-level/aliases.nix | 3 +- pkgs/top-level/all-packages.nix | 2 - 3 files changed, 2 insertions(+), 215 deletions(-) delete mode 100644 pkgs/applications/office/paperless-ng/default.nix diff --git a/pkgs/applications/office/paperless-ng/default.nix b/pkgs/applications/office/paperless-ng/default.nix deleted file mode 100644 index ab140f90ceda..000000000000 --- a/pkgs/applications/office/paperless-ng/default.nix +++ /dev/null @@ -1,212 +0,0 @@ -{ lib -, fetchurl -, fetchpatch -, nixosTests -, python3 -, ghostscript -, imagemagick -, jbig2enc -, optipng -, pngquant -, qpdf -, tesseract4 -, unpaper -, liberation_ttf -}: - -let - py = python3.override { - packageOverrides = self: super: { - django = super.django_3; - # Avoid warning in django-q versions > 1.3.4 - # https://github.com/jonaswinkler/paperless-ng/issues/857 - # https://github.com/Koed00/django-q/issues/526 - django-q = super.django-q.overridePythonAttrs (oldAttrs: rec { - version = "1.3.4"; - src = oldAttrs.src.override { - inherit version; - sha256 = "Uj1U3PG2YVLBtlj5FPAO07UYo0MqnezUiYc4yo274Q8="; - }; - }); - - # Incompatible with aioredis 2 - aioredis = super.aioredis.overridePythonAttrs (oldAttrs: rec { - version = "1.3.1"; - src = oldAttrs.src.override { - inherit version; - sha256 = "0fi7jd5hlx8cnv1m97kv9hc4ih4l8v15wzkqwsp73is4n0qazy0m"; - }; - }); - }; - }; - - path = lib.makeBinPath [ ghostscript imagemagick jbig2enc optipng pngquant qpdf tesseract4 unpaper ]; -in -py.pkgs.pythonPackages.buildPythonApplication rec { - pname = "paperless-ng"; - version = "1.5.0"; - - src = fetchurl { - url = "https://github.com/jonaswinkler/paperless-ng/releases/download/ng-${version}/${pname}-${version}.tar.xz"; - sha256 = "oVSq0AWksuWC81MF5xiZ6ZbdKKtqqphmL+xIzJLaDMw="; - }; - - patches = [ - # Fix the `slow_write_pdf` test: - # https://github.com/NixOS/nixpkgs/issues/136626 - (fetchpatch { - url = "https://github.com/paperless-ngx/paperless-ngx/commit/4fbabe43ea12811864e9676b04d82a82b38e799d.patch"; - sha256 = "sha256-8ULep5aeW3wJAQGy2OEAjFYybELNq1DzCC1uBrZx36I="; - }) - ]; - - format = "other"; - - # Make bind address configurable - postPatch = '' - substituteInPlace gunicorn.conf.py --replace "bind = '0.0.0.0:8000'" "" - ''; - - propagatedBuildInputs = with py.pkgs.pythonPackages; [ - aioredis - arrow - asgiref - async-timeout - attrs - autobahn - automat - blessed - certifi - cffi - channels-redis - channels - chardet - click - coloredlogs - concurrent-log-handler - constantly - cryptography - daphne - dateparser - django-cors-headers - django-extensions - django-filter - django-picklefield - django-q - django - djangorestframework - filelock - fuzzywuzzy - gunicorn - h11 - hiredis - httptools - humanfriendly - hyperlink - idna - imap-tools - img2pdf - incremental - inotify-simple - inotifyrecursive - joblib - langdetect - lxml - msgpack - numpy - ocrmypdf - pathvalidate - pdfminer - pikepdf - pillow - pluggy - portalocker - psycopg2 - pyasn1-modules - pyasn1 - pycparser - pyopenssl - python-dateutil - python-dotenv - python-gnupg - python-Levenshtein - python_magic - pytz - pyyaml - redis - regex - reportlab - requests - scikit-learn - scipy - service-identity - six - sortedcontainers - sqlparse - threadpoolctl - tika - tqdm - twisted.extras.tls - txaio - tzlocal - urllib3 - uvicorn - uvloop - watchdog - watchgod - wcwidth - websockets - whitenoise - whoosh - zope_interface - ]; - - installPhase = '' - mkdir -p $out/lib - cp -r . $out/lib/paperless-ng - chmod +x $out/lib/paperless-ng/src/manage.py - makeWrapper $out/lib/paperless-ng/src/manage.py $out/bin/paperless-ng \ - --prefix PYTHONPATH : "$PYTHONPATH" \ - --prefix PATH : "${path}" - ''; - - checkInputs = with py.pkgs.pythonPackages; [ - pytest-django - pytest-env - pytest-sugar - pytest-xdist - factory_boy - pytestCheckHook - ]; - - pytestFlagsArray = [ "src" ]; - - # 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" "" - ''; - - passthru = { - # PYTHONPATH of all dependencies used by the package - pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs; - inherit path; - - tests = { inherit (nixosTests) paperless-ng; }; - }; - - meta = with lib; { - description = "A supercharged version of paperless: scan, index, and archive all of your physical documents"; - homepage = "https://paperless-ng.readthedocs.io/en/latest/"; - license = licenses.gpl3Only; - maintainers = with maintainers; [ earvstedt Flakebi ]; - }; -} diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index 897005fecaeb..ba8063c60ca1 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -901,7 +901,8 @@ mapAliases ({ p11_kit = throw "'p11_kit' has been renamed to/replaced by 'p11-kit'"; # Converted to throw 2022-02-22 packet-cli = metal-cli; # Added 2021-10-25 - paperless = paperless-ng; # Added 2021-06-06 + paperless = paperless-ngx; # Added 2021-06-06 + paperless-ng = paperless-ngx; # Added 2022-04-11 parity = openethereum; # Added 2020-08-01 parity-ui = throw "parity-ui was removed because it was broken and unmaintained by upstream"; # Added 2022-01-10 parquet-cpp = throw "'parquet-cpp' has been renamed to/replaced by 'arrow-cpp'"; # Converted to throw 2022-02-22 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 223fddea8bdc..df3b962820c0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8802,8 +8802,6 @@ with pkgs; pantheon-tweaks = callPackage ../desktops/pantheon/third-party/pantheon-tweaks { }; - paperless-ng = callPackage ../applications/office/paperless-ng { }; - paperless-ngx = callPackage ../applications/office/paperless-ngx { }; paperwork = callPackage ../applications/office/paperwork/paperwork-gtk.nix { }; From 308c4bf0f7caaf59a42a9092d0e3a889490c7902 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 11 Apr 2022 17:06:02 +0200 Subject: [PATCH 3/6] nixos/paperless-ng: minor improvments Service: - Fix misleading comment: We could in fact implement password copying as a preStart script by amending BindReadOnlyPaths, but adding an extra service is simpler. Test: - Add more detailed subtest names - Simplify date check --- nixos/modules/services/misc/paperless-ng.nix | 4 +--- nixos/tests/paperless-ng.nix | 15 +++++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/nixos/modules/services/misc/paperless-ng.nix b/nixos/modules/services/misc/paperless-ng.nix index 881fa93c04ee..159aad3504bc 100644 --- a/nixos/modules/services/misc/paperless-ng.nix +++ b/nixos/modules/services/misc/paperless-ng.nix @@ -248,9 +248,7 @@ in after = [ "redis-paperless-ng.service" ]; }; - # Password copying can't be implemented as a privileged preStart script - # in 'paperless-ng-server' because 'defaultServiceConfig' limits the filesystem - # paths accessible by the service. + # Reading the user-provided password file requires root access systemd.services.paperless-ng-copy-password = mkIf (cfg.passwordFile != null) { requiredBy = [ "paperless-ng-server.service" ]; before = [ "paperless-ng-server.service" ]; diff --git a/nixos/tests/paperless-ng.nix b/nixos/tests/paperless-ng.nix index 618eeec6b125..8e9e28801910 100644 --- a/nixos/tests/paperless-ng.nix +++ b/nixos/tests/paperless-ng.nix @@ -11,9 +11,11 @@ import ./make-test-python.nix ({ lib, ... }: { }; testScript = '' + import json + machine.wait_for_unit("paperless-ng-consumer.service") - with subtest("Create test doc"): + with subtest("Add a document via the file system"): machine.succeed( "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black " "-annotate +5+20 'hello world 16-10-2005' /var/lib/paperless/consume/doc.png" @@ -24,7 +26,7 @@ import ./make-test-python.nix ({ lib, ... }: { # Wait until server accepts connections machine.wait_until_succeeds("curl -fs localhost:28981") - with subtest("Create web test doc"): + with subtest("Add a document via the web interface"): machine.succeed( "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black " "-annotate +5+20 'hello web 16-10-2005' /tmp/webdoc.png" @@ -35,11 +37,8 @@ import ./make-test-python.nix ({ lib, ... }: { machine.wait_until_succeeds( "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 2))" ) - assert "2005-10-16" in machine.succeed( - "curl -u admin:admin -fs localhost:28981/api/documents/ | jq '.results | .[0] | .created'" - ) - assert "2005-10-16" in machine.succeed( - "curl -u admin:admin -fs localhost:28981/api/documents/ | jq '.results | .[1] | .created'" - ) + docs = json.loads(machine.succeed("curl -u admin:admin -fs localhost:28981/api/documents/"))['results'] + assert "2005-10-16" in docs[0]['created'] + assert "2005-10-16" in docs[1]['created'] ''; }) From 69319ee4a6a611729e0907d6cc970201c9d2a654 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 11 Apr 2022 17:06:03 +0200 Subject: [PATCH 4/6] nixos/paperless-ng: fix /proc access for service This allows django-q to set the number of workers according to the CPU core count and to show memory stats via `manage.py qmonitor`. This also fixes a non-critical psutil error in paperless-ng-server. --- nixos/modules/services/misc/paperless-ng.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/misc/paperless-ng.nix b/nixos/modules/services/misc/paperless-ng.nix index 159aad3504bc..632e824755c4 100644 --- a/nixos/modules/services/misc/paperless-ng.nix +++ b/nixos/modules/services/misc/paperless-ng.nix @@ -53,7 +53,6 @@ let PrivateNetwork = true; PrivateTmp = true; PrivateUsers = true; - ProcSubset = "pid"; ProtectClock = true; # Breaks if the home dir of the user is in /home # Also does not add much value in combination with the TemporaryFileSystem. @@ -66,6 +65,10 @@ let ProtectKernelModules = true; ProtectKernelTunables = true; ProtectProc = "invisible"; + # Don't restrict ProcSubset because django-q requires read access to /proc/stat + # to query CPU and memory information. + # Note that /proc only contains processes of user `paperless`, so this is safe. + # ProcSubset = "pid"; RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ]; RestrictNamespaces = true; RestrictRealtime = true; From 46c333138443b76362591318ffd5541fcce53540 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Tue, 12 Apr 2022 17:46:57 +0200 Subject: [PATCH 5/6] nixos/paperless-ng: simplify redis logic - Rename `hasCustomRedis` -> `enableRedis` - Extract var `redisServer` --- nixos/modules/services/misc/paperless-ng.nix | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nixos/modules/services/misc/paperless-ng.nix b/nixos/modules/services/misc/paperless-ng.nix index 632e824755c4..2aa94199b0a4 100644 --- a/nixos/modules/services/misc/paperless-ng.nix +++ b/nixos/modules/services/misc/paperless-ng.nix @@ -6,7 +6,9 @@ let defaultUser = "paperless"; - hasCustomRedis = hasAttr "PAPERLESS_REDIS" cfg.extraConfig; + # Don't start a redis instance if the user sets a custom redis connection + enableRedis = !hasAttr "PAPERLESS_REDIS" cfg.extraConfig; + redisServer = config.services.redis.servers.paperless-ng; env = { PAPERLESS_DATA_DIR = cfg.dataDir; @@ -15,8 +17,8 @@ let GUNICORN_CMD_ARGS = "--bind=${cfg.address}:${toString cfg.port}"; } // ( lib.mapAttrs (_: toString) cfg.extraConfig - ) // (optionalAttrs (!hasCustomRedis) { - PAPERLESS_REDIS = "unix://${config.services.redis.servers.paperless-ng.unixSocket}"; + ) // (optionalAttrs enableRedis { + PAPERLESS_REDIS = "unix://${redisServer.unixSocket}"; }); manage = let @@ -36,7 +38,7 @@ let "-/etc/hosts" "-/etc/localtime" "-/run/postgresql" - ] ++ (optional (!hasCustomRedis) config.services.redis.servers.paperless-ng.unixSocket); + ] ++ (optional enableRedis redisServer.unixSocket); BindPaths = [ cfg.consumptionDir cfg.dataDir @@ -73,7 +75,7 @@ let RestrictNamespaces = true; RestrictRealtime = true; RestrictSUIDSGID = true; - SupplementaryGroups = optional (!hasCustomRedis) config.services.redis.servers.paperless-ng.user; + SupplementaryGroups = optional enableRedis redisServer.user; SystemCallArchitectures = "native"; SystemCallFilter = [ "@system-service" "~@privileged @resources @setuid @keyring" ]; # Does not work well with the temporary root @@ -198,8 +200,7 @@ in }; config = mkIf cfg.enable { - # Enable redis if no special url is set - services.redis.servers.paperless-ng.enable = mkIf (!hasCustomRedis) true; + services.redis.servers.paperless-ng.enable = mkIf enableRedis true; systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -" @@ -247,7 +248,7 @@ in echo "$superuserState" > "$superuserStateFile" fi ''; - } // optionalAttrs (!hasCustomRedis) { + } // optionalAttrs enableRedis { after = [ "redis-paperless-ng.service" ]; }; From 0977227b8622daccb5a8435d3d4216eedf845973 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Tue, 12 Apr 2022 17:48:53 +0200 Subject: [PATCH 6/6] nixos/paperless-ng: rename to `paperless`, use `paperless-ngx` package Use this opportunity to rename `paperless-(ng)-server` to `paperless-scheduler`. This follows the naming scheme in the paperless repo and docs. --- .../from_md/release-notes/rl-2205.section.xml | 11 +++ .../manual/release-notes/rl-2205.section.md | 2 + nixos/modules/module-list.nix | 2 +- .../misc/{paperless-ng.nix => paperless.nix} | 78 +++++++++---------- nixos/tests/all-tests.nix | 2 +- .../tests/{paperless-ng.nix => paperless.nix} | 8 +- .../office/paperless-ngx/default.nix | 2 + 7 files changed, 58 insertions(+), 47 deletions(-) rename nixos/modules/services/misc/{paperless-ng.nix => paperless.nix} (79%) rename nixos/tests/{paperless-ng.nix => paperless.nix} (90%) diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index a1e7a35ab058..dfc55d7f3109 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -550,6 +550,17 @@ work. + + + services.paperless-ng was renamed to + services.paperless. Accordingly, the + paperless-ng-manage script (located in + dataDir) was renamed to + paperless-manage. + services.paperless now uses + paperless-ngx. + + The matrix-synapse service diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 20dbcf998d99..fcb356f546fa 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -182,6 +182,8 @@ In addition to numerous new and upgraded packages, this release has the followin - `services.ipfs.extraFlags` is now escaped with `utils.escapeSystemdExecArgs`. If you rely on systemd interpolating `extraFlags` in the service `ExecStart`, this will no longer work. +- `services.paperless-ng` was renamed to `services.paperless`. Accordingly, the `paperless-ng-manage` script (located in `dataDir`) was renamed to `paperless-manage`. `services.paperless` now uses `paperless-ngx`. + - The `matrix-synapse` service (`services.matrix-synapse`) has been converted to use the `settings` option defined in RFC42. This means that options that are part of your `homeserver.yaml` configuration, and that were specified at the top-level of the module (`services.matrix-synapse`) now need to be moved into `services.matrix-synapse.settings`. And while not all options you diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 2901df81bf26..2452ee685eb5 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -597,7 +597,7 @@ ./services/misc/osrm.nix ./services/misc/owncast.nix ./services/misc/packagekit.nix - ./services/misc/paperless-ng.nix + ./services/misc/paperless.nix ./services/misc/parsoid.nix ./services/misc/plex.nix ./services/misc/plikd.nix diff --git a/nixos/modules/services/misc/paperless-ng.nix b/nixos/modules/services/misc/paperless.nix similarity index 79% rename from nixos/modules/services/misc/paperless-ng.nix rename to nixos/modules/services/misc/paperless.nix index 2aa94199b0a4..bfaf842fb464 100644 --- a/nixos/modules/services/misc/paperless-ng.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -2,13 +2,13 @@ with lib; let - cfg = config.services.paperless-ng; + cfg = config.services.paperless; defaultUser = "paperless"; # Don't start a redis instance if the user sets a custom redis connection enableRedis = !hasAttr "PAPERLESS_REDIS" cfg.extraConfig; - redisServer = config.services.redis.servers.paperless-ng; + redisServer = config.services.redis.servers.paperless; env = { PAPERLESS_DATA_DIR = cfg.dataDir; @@ -25,7 +25,7 @@ let setupEnv = lib.concatStringsSep "\n" (mapAttrsToList (name: val: "export ${name}=\"${val}\"") env); in pkgs.writeShellScript "manage" '' ${setupEnv} - exec ${cfg.package}/bin/paperless-ng "$@" + exec ${cfg.package}/bin/paperless-ngx "$@" ''; # Secure the services @@ -86,26 +86,22 @@ in meta.maintainers = with maintainers; [ earvstedt Flakebi ]; imports = [ - (mkRemovedOptionModule [ "services" "paperless"] '' - The paperless module has been removed as the upstream project died. - Users should migrate to the paperless-ng module (services.paperless-ng). - More information can be found in the NixOS 21.11 release notes. - '') + (mkRenamedOptionModule [ "services" "paperless-ng" ] [ "services" "paperless" ]) ]; - options.services.paperless-ng = { + options.services.paperless = { enable = mkOption { type = lib.types.bool; default = false; description = '' - Enable Paperless-ng. + Enable Paperless. When started, the Paperless database is automatically created if it doesn't exist and updated if the Paperless package has changed. Both tasks are achieved by running a Django migration. A script to manage the Paperless instance (by wrapping Django's manage.py) is linked to - ''${dataDir}/paperless-ng-manage. + ''${dataDir}/paperless-manage. ''; }; @@ -138,13 +134,13 @@ in passwordFile = mkOption { type = types.nullOr types.path; default = null; - example = "/run/keys/paperless-ng-password"; + example = "/run/keys/paperless-password"; description = '' A file containing the superuser password. A superuser is required to access the web interface. If unset, you can create a superuser manually by running - ''${dataDir}/paperless-ng-manage createsuperuser. + ''${dataDir}/paperless-manage createsuperuser. The default superuser name is admin. To change it, set option . @@ -173,9 +169,9 @@ in type = types.attrs; default = {}; description = '' - Extra paperless-ng config options. + Extra paperless config options. - See the documentation + See the documentation for available options. ''; example = literalExpression '' @@ -193,14 +189,14 @@ in package = mkOption { type = types.package; - default = pkgs.paperless-ng; - defaultText = literalExpression "pkgs.paperless-ng"; + default = pkgs.paperless-ngx; + defaultText = literalExpression "pkgs.paperless-ngx"; description = "The Paperless package to use."; }; }; config = mkIf cfg.enable { - services.redis.servers.paperless-ng.enable = mkIf enableRedis true; + services.redis.servers.paperless.enable = mkIf enableRedis true; systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -" @@ -212,11 +208,11 @@ in ) ]; - systemd.services.paperless-ng-server = { - description = "Paperless document server"; + systemd.services.paperless-scheduler = { + description = "Paperless scheduler"; serviceConfig = defaultServiceConfig // { User = cfg.user; - ExecStart = "${cfg.package}/bin/paperless-ng qcluster"; + ExecStart = "${cfg.package}/bin/paperless-ngx qcluster"; Restart = "on-failure"; # The `mbind` syscall is needed for running the classifier. SystemCallFilter = defaultServiceConfig.SystemCallFilter ++ [ "mbind" ]; @@ -225,15 +221,15 @@ in }; environment = env; wantedBy = [ "multi-user.target" ]; - wants = [ "paperless-ng-consumer.service" "paperless-ng-web.service" ]; + wants = [ "paperless-consumer.service" "paperless-web.service" ]; preStart = '' - ln -sf ${manage} ${cfg.dataDir}/paperless-ng-manage + ln -sf ${manage} ${cfg.dataDir}/paperless-manage # Auto-migrate on first run or if the package has changed versionFile="${cfg.dataDir}/src-version" if [[ $(cat "$versionFile" 2>/dev/null) != ${cfg.package} ]]; then - ${cfg.package}/bin/paperless-ng migrate + ${cfg.package}/bin/paperless-ngx migrate echo ${cfg.package} > "$versionFile" fi '' @@ -244,18 +240,18 @@ in superuserStateFile="${cfg.dataDir}/superuser-state" if [[ $(cat "$superuserStateFile" 2>/dev/null) != $superuserState ]]; then - ${cfg.package}/bin/paperless-ng manage_superuser + ${cfg.package}/bin/paperless-ngx manage_superuser echo "$superuserState" > "$superuserStateFile" fi ''; } // optionalAttrs enableRedis { - after = [ "redis-paperless-ng.service" ]; + after = [ "redis-paperless.service" ]; }; # Reading the user-provided password file requires root access - systemd.services.paperless-ng-copy-password = mkIf (cfg.passwordFile != null) { - requiredBy = [ "paperless-ng-server.service" ]; - before = [ "paperless-ng-server.service" ]; + systemd.services.paperless-copy-password = mkIf (cfg.passwordFile != null) { + requiredBy = [ "paperless-scheduler.service" ]; + before = [ "paperless-scheduler.service" ]; serviceConfig = { ExecStart = '' ${pkgs.coreutils}/bin/install --mode 600 --owner '${cfg.user}' --compare \ @@ -265,27 +261,27 @@ in }; }; - systemd.services.paperless-ng-consumer = { + systemd.services.paperless-consumer = { description = "Paperless document consumer"; serviceConfig = defaultServiceConfig // { User = cfg.user; - ExecStart = "${cfg.package}/bin/paperless-ng document_consumer"; + ExecStart = "${cfg.package}/bin/paperless-ngx document_consumer"; Restart = "on-failure"; }; environment = env; - # Bind to `paperless-ng-server` so that the consumer never runs + # Bind to `paperless-scheduler` so that the consumer never runs # during migrations - bindsTo = [ "paperless-ng-server.service" ]; - after = [ "paperless-ng-server.service" ]; + bindsTo = [ "paperless-scheduler.service" ]; + after = [ "paperless-scheduler.service" ]; }; - systemd.services.paperless-ng-web = { + systemd.services.paperless-web = { description = "Paperless web server"; serviceConfig = defaultServiceConfig // { User = cfg.user; ExecStart = '' ${pkgs.python3Packages.gunicorn}/bin/gunicorn \ - -c ${cfg.package}/lib/paperless-ng/gunicorn.conf.py paperless.asgi:application + -c ${cfg.package}/lib/paperless-ngx/gunicorn.conf.py paperless.asgi:application ''; Restart = "on-failure"; @@ -298,15 +294,15 @@ in }; environment = env // { PATH = mkForce cfg.package.path; - PYTHONPATH = "${cfg.package.pythonPath}:${cfg.package}/lib/paperless-ng/src"; + PYTHONPATH = "${cfg.package.pythonPath}:${cfg.package}/lib/paperless-ngx/src"; }; # Allow the web interface to access the private /tmp directory of the server. # This is required to support uploading files via the web interface. - unitConfig.JoinsNamespaceOf = "paperless-ng-server.service"; - # Bind to `paperless-ng-server` so that the web server never runs + unitConfig.JoinsNamespaceOf = "paperless-scheduler.service"; + # Bind to `paperless-scheduler` so that the web server never runs # during migrations - bindsTo = [ "paperless-ng-server.service" ]; - after = [ "paperless-ng-server.service" ]; + bindsTo = [ "paperless-scheduler.service" ]; + after = [ "paperless-scheduler.service" ]; }; users = optionalAttrs (cfg.user == defaultUser) { diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 44eeceda99eb..0a7352913537 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -402,7 +402,7 @@ in pam-ussh = handleTest ./pam/pam-ussh.nix {}; pantalaimon = handleTest ./matrix/pantalaimon.nix {}; pantheon = handleTest ./pantheon.nix {}; - paperless-ng = handleTest ./paperless-ng.nix {}; + paperless = handleTest ./paperless.nix {}; parsedmarc = handleTest ./parsedmarc {}; pdns-recursor = handleTest ./pdns-recursor.nix {}; peerflix = handleTest ./peerflix.nix {}; diff --git a/nixos/tests/paperless-ng.nix b/nixos/tests/paperless.nix similarity index 90% rename from nixos/tests/paperless-ng.nix rename to nixos/tests/paperless.nix index 8e9e28801910..51fe7c207851 100644 --- a/nixos/tests/paperless-ng.nix +++ b/nixos/tests/paperless.nix @@ -1,10 +1,10 @@ import ./make-test-python.nix ({ lib, ... }: { - name = "paperless-ng"; + name = "paperless"; meta.maintainers = with lib.maintainers; [ earvstedt Flakebi ]; nodes.machine = { pkgs, ... }: { environment.systemPackages = with pkgs; [ imagemagick jq ]; - services.paperless-ng = { + services.paperless = { enable = true; passwordFile = builtins.toFile "password" "admin"; }; @@ -13,7 +13,7 @@ import ./make-test-python.nix ({ lib, ... }: { testScript = '' import json - machine.wait_for_unit("paperless-ng-consumer.service") + machine.wait_for_unit("paperless-consumer.service") with subtest("Add a document via the file system"): machine.succeed( @@ -22,7 +22,7 @@ import ./make-test-python.nix ({ lib, ... }: { ) with subtest("Web interface gets ready"): - machine.wait_for_unit("paperless-ng-web.service") + machine.wait_for_unit("paperless-web.service") # Wait until server accepts connections machine.wait_until_succeeds("curl -fs localhost:28981") diff --git a/pkgs/applications/office/paperless-ngx/default.nix b/pkgs/applications/office/paperless-ngx/default.nix index be22ca7c26cd..ec83da852aba 100644 --- a/pkgs/applications/office/paperless-ngx/default.nix +++ b/pkgs/applications/office/paperless-ngx/default.nix @@ -181,6 +181,8 @@ py.pkgs.pythonPackages.buildPythonApplication rec { # PYTHONPATH of all dependencies used by the package pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs; inherit path; + + tests = { inherit (nixosTests) paperless; }; }; meta = with lib; {