The state itself rose as part of the need for the ruling class to have violent suppression against the classes it exploits. The nation state on the other hand is partially an accident of geography due to most people not travelling far(or having the means to), and liberalism today takes advantage of this as a tool of racial conflict dividing the working class but I think it's most likely that this was simply a useful tool for adopting a hostile stance to indigenous populations. They're "barbarians" therefore it is ok for us to kill them all and take their land. Very useful for colonialism.
Master race and untermenschen nazi ideas come from the ruling class justifying their right to rule as "betters", and likely evolved as various capitalist families sought to adapt the divine right of kings to bourgeoise rule. In particular it rose during an era of far greater class conflict than we have currently today so they had a lot of cause to try and provide reasons for their rule as socialist sentiment boomed.
One would expect that as capital becomes international the libs would become less nationalistic.
American nationalism serves as a useful tool as it's essentially the leader of the capitalist empire. If you view capitalism primarily as the imperial core(european+american global north or "international community") exploiting the periphery (global south) with the US as the leading force of this empire then the usefulness of this nationalism kind of explains itself.
If we break the american soft-left libs out of a national mindset and into a global one where they no longer view themselves as citizens of america but instead as citizens of the world we will find ourselves a lot more allies.
takes.