It's tricky.
A bequest is a gift and, in essence, it is no different from a gift given while you were alive. You are free to give gifts to whoever you like for whatever reason, or no reason.
However, alive or dead, your largess may cause issues for other people.
The Recipient
Some employers (not just governments) place restrictions on their employees receiving gifts. This may be an outright ban or may be a limit on the value - you don't know what these restrictions are.
The gift may put the person in a difficult position and since, presumably, the intent of the gift was to make them feel good, making them have a legal/ethical dilemma sort of defeats this.
Other Beneficiaries
Clearly the gift you give to the people above would otherwise have gone to someone else. Someone who may feel that the recipient used their trusted position as your doctor/nurse/librarian/lion tamer to place undue influence on you, overtly or covertly.
These beneficiaries may feel this so strongly that they take legal action to have that bequest set aside. If you want to avoid them being successful (or even making the attempt) your will should express clear reasons why you made the gift and demonstrate that the recipient did not in some way coerce the gift, bearing in mind that they have already been paid for the services they provided you and that you are not there to explain yourself.
As an aside, if you plan to leave someone out of a will that would normally be in it, you need good reasons for that too.
Again, given that the purpose of the gift is to bring the recipient joy, having to defend their right to it in court may dilute or eliminate that joy.
TL;DR
Is it legal? Yes.
Is it a good idea? Probably not: share a bottle of whisky with them now when you can both enjoy it.