To begin with we take $x_0 = 0$ : we want $f(0) = 0$ and $f'$ defined at $0$, with $f'(0)=1$.
Then you take :
$f$ is continuous only at $0$. Moreover, you can check that $f'(0) = 1$ : indeed we have $f(0) = 0$, so $\mid \frac{f(x) - f(0)}{x} - 1\mid = \mid \frac{f(x)}{x} - 1\mid$. This quantity equals either to $0$ if $x \in \mathbb{Q}$ or to $\mid x \mid$ if $x \notin \mathbb{Q}$. Either way, when $x$ approaches $0$, $\mid \frac{f(x) - f(0)}{x} -1 \mid $ approaches $0$. Although $f$ is almost nowhere continuous, the derivative at $0$ exists and $f'(0) = 1$.
More generally, if you want $g(x_0) = y_0$, $g'(x_0) = a$ and $g$ continuous only at $x_0$, you can take :
$g(x) = y_0 + a\times f(x-x_0)$
A quite equivalent (but slightly different) explicit version would be :