I hit the nail on the head when I had to decide to build this project from scratch.
This doesn't sound right because the phrase 'hit the nail on the head' implicitly suggests that one has chosen the right option amongst a choice of options. But in your sentence there isn't any sense of there being a search for options. In other words, some contextual information is missingand this might require additional sentences.
Although classically, the unit of sense is the sentence, in some/many cases the sense is carroed across several sentences.
Plus stylistically speaking, the sentence seems rather cliched. After all, you've used two cliches in one sentence: "hitting the nail on the head" and "from scratch".