...
from https://www.worldwidewords.org/qa/qa-nic2.htm
Language experts are sure that nick here is the same word as that for a small cut or notch.
Sometime round about the 1580s the phrase in the nick or in the very nick began to be used for the critical moment, the exact instant at which something has to take place. The idea seems to have been that a nick was a narrow and precise marker, so that if something was in the nick it was precisely where it should be.
It seems that users of the expression pretty soon afterwards found this association of ideas needed some elaboration, so started to add of time to the expression, and that’s the way it has stayed ever since. These days, the phrase more usually refers to something that only just happens in time, at the last possible moment