I’m glad to see someone else thought to mention the Create mod when faced with this question, however, one must also mention the addon mod Create: Interactive, it would in theory allow you to create a self-perpetuating giant train base that drills its path forward, creates more rail in a built in production line with the drilled stone and deploys it automatically. Let’s not forget the one addon specifically made to expand the train system as well.
I recently discovered the Create mod for Minecraft and it is still blowing my mind, it might be the best mod ever made for the game. I still remember watching the trailer for the mod and my first reaction being “THIS MOD ADDS THE MEANS OF PRODUCTION TO MINECRAFT!”
I already had the idea to make a post scarcity fully automated luxury communist villager society in Minecraft and this mod is exactly the missing piece to my plan.