How to emulate traditional stateful directory structure in general?

Sorry, while I believe many should have wondered this but I haven’t been able to find a similar Q/A.

Is it possible to build an environment that “simulates” the files, directories and permissions for any program running inside it, so that every other package manager like pip, cabal, opam … as well as stuff like cmake and ./configure can work the old way, while whatever they do only affects the environment?

Ideally such environments should be persistent and maintained in the user directory, so the user (developer) can experiment with whatever they want without feeling anything special except the need to activate the environment .

Even more ideally it would be possible to install other old stateful package mangers from other distros in said environments.

Not sure about your exact use case, but maybe run another distro as a Docker container?

You might be looking for buildFHSEnv, which emulates a FHS-style directory system for programs that expect that. You still have to manage the installed packages declaratively with Nix, though.

Yeah I think this is much closer, thanks.

Is there a way to build a persistent & mutable FHSUserEnv then? If I would need to modify the code of nix* executables, where should I look at?