Add paperless-ngx
This commit is contained in:
1 parent
0bfdb35014
commit
a459f9cc57
8 files changed
+348
No files matched your search
@@ -0,0 +1,32 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
common = config.selfhosted.common;
|
||||
cfg = config.selfhosted.docs-manager;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./paperless-ngx
|
||||
./postgres
|
||||
./redis
|
||||
./tika
|
||||
];
|
||||
|
||||
options.selfhosted.docs-manager = {
|
||||
enable = mkEnableOption "Enable ${cfg.targetName} root target";
|
||||
targetName = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.targets."${common.backend}-${cfg.targetName}" = {
|
||||
unitConfig = {
|
||||
Description = "Root target for ${cfg.targetName}";
|
||||
};
|
||||
wantedBy = [ "${common.backend}-${common.rootTarget.name}.target" ];
|
||||
partOf = [ "${common.backend}-${common.rootTarget.name}.target" ];
|
||||
after = [ "${common.backend}-${common.rootTarget.name}.target" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
rootCfg = config.selfhosted.docs-manager;
|
||||
in
|
||||
{
|
||||
config = mkIf rootCfg.enable {
|
||||
sops.secrets = {
|
||||
"paperless-ngx/db_password" = { };
|
||||
};
|
||||
|
||||
sops.templates."paperless-ngx-db.env".content = ''
|
||||
POSTGRES_DB=paperless
|
||||
POSTGRES_USER=paperless
|
||||
POSTGRES_PASSWORD=${config.sops.placeholder."paperless-ngx/db_password"}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
common = config.selfhosted.common;
|
||||
rootCfg = config.selfhosted.docs-manager;
|
||||
cfg = rootCfg.postgres;
|
||||
hostDataPath = "${common.dataDir}/${rootCfg.paperless-ngx.name}";
|
||||
in
|
||||
{
|
||||
imports = [ ./config.nix ];
|
||||
|
||||
options.selfhosted.docs-manager.postgres = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf rootCfg.enable {
|
||||
virtualisation.oci-containers.containers."${cfg.name}" = {
|
||||
image = "docker.io/library/postgres:17.7";
|
||||
environmentFiles = [ config.sops.templates."paperless-ngx-db.env".path ];
|
||||
volumes = [
|
||||
"${hostDataPath}/db:/var/lib/postgresql/data"
|
||||
];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=${common.network.name}"
|
||||
"--health-cmd=pg_isready -U paperless"
|
||||
"--health-interval=30s"
|
||||
"--health-timeout=10s"
|
||||
"--health-retries=3"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services."${common.backend}-${cfg.name}" = {
|
||||
serviceConfig = {
|
||||
Restart = lib.mkOverride 90 "always";
|
||||
};
|
||||
wantedBy = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
partOf = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
preStart = ''
|
||||
mkdir -p ${hostDataPath}/db
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
common = config.selfhosted.common;
|
||||
rootCfg = config.selfhosted.docs-manager;
|
||||
cfg = rootCfg.redis;
|
||||
hostDataPath = "${common.dataDir}/${rootCfg.paperless-ngx.name}";
|
||||
in
|
||||
{
|
||||
options.selfhosted.docs-manager.redis = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf rootCfg.enable {
|
||||
virtualisation.oci-containers.containers."${cfg.name}" = {
|
||||
image = "docker.io/library/redis:7.4.11";
|
||||
volumes = [
|
||||
"${hostDataPath}/redis:/data"
|
||||
];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=${common.network.name}"
|
||||
"--health-cmd=redis-cli ping"
|
||||
"--health-interval=30s"
|
||||
"--health-timeout=10s"
|
||||
"--health-retries=3"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services."${common.backend}-${cfg.name}" = {
|
||||
serviceConfig = {
|
||||
Restart = lib.mkOverride 90 "always";
|
||||
};
|
||||
wantedBy = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
partOf = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
preStart = ''
|
||||
mkdir -p ${hostDataPath}/redis
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
common = config.selfhosted.common;
|
||||
rootCfg = config.selfhosted.docs-manager;
|
||||
cfg = rootCfg.tika;
|
||||
in
|
||||
{
|
||||
options.selfhosted.docs-manager.tika = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
gotenbergName = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf rootCfg.enable {
|
||||
virtualisation.oci-containers.containers."${cfg.gotenbergName}" = {
|
||||
image = "docker.io/gotenberg/gotenberg:8.19.0";
|
||||
cmd = [
|
||||
"gotenberg"
|
||||
"--chromium-disable-javascript=true"
|
||||
"--chromium-allow-list=file:///tmp/.*"
|
||||
];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=${common.network.name}"
|
||||
];
|
||||
};
|
||||
|
||||
virtualisation.oci-containers.containers."${cfg.name}" = {
|
||||
image = "docker.io/apache/tika:3.3.1.0";
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=${common.network.name}"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services."${common.backend}-${cfg.gotenbergName}" = {
|
||||
serviceConfig = {
|
||||
Restart = lib.mkOverride 90 "always";
|
||||
};
|
||||
wantedBy = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
partOf = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
};
|
||||
|
||||
systemd.services."${common.backend}-${cfg.name}" = {
|
||||
serviceConfig = {
|
||||
Restart = lib.mkOverride 90 "always";
|
||||
};
|
||||
wantedBy = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
partOf = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user