In many governments, it is quite illegal.
I wrote "many governments" because I am not fully versed in the policies and laws of every nation on the planet. Perhaps you can fill us in?
It's very difficult to get a job at NASA. I forget the exact number, but something like 75% of people who "work for NASA" are contractors and only a small minority are actual government employees. In order to get a full-time job, it helps to have previous experience usually in the form of a graduate fellowship. In order to get a fellowship, it helps to have undergrad summer experience. In order to get undergraduate experience, it's very helpful to have high school summer program experience. In order to get high school experience, you'll need to live in the area and probably have some connections which means parents or family who work at the NASA facility in question.
In my experience, national labs were similar but to a much lesser extreme, often just because they're remote and sometimes antiquated and children of lab employees often can't wait to get away.
When I worked at at the UN, (NGO, not formal government) coworkers were genuinely confused about how I got a job there with no family connections in higher places. I had the same conversation with several bewildered coworkers who plainly told me about their parent or uncle who got them their job. I was told that nepotism is much, much more common and openly acknowledged in Europe than in the US.
The reason for AA was because you couldn't get anything that specifically calculated and addressed the harms of slavery and Jim Crow past the advocates of "meritocracy." Was the literal pricing of slaves not the ultimate capitalist proof of merit?
It may be reflective of corruption and produce inequitable and undesirable outcomes, but nepotism is something else.
[0]: https://www.jstor.org/stable/23055549
[1]: https://www.nytimes.com/2022/07/13/us/legacy-admissions-coll...
There tend to be more laws pro-family than anti- for some reason . . .