2024-01-30 12:22:04 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2021-08-19 13:05:08 +02:00
|
|
|
let
|
|
|
|
cfg = config.my.services.paperless;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.services.paperless = with lib; {
|
|
|
|
enable = mkEnableOption "Paperless service";
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 4535;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for webui";
|
|
|
|
};
|
|
|
|
|
2021-09-25 13:15:34 +02:00
|
|
|
secretKeyFile = mkOption {
|
2021-08-19 13:05:08 +02:00
|
|
|
type = types.str;
|
2021-09-25 13:15:34 +02:00
|
|
|
example = "/var/lib/paperless/secret-key.env";
|
|
|
|
description = ''
|
|
|
|
Secret key as an 'EnvironmentFile' (see `systemd.exec(5)`)
|
|
|
|
'';
|
2021-08-19 13:05:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
documentPath = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "/mnt/paperless";
|
|
|
|
description = ''
|
|
|
|
Path to the directory to store the documents. Use default if null
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ambroisie";
|
|
|
|
example = "username";
|
|
|
|
description = "Name of the administrator";
|
|
|
|
};
|
2021-08-30 20:37:18 +02:00
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/var/lib/paperless/password.txt";
|
|
|
|
description = "Read the administrator's password from this path";
|
|
|
|
};
|
2021-08-19 13:05:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2022-04-18 14:09:38 +02:00
|
|
|
services.paperless = {
|
2021-08-19 13:05:08 +02:00
|
|
|
enable = true;
|
|
|
|
|
|
|
|
port = cfg.port;
|
|
|
|
|
|
|
|
mediaDir = lib.mkIf (cfg.documentPath != null) cfg.documentPath;
|
|
|
|
|
2024-01-22 17:57:18 +01:00
|
|
|
settings =
|
2021-08-19 13:05:08 +02:00
|
|
|
let
|
|
|
|
paperlessDomain = "paperless.${config.networking.domain}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
# Use SSO
|
|
|
|
PAPERLESS_ENABLE_HTTP_REMOTE_USER = true;
|
|
|
|
PAPERLESS_HTTP_REMOTE_USER_HEADER_NAME = "HTTP_X_USER";
|
|
|
|
|
|
|
|
# Use PostgreSQL
|
|
|
|
PAPERLESS_DBHOST = "/run/postgresql";
|
|
|
|
PAPERLESS_DBUSER = "paperless";
|
|
|
|
PAPERLESS_DBNAME = "paperless";
|
|
|
|
|
|
|
|
# Security settings
|
|
|
|
PAPERLESS_ALLOWED_HOSTS = paperlessDomain;
|
|
|
|
PAPERLESS_CORS_ALLOWED_HOSTS = "https://${paperlessDomain}";
|
|
|
|
|
|
|
|
# OCR settings
|
|
|
|
PAPERLESS_OCR_LANGUAGE = "fra+eng";
|
|
|
|
|
2023-09-18 15:43:33 +02:00
|
|
|
# Workers
|
|
|
|
PAPERLESS_TASK_WORKERS = 3;
|
|
|
|
PAPERLESS_THREADS_PER_WORKER = 4;
|
|
|
|
|
2021-08-19 13:05:08 +02:00
|
|
|
# Misc
|
|
|
|
PAPERLESS_TIME_ZONE = config.time.timeZone;
|
|
|
|
PAPERLESS_ADMIN_USER = cfg.username;
|
2024-01-30 12:22:04 +01:00
|
|
|
|
|
|
|
# Fix classifier hangs
|
|
|
|
LD_LIBRARY_PATH = "${lib.getLib pkgs.mkl}/lib";
|
2021-08-19 13:05:08 +02:00
|
|
|
};
|
2021-08-30 20:37:18 +02:00
|
|
|
|
|
|
|
# Admin password
|
|
|
|
passwordFile = cfg.passwordFile;
|
2021-08-19 13:05:08 +02:00
|
|
|
};
|
|
|
|
|
2021-09-25 13:15:34 +02:00
|
|
|
systemd.services = {
|
2022-07-28 17:53:55 +02:00
|
|
|
paperless-scheduler = {
|
2022-10-07 15:07:04 +02:00
|
|
|
requires = [ "postgresql.service" ];
|
2022-07-28 17:53:55 +02:00
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
|
|
|
};
|
2021-09-25 13:15:34 +02:00
|
|
|
};
|
|
|
|
|
2022-07-28 17:53:55 +02:00
|
|
|
paperless-consumer = {
|
2022-10-07 15:07:04 +02:00
|
|
|
requires = [ "postgresql.service" ];
|
2022-07-28 17:53:55 +02:00
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
|
|
|
};
|
2021-09-25 13:15:34 +02:00
|
|
|
};
|
|
|
|
|
2022-07-28 17:53:55 +02:00
|
|
|
paperless-web = {
|
2022-10-07 15:07:04 +02:00
|
|
|
requires = [ "postgresql.service" ];
|
2023-03-23 13:16:40 +01:00
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
paperless-task-queue = {
|
|
|
|
requires = [ "postgresql.service" ];
|
2022-07-28 17:53:55 +02:00
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
|
|
|
};
|
2021-09-25 13:15:34 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-08-19 13:05:08 +02:00
|
|
|
# Set-up database
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "paperless" ];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "paperless";
|
2023-11-21 00:18:29 +01:00
|
|
|
ensureDBOwnership = true;
|
2021-08-19 13:05:08 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-09-15 15:57:23 +02:00
|
|
|
# Set-up media group
|
|
|
|
users.groups.media = { };
|
|
|
|
|
2022-04-18 14:09:38 +02:00
|
|
|
users.users.${config.services.paperless.user} = {
|
2021-08-19 13:05:08 +02:00
|
|
|
extraGroups = [ "media" ];
|
|
|
|
};
|
|
|
|
|
2023-12-25 19:25:08 +01:00
|
|
|
my.services.nginx.virtualHosts = {
|
|
|
|
paperless = {
|
2021-08-19 13:05:08 +02:00
|
|
|
inherit (cfg) port;
|
|
|
|
sso = {
|
|
|
|
enable = true;
|
|
|
|
};
|
2021-08-30 21:02:47 +02:00
|
|
|
|
|
|
|
# Enable websockets on root
|
|
|
|
extraConfig = {
|
|
|
|
locations."/".proxyWebsockets = true;
|
|
|
|
};
|
2023-12-25 19:25:08 +01:00
|
|
|
};
|
|
|
|
};
|
2021-08-19 13:05:08 +02:00
|
|
|
|
|
|
|
my.services.backup = {
|
|
|
|
paths = [
|
2022-04-18 14:09:38 +02:00
|
|
|
config.services.paperless.dataDir
|
|
|
|
config.services.paperless.mediaDir
|
2021-08-19 13:05:08 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|