nix-config/modules/nixos/services/paperless/default.nix

117 lines
2.7 KiB
Nix
Raw Normal View History

{ config, lib, ... }:
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";
};
secretKeyFile = mkOption {
2021-08-19 13:05:08 +02:00
type = types.str;
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";
};
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 {
services.paperless = {
2021-08-19 13:05:08 +02:00
enable = true;
port = cfg.port;
mediaDir = lib.mkIf (cfg.documentPath != null) cfg.documentPath;
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";
# Security settings
PAPERLESS_ALLOWED_HOSTS = paperlessDomain;
PAPERLESS_CORS_ALLOWED_HOSTS = "https://${paperlessDomain}";
# OCR settings
PAPERLESS_OCR_LANGUAGE = "fra+eng";
# 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;
};
# Admin password
passwordFile = cfg.passwordFile;
# Secret key
environmentFile = cfg.secretKeyFile;
# Automatic PostgreSQL provisioning
database = {
createLocally = true;
};
2021-08-19 13:05:08 +02:00
};
# Set-up media group
users.groups.media = { };
users.users.${config.services.paperless.user} = {
2021-08-19 13:05:08 +02:00
extraGroups = [ "media" ];
};
my.services.nginx.virtualHosts = {
paperless = {
2021-08-19 13:05:08 +02:00
inherit (cfg) port;
sso = {
enable = true;
};
websocketsLocations = [ "/" ];
};
};
2021-08-19 13:05:08 +02:00
my.services.backup = {
paths = [
config.services.paperless.dataDir
config.services.paperless.mediaDir
2021-08-19 13:05:08 +02:00
];
};
};
}