I read a story written in 50s to 60s about astronauts stuck on the moon. And they figure out how to get everything they need to survive from minerals on the moon: water, air, nutrients.
Similar to The Martian.
The Moon is Hell!, a 1951 novel by John W. Campbell, Jr.. Does any of these covers look familiar? The story has its own Wikipedia page. Here is a review from the The Magazine of Fantasy and Science Fiction, August 1951 (available at the Internet Archive):
John W. Campbell Jr.'s THE MOON IS HELL! (Fantasy Press) is an extraordinary short novel: the diary of a stranded lunar expedition which creates its own living conditions out of that barren satellite—a narrative with much of the fascination of a SWISS FAMILY ROBINSON or a ROBINSON CRUSOE, and with Defoe's own dry convincing factuality.
Except for a prologue and an epilogue, the story is told in the form of a diary.
The second expedition to the moon lands in the middle of the far side, out of communication with Earth:
Dr. James Harwood Garner was the leader of this party of carefully chosen men, and in the name of the United States of America, he claimed the so-called dark half of the moon. Half a world! Millions, tens of millions of square miles of utterly barren surface, surface never seen by Terrestrian eyes, save when, five years before, Capt. Roger Wilson had circumnavigated the moon twice, landing for two brief days on the Earthward side, and claimed that.
Disaster strikes:
Outside, the relief ship lies, a crushed, red-hot mass of broken, glowing metal. It arrived this afternoon, twenty-one hours late.
The meaning of this to us, is terrible. It will be at least one full month before Earth even knows that the relief expedition has failed. It will take at least another for action to be started. And not less than five months will be necessary to build a new relief ship. This means that not less than seven months must pass before we can hope for relief—and we have oxygen for two months more! Food we can cut down on, but oxygen we cannot reduce.
Campbell's heroes figure out how to live off the land:
Again today the food supply was generously helped out by a portion of the sticky, tarry liquid Moore is producing. We are all helping Moore set up the complicated apparatus he needs—and also mining our food supplies! Food and air from the rocks! Man has conquered this frozen hell, and is living off the most inhospitable territory ever touched. I believe that with men like these we could have wrested a living from cold, frozen Pluto itself!
Finally they are rescued:
The Garner expedition is ended. The frozen hell of the Moon was left behind. But an enormous thing had been accomplished. Thirteen men, by the might of their brains, and the work of their hands, had wrested from Luna a living, and more, comfort. Had they but known of RB-X solution, they need never had feared. They had established an outpost! The Castle! What memories of the great and the famous that stirs in our minds today? Duncan—Rice—Johansen—Murgatroyd—
Possibly the 1951 Arthur C. Clarke short story If I Forget Thee, Oh Earth?
This involves the last humans living in a self-sustaining moon colony after a nuclear war leaves Earth uninhabitable.
If you are seeking something longer, perhaps the 1969 novel by D S Halacy "Return From Luna"
An eighteen-year-old boy looks forward to spending time on the moon as research assistant to his physics professor. But soon after they arrive nuclear war is reported on earth cutting off supplies of oxygen, water, and food and the base must struggle for survival.