I can't speak for NixOS specifically, but in GuixSD (a closely related project) this is handled at the service layer, an I imagine the same must be true for NixOS. The OS declaration specifies that, for example, the PostgreSQL daemon should be running with a specific configuration and the init system will run it when the system is instantiated. Your database runs as normal, and you would back up your state as normal. Functional configuration management provides an extremely clean separation of stateless from the stateful.