Import existing dataset into paperless-ngx module

I currently run the paperless-ngx docker container but am interested in migrating to the nix module. Does anyone have any pointers on how import my existing data? It seems that the paperless team provide scripts for import but I have not had success running them. I have minimal experience with databases and have poked around in the service but have had nothing but problems with paths and permissions.

The application of the module will run as a unprivileged user instead of root in the docker version. Try changing the owner of the data folder to that user with chown.

I’ve restored backups produced by the document_exporter between NixOS installations before and it worked flawlessly (apart from needing to re-generate archives and thumbnails that I explicitly excluded from the backup).

Is that what you mean by “scripts for import”?

The relevant config is as follows:

{
  self,
  config,
  lib,
  pkgs,
  ...
}: {
  age.secrets.namecheap_credentials.file = ./secrets/namecheap_credentials.age;

  networking.firewall.allowedTCPPorts = [80 443];

  services.postgresql = {
    enable = true;
    ensureDatabases = ["paperless"];
    ensureUsers = [
      {
        name = "paperless";
        ensureDBOwnership = true;
      }
    ];
  };

  services.paperless = {
    enable = true;
    settings = {
      PAPERLESS_URL = "https://MY_DOMAIN";
      PAPERLESS_DBHOST = "/run/postgresql";
      };
    };
  };

  security.acme = {
    acceptTerms = true;
    defaults = {
      email = "MY_EMAIL";
      dnsProvider = "namecheap";
      credentialsFile = config.age.secrets.namecheap_credentials.path;
    };
  };

  services.nginx = {
    enable = true;

    # Use recommended settings
    recommendedGzipSettings = true;

    virtualHosts = {
      "MY_DOMAIN" = {
        forceSSL = true;
        enableACME = true;
        acmeRoot = null;
        locations."/" = {
          proxyPass = "http://127.0.0.1:${toString config.services.paperless.port}";
        };
      };
    };
  };
}

When I attempt to run ${dataDir}/paperless-manage document_importer /paperless-backup I receive a python stack trace, I believe, and the telling lines: psycopg.OperationalError: connection failed: FATAL: Peer authentication failed for user "paperless" and django.db.utils.OperationalError: connection failed: FATAL: Peer authentication failed for user "paperless".

1 Like

After doing a bit more googling I realized I missed the very important

services.postgresql.authentication = lib.mkOverride 10 ''
# TYPE    DATABASE     USER    ADDRESS   METHOD
   local         all    all              trust
'';

from the wiki. Thanks!

Not really. That way you are allowing anyone to access that database. Try running that script with sudo -u paperless thatcommand.

1 Like

I tried sudo -c 'command' paperless and it didn’t work I believe because the paperless user’s shell is set to nologin. Is there a way to reset the database and try your command?

sudo -u paperless bash should work so I dont think that it matters much.

2 Likes