I would do this by parenting an empty in line with the sun, then using the empty's coordinates as a vector in the node editor to get the sun's rotation.
First create an empty and parent it to the sun lamp. The empty should be directly in line with the sun lamp, but not exactly on top of it. To do this it helps to reset the sun's rotation (Alt+R) and put the empty somewhere directly underneath the lamp before parenting it, then re-position the lamp how you want it.
Next go to the node editor and add the following nodes. The output on the right will be the desired gradient from facing sun's direction 1.0
to facing directly away from the sun 0.0
. The three Value nodes on the left are driven by the empty's X, Y, and Z positions respectively.
The position of the empty is converted to a vector using the Converter > Combine XYZ node, then normalized so that you don't have to worry about the distance from the lamp to the empty and scene units conversion to the node editor etc. The desired output is created by taking the dot product of this value and the geometry's normals.
Note that since I am using the dot product, this output will be a quadratic gradient. To get a linear gradient you will have to compute the vector similarity manually, or just use a color ramp or RGB curve node to create a satisfactory gradient.