2022-04-10 11:54:58 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
2022-01-11 16:08:21 +01:00
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
2022-04-10 11:54:58 +02:00
|
|
|
;
|
2022-01-11 16:08:21 +01:00
|
|
|
|
2021-07-12 19:07:39 +02:00
|
|
|
cfg = config.my.services.paperless;
|
|
|
|
my = config.my;
|
|
|
|
domain = config.networking.domain;
|
2021-12-22 19:17:16 +01:00
|
|
|
paperlessDomain = "paperless.${domain}";
|
2022-04-10 11:54:58 +02:00
|
|
|
in {
|
|
|
|
options.my.services.paperless = let
|
|
|
|
inherit (lib) types;
|
|
|
|
in {
|
2022-01-11 16:08:21 +01:00
|
|
|
enable = mkEnableOption "Paperless";
|
2021-07-12 19:07:39 +02:00
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for Paperless service";
|
|
|
|
};
|
2022-03-11 18:55:56 +01:00
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Path to a file containing the admin's password
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secretKeyFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Path to a file containing the service's secret key
|
|
|
|
'';
|
|
|
|
};
|
2021-07-12 19:07:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-04-15 16:17:14 +02:00
|
|
|
services.paperless = {
|
2021-12-22 19:17:16 +01:00
|
|
|
enable = true;
|
|
|
|
port = cfg.port;
|
2022-03-11 18:55:56 +01:00
|
|
|
passwordFile = cfg.passwordFile;
|
2021-12-22 19:17:16 +01:00
|
|
|
extraConfig = {
|
|
|
|
# Postgres settings
|
|
|
|
PAPERLESS_DBHOST = "/run/postgresql";
|
|
|
|
PAPERLESS_DBUSER = "paperless";
|
|
|
|
PAPERLESS_DBNAME = "paperless";
|
|
|
|
|
|
|
|
PAPERLESS_ALLOWED_HOSTS = paperlessDomain;
|
|
|
|
PAPERLESS_CORS_ALLOWED_HOSTS = "https://${paperlessDomain}";
|
|
|
|
|
|
|
|
PAPERLESS_OCR_LANGUAGE = "fra+eng";
|
2021-12-22 22:54:00 +01:00
|
|
|
PAPERLESS_OCR_MODE = "skip_noarchive";
|
2021-12-22 19:17:16 +01:00
|
|
|
|
|
|
|
PAPERLESS_TIME_ZONE = config.time.timeZone;
|
|
|
|
|
|
|
|
PAPERLESS_ADMIN_USER = "alarsyo";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services = {
|
2022-04-26 16:24:20 +02:00
|
|
|
paperless-scheduler.serviceConfig = {
|
2022-03-11 18:55:56 +01:00
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
2021-12-22 19:17:16 +01:00
|
|
|
};
|
|
|
|
|
2022-04-15 16:17:14 +02:00
|
|
|
paperless-consumer.serviceConfig = {
|
2022-03-11 18:55:56 +01:00
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
2021-12-22 19:17:16 +01:00
|
|
|
};
|
|
|
|
|
2022-04-15 16:17:14 +02:00
|
|
|
paperless-web.serviceConfig = {
|
2022-03-11 18:55:56 +01:00
|
|
|
EnvironmentFile = cfg.secretKeyFile;
|
2021-12-22 19:17:16 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2022-04-10 11:54:58 +02:00
|
|
|
ensureDatabases = ["paperless"];
|
2021-12-22 19:17:16 +01:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "paperless";
|
|
|
|
ensurePermissions."DATABASE paperless" = "ALL PRIVILEGES";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-04-15 16:17:14 +02:00
|
|
|
systemd.services.paperless-server = {
|
2021-12-22 19:17:16 +01:00
|
|
|
# Make sure the DB is available
|
2022-04-10 11:54:58 +02:00
|
|
|
after = ["postgresql.service"];
|
2021-12-22 19:17:16 +01:00
|
|
|
};
|
2021-07-13 13:15:38 +02:00
|
|
|
|
2021-07-12 19:07:39 +02:00
|
|
|
services.nginx.virtualHosts = {
|
2021-12-22 19:17:16 +01:00
|
|
|
"${paperlessDomain}" = {
|
2021-07-12 19:07:39 +02:00
|
|
|
forceSSL = true;
|
2021-07-13 00:57:33 +02:00
|
|
|
useACMEHost = domain;
|
2021-07-12 19:07:39 +02:00
|
|
|
|
2021-07-13 01:14:01 +02:00
|
|
|
listen = [
|
|
|
|
# FIXME: hardcoded tailscale IP
|
|
|
|
{
|
|
|
|
addr = "100.80.61.67";
|
|
|
|
port = 443;
|
|
|
|
ssl = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
addr = "100.80.61.67";
|
|
|
|
port = 80;
|
|
|
|
ssl = false;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-07-12 19:07:39 +02:00
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-07-13 22:20:21 +02:00
|
|
|
|
2021-08-09 20:19:27 +02:00
|
|
|
my.services.restic-backup = mkIf cfg.enable {
|
2021-07-14 03:00:36 +02:00
|
|
|
paths = [
|
2022-04-15 16:17:14 +02:00
|
|
|
config.services.paperless.dataDir
|
|
|
|
config.services.paperless.mediaDir
|
2021-07-14 03:00:36 +02:00
|
|
|
];
|
2021-07-13 22:20:21 +02:00
|
|
|
};
|
2021-07-12 19:07:39 +02:00
|
|
|
};
|
|
|
|
}
|