The overwhelming majority of SpaceX's revenue has been government contracting. That is starting to diversify in the last 2-3 years with more truly private launches and with Starlink, but that's relatively new, and even so government is a very, very large share of revenue.
Many were. I'm not saying this is terrible-- these programs cost too much for private entities to bear all the risk, and most of the programs that SpaceX has gotten funding from have been well-run programs.
COTS paid for vehicle development for Falcon-9 and Dragon; CRS paid for flights. COTS was a pretty well-managed program with a lot of clear milestones for funding release.
The troubled Artemis program has paid for a whole lot of Starship development and demonstration. It's questionable how well Starship actually meets Artemis needs, so this is more troubling.
And, of course, the government has bought early flights with no guarantee of success, including just to fly masses/demosats. DARPA/NASA/ORS paid for the first 3 Falcon I failures.
It goes up and up with every aerospace company doing government contracting.