Gianluca,
I got the impression that the original poster wants the curves to be labeld by the functions itself. Not just "function" and "derivative". So this a simple variation of your solution:
var = Input["Type a variable, such as x, in this window."];
expr = Input[
"Type an expression to be differentiated in the variable you just typed in the last window."];
g[blah_] = expr /. {var -> blah};
derivatives := {Callout[g[var], g[var], Above], Callout[g'[var], g'[var], Above]};
Plot[
Evaluate@derivatives, {x, -3, 5},
PlotLabel -> "A function and its Derivative", PlotRange -> 20
]

I increased the plot range, so as not to crowd the function labels
Callout documentation