I set up a machine for this recently, which works by repeatedly pulverizing sandstone to get niter, which is crafted together with sulfur and charcoal dust (fed in manually, since they're generally quicker and easier to get) to make gunpowder. The sand supply comes from pulverizing cobblestone from igneous extruders, which produces gravel as a byproduct, which I process further into flint dust. Flint dust can be used to increase the efficiency of the iTNT recipe (5 per 3 TNT instead of 4 with plain flint). Works pretty well, but took quite a bit of effort to set up. I show it in detail in this video (starting around 4:45):
That's the Thermal Expansion way. There's another option with GregTech if you have a lot of excess ender pearls: Smelt/pulverize/macerate them into ender pearl dust, put that into an industrial electrolyzer for nitrogen and potassium cells, then use those in an electric crafting table (along with compressed air) to get saltpeter dust. The electric crafting table is necessary to get the cells back; otherwise, you'll be burning through tin to make cells each time you craft saltpeter.