Home data per-app separation

I like how each package from nixpkgs is in its own directory in /nix/store. However, when it comes to the home folder, different programs just put files all over the place.

Home manager solves this problem only partially, but many programs still have state they need to manage themselves.

I’d like to have each program store its files in its own subdirectory of home. For example, One idea I had was to try to run some programs with env HOME=/home/user/store/app-name XDG_CONFIG_HOME=/home/user/store/app-name/config XDG_DATA_HOME=/home/user/store/app-name/data app-name. But I’m sure there will be a bunch of caveats with that.

Has someone tried to so something similar? What would the best approach be? I don’t need something that works for every app, though I’d prefer an opt-out approach for programs that shouldn’t be separated, rather than opt-in for those that should.