If you lose the magnetometer, the HSI should revert to using the GPS track. It is not a heading but pretty close except in high crosswinds…
Loss of all electrical power is extremely rare. Losing an alternator is certainly a risk, but just puts you on the battery for as long as it lasts…