Is there a formula/theory for writing country licks/riffs, and where can I find it?
It's the same formula/theory to write any music: listen to it. Listen to as much as you can and get it in your head. I have been trying to write and improvise solos on guitar for country and it is really difficult coming from a rock background. Country guitarist use reverse bends, major pentatonics and play with the chord changes targeting notes of those chords in the songs. So I had to really listen hard and practice starting with Johnny Cash guitar licks.
The other thing they really like to do is hybrid picking, to get all those major sixth double stops, etc. If you learn that technique, it'll be a whole lot easier to sound like a country virtuoso.