I am aware these are most likely not original thoughts but i am going crazy over wrath of khan and the implications of the tale of two cities quotes.
I mean first we have kirk asking spock if he was trying to tell him something by buying that specific book, quoting "it was the best of times it was the worst of times."
Kirk might have interpreted it the way that spock was talking about their first five years mission together. They meet the first time and are coworkers, then they become friends, and eventually spock leaves in order to undergo kohlinar. All these feelings that kirk forces spock to deal with are so strange and hard to understand and the whole repressing his human side that spock had going on wasn't exactly helping either. In that way those were the worst years. But also, spock finally had a friend, someone he could trust and who would accept hin completely. He doesn't have to be vulcan or human, he can just be spock. And thus, it was the best of times.
But spock dismisses this. He might just be lying but in the end kirk understands what he was actually trying to say.
"It is a far, far better thing that I do, than I have ever done; it is a far, far better rest that I go to than I have ever known."
Spock doesn't want to just tell kirk about how those first years were for him. While it might have been complicated and messy, it still led them exactly where they are now. And spock loving kirk is just "a far far better thing that he does, than he has ever done."
I have not read the book but with it ending with a self sacrifice to save the characters friends is also telling of course. And that is what that quote is about. Knowing that his friends (And kirk specifically) will be safe spock will rest better than he has ever before.
And while spock couldn't have predicted his death when he bought the book for kirk he still knew that he would do what the character does for him.
And that what they have now, is exactly how it is supposed to be and he wouldn't change anything about it.