If you are a sufficiently ingenious chemist, it is possible to dream up alternative schemes of energy flow on this planet, which do not start with the sun. And if a useful piece of chemistry can be dreamed up, the chances are that a bacterium got there first: maybe even before they discovered the solar energy trick, and that was more than 3 billion years ago. There has to be some kind of external source of energy, but it doesn’t have to be the sun. There is chemical energy locked up in lots of substances, energy that can be released by the right chemical reactions.