{ 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 ''; }; }; }