The essential need for life-support is electrical power, water and oxygen supply, processed from the soil around. While we easily can generate heat in several ways, the cooling of it is quite a different story. No problem on Earth to water and air, but Mars has no liquids on its surface, while the cooling capacity of its indeed very cold but also very thin atmospheric air is around 75 times lower per unit of air volume, than Earth's. This means that a cooling system on Mars must be 75 times larger than an equivalent one on Earth. For the very low powers that the robots presently on Mars dissipate, we still can cope with this, but not for the much larger powers needed to support a manned base (also the Apollo astronauts could not use solar for the same reason, using liquid Hydrogen and Oxygen with a fuel cell instead).
There is a saying: "If you can't fight it, join it" and that is what we are going to do here, turning the very low pressure of the martian atmosphere, and the vacuum on the Moon, into an advantage. We can expand vapors to a far lower pressure than possible on Earth, thus liquefying a part of them by the extra work done. It means, however, that we must obtain cooling by mass-rejection. This means that a part of the produced (cold) water, after being heated up by the technical systems and the people's bodies in the habitat, must be wasted to the environment, thus carrying the excess heat with it. If we can produce more water than needed for life-support, we can afford to do that.
It has been discovered that 1 cubic foot of martian soil contains two pints of water. That water exists as ice particles in the soil. By heating up that soil, the water inside can be extracted as steam. In Fig.1 we do this with heat from a nuclear source that produces hot steam, by which it is cooled at the same time. For those who have a good understanding of thermodynamics, the rest of the process follows from the text in the image - others simply have to believe it (I can't explain it all here).
The Moon's regolith contains Oxygen and Hydrogen in various chemical bonds, that have to be broken up by very high temperatures. When done, the oxygen and hydrogen molecules fuse to water steam, releasing far more energy (as heat) than needed to start the process - the regolith then becomes an energy source. The regolith is heated by absorbing microwaves, which already has been tested in labs to work fine (water ice doesn't absorb microwaves, so we can't use it for the martian soil). The magnetron, producing quite a lot of heat itself, is cooled with water that it evaporates, as shown in Fig.2. The rest of the system is the same as in Fig.1