From 88e40e42ef193e3fd76dc62b624ee8863627a53e Mon Sep 17 00:00:00 2001 From: flakeuser <2792697+Jdogzz@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:13:05 -0700 Subject: [PATCH] nixos/services.paperless: add extra files OCR This adds a setting for processing extra files with OCR through tika and gotenberg --- nixos/modules/services/misc/paperless.nix | 38 +++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index c1f35526bd9b..a9cb6f436872 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -357,6 +357,14 @@ in description = "Settings to pass to the document exporter as CLI arguments."; }; }; + + configureTika = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether to configure Tika and Gotenberg to process Office and e-mail files with OCR. + ''; + }; }; config = lib.mkIf cfg.enable ( @@ -377,12 +385,18 @@ in ]; }; - services.paperless.settings = lib.mkIf cfg.database.createLocally { - PAPERLESS_DBENGINE = "postgresql"; - PAPERLESS_DBHOST = "/run/postgresql"; - PAPERLESS_DBNAME = "paperless"; - PAPERLESS_DBUSER = "paperless"; - }; + services.paperless.settings = lib.mkMerge [ + (lib.mkIf cfg.database.createLocally { + PAPERLESS_DBENGINE = "postgresql"; + PAPERLESS_DBHOST = "/run/postgresql"; + PAPERLESS_DBNAME = "paperless"; + PAPERLESS_DBUSER = "paperless"; + }) + (lib.mkIf cfg.configureTika { + PAPERLESS_GOTENBERG_ENABLED = true; + PAPERLESS_TIKA_ENABLED = true; + }) + ]; systemd.slices.system-paperless = { description = "Paperless Document Management System Slice"; @@ -571,6 +585,18 @@ in gid = config.ids.gids.paperless; }; }; + + services.gotenberg = lib.mkIf cfg.configureTika { + enable = true; + # https://github.com/paperless-ngx/paperless-ngx/blob/v2.15.3/docker/compose/docker-compose.sqlite-tika.yml#L64-L69 + chromium.disableJavascript = true; + extraArgs = [ "--chromium-allow-list=file:///tmp/.*" ]; + }; + + services.tika = lib.mkIf cfg.configureTika { + enable = true; + enableOcr = true; + }; } (lib.mkIf cfg.exporter.enable {