The 25-year old was on loan at Pride Park for the final three months of last season and his performances were enough to force Nigel Clough to offer him a full contract.
Despite Millwall winning promotion to the second tier, Martin has decided to make the move, delighting Clough in the process.
“He settled in well during his loan spell and will come back for pre-season with a great deal of confidence because of the way he finished the season," said Clough.
"David is an exciting player, who we hope can develop here. He's hungry to succeed.
"He had to be patient waiting for his chance, but with Stephen Pearson likely to miss the start of the season after undergoing surgery he has the chance to make the position his own from the start."