The function $f$ doesn't have to be constant!
A non-constant function $f$ with the required properties is given as Exercise 13.J in A. C. M. van Rooij, W. H. Schikhof, A Second Course on Real Functions, based on an example due to Y. Katznelson and Karl Stromberg, in Everywhere differentiable, nowhere monotone, functions, Amer. Math. Monthly 81 (1974), 349–354, jstor.
Here is a copy of the example:
Another example is has been constructed by Dimitrie Pompeiu in Sur les fonctions dérivées, Math. Ann. 63 (1907), no. 3, 326—332, doi: 10.1007/BF01449201, eudml, GDZ.
You can have a look here.