Nonequilibrium thermodynamics as a gauge theory