First-order formalism for dark energy and dust