From 540a20546a1bd40622b678d8f603d2503f1d5bd8 Mon Sep 17 00:00:00 2001 From: Gregor Godbersen Date: Sat, 5 Aug 2023 22:06:01 +0200 Subject: [PATCH 1/2] nixos/paperless: add test for plaintext document --- nixos/tests/paperless.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nixos/tests/paperless.nix b/nixos/tests/paperless.nix index 7f36de4c29b7..ce6a4d8128df 100644 --- a/nixos/tests/paperless.nix +++ b/nixos/tests/paperless.nix @@ -30,20 +30,27 @@ import ./make-test-python.nix ({ lib, ... }: { with subtest("Task-queue gets ready"): machine.wait_for_unit("paperless-task-queue.service") - with subtest("Add a document via the web interface"): + with subtest("Add a png 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" ) machine.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.png -fs localhost:28981/api/documents/post_document/") + with subtest("Add a txt document via the web interface"): + machine.succeed( + "echo 'hello web 16-10-2005' > /tmp/webdoc.txt" + ) + machine.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.txt -fs localhost:28981/api/documents/post_document/") + with subtest("Documents are consumed"): machine.wait_until_succeeds( - "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 2))" + "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 3))" ) 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'] + assert "2005-10-16" in docs[2]['created'] # Detects gunicorn issues, see PR #190888 with subtest("Document metadata can be accessed"): @@ -52,5 +59,8 @@ import ./make-test-python.nix ({ lib, ... }: { metadata = json.loads(machine.succeed("curl -u admin:admin -fs localhost:28981/api/documents/2/metadata/")) assert "original_checksum" in metadata + + metadata = json.loads(machine.succeed("curl -u admin:admin -fs localhost:28981/api/documents/3/metadata/")) + assert "original_checksum" in metadata ''; }) From 3d9a6399a1a90c8f811285672e03b19f250bad4b Mon Sep 17 00:00:00 2001 From: Gregor Godbersen Date: Sat, 5 Aug 2023 20:45:07 +0200 Subject: [PATCH 2/2] nixos/paperless: set default thumbnail font The upstream default for the thumbnail font is set to "Liberation Serif Regular" located at /usr/share/fonts which is inaccessible under nix. (https://github.com/paperless-ngx/paperless-ngx/blob/2a2bf3bf55be5c591d496d974e9b5e94b0259d28/src/paperless/settings.py#L894) Paperless throws an error when parsing plaintext files without a valid font. This change sets a nix default using the liberation_ttf package. --- nixos/modules/services/misc/paperless.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index 1845d8ad29b5..0683a1f922ab 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -7,6 +7,7 @@ let defaultUser = "paperless"; nltkDir = "/var/cache/paperless/nltk"; + defaultFont = "${pkgs.liberation_ttf}/share/fonts/truetype/LiberationSerif-Regular.ttf"; # Don't start a redis instance if the user sets a custom redis connection enableRedis = !hasAttr "PAPERLESS_REDIS" cfg.extraConfig; @@ -17,6 +18,7 @@ let PAPERLESS_MEDIA_ROOT = cfg.mediaDir; PAPERLESS_CONSUMPTION_DIR = cfg.consumptionDir; PAPERLESS_NLTK_DIR = nltkDir; + PAPERLESS_THUMBNAIL_FONT_NAME = defaultFont; GUNICORN_CMD_ARGS = "--bind=${cfg.address}:${toString cfg.port}"; } // optionalAttrs (config.time.timeZone != null) { PAPERLESS_TIME_ZONE = config.time.timeZone;