ראב"צ אומר עשה דברים לשם פעלם [ראש: לשמו של הקב"ה שפעל הכל למענהו], ודבר בהם לשמם [רא"ש: כל דבורך ומשאך בדברי תורה יהיה לשם התורה כגון לידע ולהבין ולהוסיף לקח ופלפול, ולא לקנטר ולהתגאות] ע"כ
The Nefesh HaChaim at the beginning of sha'ar 4 uses this gemara as his source for his definition of Torah li'shma, which is really the definition of the Rosh. Li'shma means for the purpose of mastering Torah, meaning study Torah with the focus and mindset of mastering the material. This is different than the intention needed for a mitzvah, which is for the sake of G-d (as the rosh explains), but by learning it is not for the sake of Hashem, rather for the sake of mastering the Torah.
Rashi seems to disagree because his girsa is דבר בהן לשם שמים which implies that even Torah should be studied for the purpose of serving Hashem. The Nefesh HaChaim already points this out and says that even Rashi doesn't mean d'veikus to hashem but rather just to the exclusion of ulterior motives such as arrogance. Nevertheless, the Nefesh HaChaim claims that Rashi would entirely agree with the Rosh that the definition of "li'shma" is for the sake of mastering Torah. However, in the footnotes on Nefesh HaChaim (Goldberg) he points out that rashi in Ta'anis 7a in the context of Torah li'shma being a medicine for life, defines "li'shma" to mean "because G-d commanded me to do so". This clearly seems to be different that the Rosh cited by Nefesh HaChaim.
I would suggest that everything depends on the context of what you want from the Torah. R' Elazar Bar Tzadok is talking about what one needs to do to acheive maximum reward in olam ha'ba, and that is accomplished by studying Torah for the purpose of mastering Torah. That is why the Nefesh HaChaim connects this to R' Yochanan Ben Zakai (succah 28a) who was zoche to "li'hanchil l'ohavai yesh" - receiving s'char for his efforts. But, when one wants a physical benefit from the Torah such as serving as a "medicine of life", the Torah must be studied for the purpose of being submissive to G-d and learning because of Hashems command. Being mevatel one's physical self to the command of Hashem is in essence putting his body in G-d's hands and causing Hashem to take responsibility for his physical health (as a master takes responsibility for the health of his servants).