Endolithic (rock-dwelling) microbial communities are ubiquitous in hyper-arid deserts around the world and the last resort for life under extreme aridity. These communities are excellent models to explore biotic and abiotic drivers of diversity because they are of low complexity. Using high-throughput amplicon and metagenome sequencing, combined with X-ray computed tomography, we investigated how water availability and substrate architecture modulated the taxonomic and functional composition of gypsum endolithic communities in the Atacama Desert, Chile. We found that communities inhabiting gypsum rocks with a more fragmented substrate architecture had higher taxonomic and functional diversity, despite having less water available. This effect was tightly linked with community connectedness and likely the result of niche differentiation. Gypsum communities were functionally similar, yet adapted to their unique micro-habitats by modulating their carbon and energy acquisition strategies and their growth modalities. Reconstructed population genomes showed that these endolithic microbial populations encoded potential pathways for anoxygenic phototrophy and atmospheric hydrogen oxidation as supplemental energy sources.