I'm trying to follow Goldman's paper 'The symplectic nature of fundamental groups of surfaces'. I'm having trouble understanding the following isomorphism: let's take a principal $G$-bundle $P \to M$ over a closed oriented surface, equipped with a flat connection $A \in \Omega^1(P, \mathfrak{g})$, and let's suppose that the holonomy is given by (the pointwise inverse of) $\phi : \pi_1(M) \to G$ (I'll omit choices of basepoint). Goldman claims in section 1.8 that $H^*(\pi_1(M); \mathfrak{g}_{\text{Ad}_{\phi}}) \simeq H^*(M; \text{ad }P)$, where the left hand side is the group cohomology of $\pi_1(M)$ with values in $\mathfrak{g}$ as a $\pi_1(M)$-module with the $\text{Ad}_{\phi}$ representation, and the right hand side is the de Rham cohomology of $M$ with values in the adjoint bundle $\text{ad }P$ (using as differential the one that comes from the flat connection in $\text{ad }P$ associated to $A$).
Since $M$ is a surface, it's a $K(\pi_1(M), 1)$, so the group cohomology gets identified with the singular cohomology of $M$, which in turn gets in some sense identified with its de Rham cohomology. I'm not sure what are the proper statements in this case, though, since we have coefficients. What exactly are the versions of these theorems for coefficients, and what's the relation between $\text{ad }P$ equipped with the flat connection that comes from $A$ and $\mathfrak{g}$ as a $\pi_1(M)$-module?