There’s more than one way to be wonky, and not all of them are bad.
Originally, though, "wonky" leaned negative. It first showed up in British English and described someone who was shaky or groggy. It could also refer to something that was faulty, unsound, or unreliable. Unfortunately, we don't know the origin of this meaning of "wonky."
The Oxford English Dictionary's earliest citation of "wonky" is from 1919, when a writer described himself as "week and wonky" in a letter. Use of "wonky" expanded from there to describe anything that wasn't quite right, like "wonky headlights" or "a wonky account." This meaning of "wonky" crossed over into American English by at least the 1960s.
In American English in the 1970s, another meaning of "wonky" emerged which was "bookish, studious, or nerdy." This meaning appears to come from the noun "wonk" which is a slangy term that may have started at Harvard. Some of the earliest data we have of "wonk" is from a 1962 Sports Illustrated article where the writer described Harvard slang as "making a tripartite classification of students into wonks, preppies, and jocks."
The OED has citations starting in 1970 where "wonkish" describes someone who was "excessively concerned with minute points of policy, especially governmental policy." Here's an example from Steven Kelman's 1970 book Push Comes to Shove, which is a memoir of political life at Harvard: "Harry is afraid that with you and Dave, the room is going to become too political and wonkish."
The noun "policy wonk" made its way into the language by the 1980s, but we should note that being wonkish doesn't always have to be about policy. In Jon Krakauer's 1997 book Into Thin Air, he describes someone as "a cerebral, somewhat wonkish cardiologist.
For more on "wonky" and "wonk," listen to the audio above.