You need to encode the metadata in a standard way, encode new data that shows up in a standard way, and various people can add more metadata to files: think like Posix ACLs or the immutable flag or whatever.
Nix actually invented a fork of tar specifically for this called “normalized archive” or “Nix Archive” or nar. Guix uses this too:
https://releases.nixos.org/nix/nix-2.22.0/manual/protocols/nix-archive.html


A real flatpak cake would come wrapped in the oven used to bake it.