From cfdce40a926835e2812c9aab3e83f30c07a75f3c Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 19 Sep 2024 21:51:56 +0200 Subject: [PATCH] fuuko: Add paperless --- machines/fuuko/configuration.nix | 17 ++++++++++ machines/fuuko/services/paperless.nix | 45 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 machines/fuuko/services/paperless.nix diff --git a/machines/fuuko/configuration.nix b/machines/fuuko/configuration.nix index 2aee6b3..f798bc8 100644 --- a/machines/fuuko/configuration.nix +++ b/machines/fuuko/configuration.nix @@ -11,6 +11,7 @@ ./services/media-backup.nix ./services/media.nix + ./services/paperless.nix ./services/photoprism.nix ./services/torrent.nix ]; @@ -53,4 +54,20 @@ networking.hostName = "fuuko"; system.stateVersion = "20.09"; + + services.postgresql = { + enable = true; + package = pkgs.postgresql_16; + }; + + services.postgresqlBackup = { + enable = true; + startAt = [ ]; # triggered by restic system backup + location = "/var/lib/postgresql-backup"; + compression = "none"; + }; + systemd.services.restic-backups-system = { + after = [ "postgresqlBackup.service" ]; + wants = [ "postgresqlBackup.service" ]; + }; } diff --git a/machines/fuuko/services/paperless.nix b/machines/fuuko/services/paperless.nix new file mode 100644 index 0000000..2d2f106 --- /dev/null +++ b/machines/fuuko/services/paperless.nix @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2024 Simon Bruder +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ config, lib, ... }: + +{ + services.postgresql = { + enable = true; + ensureDatabases = [ "paperless" ]; + ensureUsers = lib.singleton { + name = "paperless"; + ensureDBOwnership = true; + }; + }; + + services.paperless = { + enable = true; + settings = { + PAPERLESS_DBHOST = "/run/postgresql"; + PAPERLESS_URL = "https://paperless.sbruder.de"; + PAPERLESS_OCR_LANGUAGE = "deu+eng"; + PAPERLESS_TASK_WORKERS = 4; + PAPERLESS_TIME_ZONE = "Europe/Berlin"; + PAPERLESS_FILENAME_FORMAT = "{correspondent}/{document_type}/{created}_{title}_{doc_pk}"; + }; + }; + + services.nginx = { + enable = true; + + virtualHosts."paperless.sbruder.de" = { + enableACME = true; + forceSSL = true; + + locations = { + "/" = { + proxyPass = with config.services.paperless; "http://${address}:${toString port}"; + proxyWebsockets = true; + }; + "/static".root = "${config.services.paperless.package}/lib/paperless-ngx"; + }; + }; + }; +}