I maintain a FOSS library as a hobby project. Does this count as using its name in commerce, or do I have to sell a copy to someone?
An exchange of money is not necessarily required for a trademark to satisfy the "use in commerce" requirement, and both for profit and nonprofit entities can obtain trademarks.
Simply maintaining a library, however, is generally not enough. You must show marketing materials that are used to bring awareness of the mark to a wider public. "Use in interstate commerce" is basically synonymous with either branding something that is distributed in more than one state, or marketing something in more than one state. Websites and anything done to promote a website with a logo, for example, might qualify.
Similarly, if every use of the FOSS library were accompanied by an email with a logo or catchy phrase on it, that might constitute "use in commerce."
This said, if one were suing for infringement of the mark, it might be hard to prove significant money damages, making it harder to justify the registration economically than a typical for profit mark registration.