nixos/paperless: add configureNginx option (#385637)

Sandro b62d48b2 88abe9ea

Changed files
+61 -24
nixos
modules
services
tests
+34
nixos/modules/services/misc/paperless.nix
···
};
};
exporter = {
enable = lib.mkEnableOption "regular automatic document exports";
···
services.paperless.manage = manage;
environment.systemPackages = [ manage ];
services.redis.servers.paperless.enable = lib.mkIf enableRedis true;
services.postgresql = lib.mkIf cfg.database.createLocally {
···
};
services.paperless.settings = lib.mkMerge [
(lib.mkIf cfg.database.createLocally {
PAPERLESS_DBENGINE = "postgresql";
PAPERLESS_DBHOST = "/run/postgresql";
···
};
};
+
configureNginx = lib.mkEnableOption "" // {
+
description = "Whether to configure nginx as a reverse proxy.";
+
};
+
+
domain = lib.mkOption {
+
type = lib.types.str;
+
example = "paperless.example.com";
+
description = "Domain under which paperless will be available.";
+
};
+
exporter = {
enable = lib.mkEnableOption "regular automatic document exports";
···
services.paperless.manage = manage;
environment.systemPackages = [ manage ];
+
services.nginx = lib.mkIf cfg.configureNginx {
+
enable = true;
+
upstreams.paperless.servers."${cfg.address}:${toString cfg.port}" = { };
+
virtualHosts.${cfg.domain} = {
+
forceSSL = lib.mkDefault true;
+
locations = {
+
"/".proxyPass = "http://paperless";
+
"/static/" = {
+
root = config.services.paperless.package;
+
extraConfig = ''
+
rewrite ^/(.*)$ /lib/paperless-ngx/$1 break;
+
'';
+
};
+
"/ws/status" = {
+
proxyPass = "http://paperless";
+
proxyWebsockets = true;
+
};
+
};
+
};
+
};
+
services.redis.servers.paperless.enable = lib.mkIf enableRedis true;
services.postgresql = lib.mkIf cfg.database.createLocally {
···
};
services.paperless.settings = lib.mkMerge [
+
(lib.mkIf (cfg.domain != "") {
+
PAPERLESS_URL = "https://${cfg.domain}";
+
})
(lib.mkIf cfg.database.createLocally {
PAPERLESS_DBENGINE = "postgresql";
PAPERLESS_DBHOST = "/run/postgresql";
+27 -24
nixos/tests/paperless.nix
···
imagemagick
jq
];
-
services.paperless = {
-
enable = true;
-
passwordFile = builtins.toFile "password" "admin";
-
-
exporter = {
enable = true;
-
settings = {
-
"no-color" = lib.mkForce false; # override a default option
-
"no-thumbnail" = true; # add a new option
};
};
};
};
-
postgres =
-
{ config, pkgs, ... }:
-
{
-
imports = [ self.simple ];
-
services.paperless.database.createLocally = true;
-
services.paperless.settings = {
-
PAPERLESS_OCR_LANGUAGE = "deu";
-
};
};
};
in
self;
···
with subtest("Web interface gets ready"):
node.wait_for_unit("paperless-web.service")
# Wait until server accepts connections
-
node.wait_until_succeeds("curl -fs localhost:28981")
# Required for consuming documents via the web interface
with subtest("Task-queue gets ready"):
···
"convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black "
"-annotate +5+20 'hello web 16-10-2005' /tmp/webdoc.png"
)
-
node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.png -fs localhost:28981/api/documents/post_document/")
with subtest("Add a txt document via the web interface"):
node.succeed(
"echo 'hello web 16-10-2005' > /tmp/webdoc.txt"
)
-
node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.txt -fs localhost:28981/api/documents/post_document/")
with subtest("Documents are consumed"):
node.wait_until_succeeds(
-
"(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 3))"
)
-
docs = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/"))['results']
assert "2005-10-16" in docs[0]['created']
assert "2005-10-16" in docs[1]['created']
assert "2005-10-16" in docs[2]['created']
# Detects gunicorn issues, see PR #190888
with subtest("Document metadata can be accessed"):
-
metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/1/metadata/"))
assert "original_checksum" in metadata
-
metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/2/metadata/"))
assert "original_checksum" in metadata
-
metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost:28981/api/documents/3/metadata/"))
assert "original_checksum" in metadata
with subtest("Exporter"):
···
imagemagick
jq
];
+
services = {
+
nginx.virtualHosts."localhost".forceSSL = false;
+
paperless = {
enable = true;
+
configureNginx = true;
+
domain = "localhost";
+
passwordFile = builtins.toFile "password" "admin";
+
exporter = {
+
enable = true;
+
+
settings = {
+
"no-color" = lib.mkForce false; # override a default option
+
"no-thumbnail" = true; # add a new option
+
};
};
};
};
};
+
postgres = {
+
imports = [ self.simple ];
+
services.paperless.database.createLocally = true;
+
services.paperless.settings = {
+
PAPERLESS_OCR_LANGUAGE = "deu";
};
+
};
};
in
self;
···
with subtest("Web interface gets ready"):
node.wait_for_unit("paperless-web.service")
# Wait until server accepts connections
+
node.wait_until_succeeds("curl -fs localhost")
# Required for consuming documents via the web interface
with subtest("Task-queue gets ready"):
···
"convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black "
"-annotate +5+20 'hello web 16-10-2005' /tmp/webdoc.png"
)
+
node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.png -fs localhost/api/documents/post_document/")
with subtest("Add a txt document via the web interface"):
node.succeed(
"echo 'hello web 16-10-2005' > /tmp/webdoc.txt"
)
+
node.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.txt -fs localhost/api/documents/post_document/")
with subtest("Documents are consumed"):
node.wait_until_succeeds(
+
"(($(curl -u admin:admin -fs localhost/api/documents/ | jq .count) == 3))"
)
+
docs = json.loads(node.succeed("curl -u admin:admin -fs localhost/api/documents/"))['results']
assert "2005-10-16" in docs[0]['created']
assert "2005-10-16" in docs[1]['created']
assert "2005-10-16" in docs[2]['created']
# Detects gunicorn issues, see PR #190888
with subtest("Document metadata can be accessed"):
+
metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost/api/documents/1/metadata/"))
assert "original_checksum" in metadata
+
metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost/api/documents/2/metadata/"))
assert "original_checksum" in metadata
+
metadata = json.loads(node.succeed("curl -u admin:admin -fs localhost/api/documents/3/metadata/"))
assert "original_checksum" in metadata
with subtest("Exporter"):