Add paperless-ngx

This commit is contained in:
aloslider committed 2026-10-27 22:40:18 +03:00
1 parent 0bfdb35014
commit a459f9cc57
8 files changed
+348

No files matched your search

@@ -0,0 +1,64 @@
{ config, lib, ... }:
with lib;
let
common = config.selfhosted.common;
rootCfg = config.selfhosted.docs-manager;
cfg = rootCfg.paperless-ngx;
domain = "${config.sops.placeholder."domains/serv"}";
pocketIdSubdomain = config.selfhosted.pocket-id.subdomain;
socialAccountProviders = builtins.toJSON {
openid_connect = {
OAUTH_PKCE_ENABLED = true;
SCOPE = [
"openid"
"profile"
"email"
];
APPS = [
{
provider_id = "paperless-ngx";
name = "PocketID";
client_id = "paperless-ngx";
secret = config.sops.placeholder."paperless-ngx/client_secret";
settings = {
server_url = "https://${pocketIdSubdomain}.${domain}";
token_auth_method = "client_secret_basic";
fetch_userinfo = true;
};
}
];
};
};
in
{
config = mkIf rootCfg.enable {
sops.secrets = {
"paperless-ngx/client_secret" = { };
"paperless-ngx/secret_key" = { };
};
sops.templates."paperless-ngx.env".content = ''
USERMAP_UID=${common.user.uid}
USERMAP_GID=${common.group.gid}
PAPERLESS_URL=https://${cfg.subdomain}.${domain}
PAPERLESS_SECRET_KEY=${config.sops.placeholder."paperless-ngx/secret_key"}
PAPERLESS_TIME_ZONE=${config.time.timeZone}
PAPERLESS_REDIS=redis://${rootCfg.redis.name}:6379
PAPERLESS_DBENGINE=postgresql
PAPERLESS_DBHOST=${rootCfg.postgres.name}
PAPERLESS_DBPORT=5432
PAPERLESS_DBNAME=paperless
PAPERLESS_DBUSER=paperless
PAPERLESS_DBPASS=${config.sops.placeholder."paperless-ngx/db_password"}
PAPERLESS_APPS=allauth.socialaccount.providers.openid_connect
PAPERLESS_SOCIAL_AUTO_SIGNUP=true
PAPERLESS_SOCIAL_ACCOUNT_DEFAULT_GROUPS=users
PAPERLESS_ACCOUNT_EMAIL_VERIFICATION=none
PAPERLESS_SOCIALACCOUNT_PROVIDERS=${socialAccountProviders}
PAPERLESS_TIKA_ENABLED=1
PAPERLESS_TIKA_GOTENBERG_ENDPOINT=http://${rootCfg.tika.gotenbergName}:3000
PAPERLESS_TIKA_ENDPOINT=http://${rootCfg.tika.name}:9998
'';
};
}
@@ -0,0 +1,69 @@
{ config, lib, ... }:
with lib;
let
common = config.selfhosted.common;
rootCfg = config.selfhosted.docs-manager;
cfg = rootCfg.paperless-ngx;
hostDataPath = "${common.dataDir}/${cfg.name}";
in
{
imports = [ ./config.nix ];
options.selfhosted.docs-manager.paperless-ngx = {
name = mkOption {
type = types.str;
};
subdomain = mkOption {
type = types.str;
};
hostHttpPort = mkOption {
type = types.port;
};
};
config = mkIf rootCfg.enable {
virtualisation.oci-containers.containers."${cfg.name}" = {
image = "ghcr.io/paperless-ngx/paperless-ngx:2.15.3";
ports = [
"0.0.0.0:${toString cfg.hostHttpPort}:8000"
];
environmentFiles = [
config.sops.templates."paperless-ngx.env".path
];
volumes = [
"${hostDataPath}/data:/usr/src/paperless/data"
"${hostDataPath}/media:/usr/src/paperless/media"
"${hostDataPath}/export:/usr/src/paperless/export"
"${hostDataPath}/consume:/usr/src/paperless/consume"
];
log-driver = "journald";
extraOptions = [
"--network=${common.network.name}"
"--health-cmd=curl -fsS http://127.0.0.1:8000/"
"--health-interval=30s"
"--health-timeout=10s"
"--health-retries=5"
"--health-start-period=90s"
];
};
systemd.services."${common.backend}-${cfg.name}" = {
serviceConfig = {
Restart = lib.mkOverride 90 "always";
};
wantedBy = [ "${common.backend}-${rootCfg.targetName}.target" ];
partOf = [ "${common.backend}-${rootCfg.targetName}.target" ];
after = [
"${common.backend}-${rootCfg.redis.name}.service"
"${common.backend}-${rootCfg.postgres.name}.service"
"${common.backend}-${rootCfg.tika.gotenbergName}.service"
"${common.backend}-${rootCfg.tika.name}.service"
];
preStart = ''
mkdir -p ${hostDataPath}/data ${hostDataPath}/media ${hostDataPath}/export ${hostDataPath}/consume
chown -R ${common.user.uid}:${common.group.gid} ${hostDataPath}/data ${hostDataPath}/media ${hostDataPath}/export ${hostDataPath}/consume
chmod -R 0775 ${hostDataPath}/data ${hostDataPath}/media ${hostDataPath}/export ${hostDataPath}/consume
'';
};
};
}