Nix & Guix solve this reasonably well, without most Flatpak pitfalls, and are available for nearly all distributions. Plus, Nix also targets macOS.