Derivation (variance of geometric distribution)

The generating function of the geometric distribution is $$ G_X(t) = \frac{p}{1-(1-p)t}. $$ Computing the derivatives, $$\begin{align*} G_X'(t) &= \frac{p(1-p)}{(1-(1-p)t)^2} \\ G_X''(t) &= \frac{2p(1-p)^2}{(1-(1-p)t)^3}. \end{align*}$$ Then $$ \expect(X^2-X) = G_X''(1) = \frac{2(1-p)^2}{p^2}.$$ Hence $$ \begin{align*} \op{var}(X) &= \expect(X^2-X) + \expect(X) - \expect(X^2) \\ &= \frac{2(1-p)^2}{p^2} + \frac{1-p}{p} - \frac{(1-p)^2}{p^2} \\ &= \frac{1-p}{p^2}. \end{align*} $$