nixos-config/services/paperless.nix

140 lines
3.1 KiB
Nix
Raw Normal View History

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
cfg = config.my.services.paperless;
my = config.my;
domain = config.networking.domain;
hostname = config.networking.hostName;
fqdn = "${hostname}.${domain}";
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";
port = mkOption {
type = types.port;
default = 8080;
example = 8080;
description = "Internal port for Paperless service";
};
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
'';
};
};
config = mkIf cfg.enable {
2022-04-15 16:17:14 +02:00
services.paperless = {
enable = true;
port = cfg.port;
passwordFile = cfg.passwordFile;
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";
PAPERLESS_OCR_MODE = "skip_noarchive";
PAPERLESS_TIME_ZONE = config.time.timeZone;
PAPERLESS_ADMIN_USER = "alarsyo";
2023-08-31 11:42:04 +02:00
PAPERLESS_TASK_WORKERS = 3;
PAPERLESS_THREADS_PER_WORKER = 4;
};
};
systemd.services = {
2022-04-26 16:24:20 +02:00
paperless-scheduler.serviceConfig = {
EnvironmentFile = cfg.secretKeyFile;
};
2022-04-15 16:17:14 +02:00
paperless-consumer.serviceConfig = {
EnvironmentFile = cfg.secretKeyFile;
};
2022-04-15 16:17:14 +02:00
paperless-web.serviceConfig = {
EnvironmentFile = cfg.secretKeyFile;
};
};
services.postgresql = {
enable = true;
2022-04-10 11:54:58 +02:00
ensureDatabases = ["paperless"];
ensureUsers = [
{
name = "paperless";
ensurePermissions."DATABASE paperless" = "ALL PRIVILEGES";
}
];
};
2022-04-15 16:17:14 +02:00
systemd.services.paperless-server = {
# Make sure the DB is available
2022-04-10 11:54:58 +02:00
after = ["postgresql.service"];
};
services.nginx.virtualHosts = {
"${paperlessDomain}" = {
forceSSL = true;
useACMEHost = fqdn;
listen = [
# FIXME: hardcoded tailscale IP
{
2022-11-05 16:15:33 +01:00
addr = "100.115.172.44";
port = 443;
ssl = true;
}
{
2022-11-05 16:15:33 +01:00
addr = "100.115.172.44";
port = 80;
ssl = false;
}
];
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
proxyWebsockets = true;
};
};
};
2021-07-13 22:20:21 +02:00
security.acme.certs.${fqdn}.extraDomainNames = [paperlessDomain];
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
};
};
}