about summary refs log tree commit diff
path: root/nixos/modules/services/misc
diff options
context:
space:
mode:
authorLeona Maroni <dev@leona.is>2024-02-01 16:53:15 +0100
committerLeona Maroni <dev@leona.is>2024-02-01 16:53:34 +0100
commit6300f478e9d9a9a0f0d66004e50e67a107f9cea3 (patch)
treed7173d9560a0ad19a0acc868d634793f1cf673a0 /nixos/modules/services/misc
parent3d195bb8598ac46b3316e9e3bff213ec020e7116 (diff)
downloadnixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.tar
nixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.tar.gz
nixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.tar.bz2
nixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.tar.lz
nixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.tar.xz
nixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.tar.zst
nixlib-6300f478e9d9a9a0f0d66004e50e67a107f9cea3.zip
nixos/paperless: use nltk_data package as NLTK data source
nixos
Diffstat (limited to 'nixos/modules/services/misc')
-rw-r--r--nixos/modules/services/misc/paperless.nix24
1 files changed, 5 insertions, 19 deletions
diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix
index ca34a327dbdf..5193cabe63ac 100644
--- a/nixos/modules/services/misc/paperless.nix
+++ b/nixos/modules/services/misc/paperless.nix
@@ -6,7 +6,6 @@ let
   pkg = cfg.package;
 
   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
@@ -17,13 +16,17 @@ let
     PAPERLESS_DATA_DIR = cfg.dataDir;
     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;
   } // optionalAttrs enableRedis {
     PAPERLESS_REDIS = "unix://${redisServer.unixSocket}";
+  } // optionalAttrs (cfg.settings.PAPERLESS_ENABLE_NLTK or true) {
+    PAPERLESS_NLTK_DIR = pkgs.symlinkJoin {
+      name = "paperless_ngx_nltk_data";
+      paths = pkg.nltkData;
+    };
   } // (lib.mapAttrs (_: s:
     if (lib.isAttrs s || lib.isList s) then builtins.toJSON s
     else if lib.isBool s then lib.boolToString s
@@ -292,23 +295,6 @@ in
       };
     };
 
-    # Download NLTK corpus data
-    systemd.services.paperless-download-nltk-data = {
-      wantedBy = [ "paperless-scheduler.service" ];
-      before = [ "paperless-scheduler.service" ];
-      after = [ "network-online.target" ];
-      wants = [ "network-online.target" ];
-      serviceConfig = defaultServiceConfig // {
-        User = cfg.user;
-        Type = "oneshot";
-        # Enable internet access
-        PrivateNetwork = false;
-        ExecStart = let pythonWithNltk = pkg.python.withPackages (ps: [ ps.nltk ]); in ''
-          ${pythonWithNltk}/bin/python -m nltk.downloader -d '${nltkDir}' punkt snowball_data stopwords
-        '';
-      };
-    };
-
     systemd.services.paperless-consumer = {
       description = "Paperless document consumer";
       # Bind to `paperless-scheduler` so that the consumer never runs