{ lib, config, ... }: with lib; { options = { paperless = { enable = mkEnableOption "enables paperless"; port = lib.mkOption { type = lib.types.int; default = 8089; description = "The port that paperless is served on."; }; hostname = lib.mkOption { type = lib.types.str; default = "127.0.0.1"; description = "The hostname that paperless is served on."; }; domain = lib.mkOption { type = lib.types.str; default = "paperless.wastring.com"; description = "The domain that paperless is served on."; }; }; }; config = mkMerge [ (mkIf config.paperless.enable { sops.secrets.paperless-admin-password = { }; services.nginx.virtualHosts.${config.paperless.domain} = { forceSSL = true; enableACME = true; locations."/" = { proxyPass = "http://${toString config.paperless.hostname}:${toString config.paperless.port}"; proxyWebsockets = true; }; }; services.paperless = { enable = true; passwordFile = config.sops.secrets.paperless-admin-password.path; address = config.paperless.hostname; port = config.paperless.port; consumptionDirIsPublic = true; settings = { PAPERLESS_CONSUMER_IGNORE_PATTERN = [ ".DS_STORE/*" "desktop.ini" ]; PAPERLESS_OCR_LANGUAGE = "swe+eng"; PAPERLESS_OCR_USER_ARGS = { optimize = 1; pdfa_image_compression = "lossless"; }; PAPERLESS_URL = "https://${toString config.paperless.domain}"; }; }; }) ]; }