Some precedents for gun regulation

Alcohol can only be bought from state-licensed vendors. Some states give these licenses easily, others reserve a monopoly. This is allowed under the U.S. Constitution.

Airplanes can only be flown by pilots who pass 40 hours of instruction a written and solo flight check and a medical exam that grounds them for life if they have taken any psychiatric medication for more than just a little while.

The Military is subject to a separate legal code, the Uniform Code of Military Justice.

So, if you’re going to rely on the excuse of a “well regulated militia” to own a gun, you should have to buy it from a government monopoly after an exam on par with a pilot’s license (or at least a drivers license, which is still harder than the existing rules for guns) and your behavior when using it as part of the militia should be subject to the UCMJ.