I presume running a national rail system is somewhat different from a railway for a single city. How good are the national rail systems in these countries?
They still don't make money off of being rail systems, they make money off of real-estate developments.
So, sure, you can have a rail system self-fund as long as you let it build whatever the fuck it wants at stations and funnel all the profits back into the train line.