No good reason for purpose-designed firearms
Risk assessments are critical to space travel, even more than on Earth. Some of the obvious things that can go wrong because you are carrying a firearm are:
- propellant becomes unstable
- poor maintenance results in mechanism seizing up
- accidental/negligent discharge results in personnel injury or death
- accidental/negligent discharge results in destruction of critical spacecraft components (including atmospheric integrity)
- accidental/negligent discharge imparts momentum (linear or rotational) to spacecraft requiring fuel expenditure for course correction
In addition to these possible risks there is also the certainty that every single flight will be wasting mass on a dangerous object of negligible use - mass that could be used to carry more fuel or operational/profit-generating payload.
To offset these massive disadvantages, there has to be a concrete benefit to putting a firearms on a spacecraft. This is hard to see - in the anti-hijacking role weapons such as tasers are much preferred to things that punch holes in your own ship. Boarding actions are dubious in any hard science setting - docking with a cooperative target is hard enough, docking with an uncooperative target is practically impossible even if its propulsion systems are disabled. As for employing firearms (other than those mounted in sophisticated turrets) against other spacecraft - forget it. Then there is the problem of keeping all of the astronauts current in their firearms training - if they are rusty then they may as well not have a firearm.
Not all is lost, however. As was well-portrayed in The Martian, astronauts are a technically competent group of trained improvisers. If the plot of your story requires that a firearm is used then a character can improvise one. Hand-held and/or drone thruster units are a plausible item to have on board a spacecraft - if you disconnect a few safety devices and plug the exhaust with a ball bearing (possibly with some tape wrapped around it to get a good seal) then you have a projectile weapon. A high-pressure air tank is a ready-made reservoir for a very dangerous air rifle, just add a metal tube for a barrel and a valve. (With more time a semi- and/or full-auto version could be manufactured.)
If the requirement is just for a ranged weapon, not necessarily a firearm, then slings are just as easy to make as on Earth. A spacecraft machine shop could be used to make a bow or crossbow.
In summary - just as in many situations on Earth, carrying a firearm is far more dangerous than not carrying a firearm. However, spacecraft have plenty of options for making ranged weapons in an emergency.