The proposed solution works, or can be made to work. There is a bit of a problem in that the reasoning is not explained fully. For example, the derivative is used in the argument. But it is conceivable that f' does not exist, at least for some $x$.
However, to me the main issue is that there are too many symbols, and too little geometry. We are dealing with a very concrete problem, and a more concrete solution, if achievable, is better.
So let us think about this mapping $f$. Suppose that $f$ takes $0$ to $a$. Let $g(x)=f(x)-a$. Then $g(0)=0$, and $g$ is distance-preserving.
We will show that $g(x)=x$ or $g(x)=-x$, from which it will follow that $f(x)=x+a$ or $f(x)=-x+a$.
Look at $g(1)$. Because $g$ is distance-preserving, we have $g(1)=1$ or $g(1)=-1$. We deal first with the case $g(1)=1$.
Case $g(1)=1$: Suppose that $g(1)=1$. Let $x$ be any number other than $0$. We show that $g(x)=x$. This is clear, there is only one point at distance $|x|$ from $0$ and simultaneously at distance $|x-1|$ from $1$, and this point is $x$. For a "formal" verification, let's show that $-x$ doesn't work. How can we have $|(-x)-1|=|x-1|$? We need either $-x-1=x-1$, which forces $x=0$, or $x+1=x-1$, which is impossible.
Case $g(1)=-1$: Let $h(x)=-g(x)$. Then $h(1)=1$. Since $h$ is distance-preserving, we have $h(x)=x$ for all $x$, and hence $g(x)=-x$.