Why in my grammar book this sentence " Almost before I had shut my eyes, I felt a nudge in my side" they use past perfect, even nudge occurred first?
You've probably been told that the past perfect represents a time prior to some other past time. Although it's a very common explanation, it isn't quite true.
The "had shut" construction doesn't directly represent an action further in the past than the "felt". In fact, it doesn't directly represent an action. It represents a state. The "had shut" construction directly represents a state that is the result of the action of "to shut", as possessed by the semantic agent of "to shut".
Obviously, the result of an action can't exist before that action begins. The usual implication is that this past-tense state is the result of an earlier past-tense action. This is the reason that the common explanation mentioned in my first paragraph, although not quite true and not quite complete, still seems to make sense in many cases.
In your example sentence, "had shut" and "felt" represent the same point of time in the past. We could recast the sentence to use past indefinite constructions for both clauses:
Almost before I shut my eyes, I felt a nudge at my side.
Alternately, we could write sentences that have different sequences, without changing tense or aspect at all:
Long before I had shut my eyes, I felt a nudge at my side.
Long after I had shut my eyes, I felt a nudge at my side.
There is no specific sequence in time between a given past perfect construction and any other past-tense construction. There is only the logical requirement that the result of an action does not exist before the action that produces it begins.