Backup and Restore Nix Store

I’m trying to backup the complete Nix store into a single file to then restore it on a different host. I’m trying to do this in the least hacky way possible. I think what I wish existed is nix-store --export --all. But there seems to be no (standard) way to emulate this by listing all store paths. Also nix-store doesn’t support --stdin and passing tens of thousands of arguments seems problematic as well.

Another approach I considered is nix-copy --to file://... --stdin, but it still boils down to the problem of listing all store paths.

As far as I can tell the format of nix-store --dump-db is not documented either.

So tl;dr:

  1. Is there a way to list all the store paths in a given Nix store?
  2. Alternatively: Is there something like nix-store --export --all?

Ah, nix path-info --all lists all paths! So this works:

$ nix path-info --all | nix copy --to file://somewhere --stdin

Would be still nice to have a way to use nix-store --export without having to specify all paths as arguments, because the resulting file is much easier to handle.