Lloyd missed Glamorgan's recent T20 Blast campaign through a hamstring injury but at 32 will hope to be an all-format regular for Derbyshire for several seasons, and could take on a leadership role.
He cited living in North Wales with his family as a contributing factor in his move. "Glamorgan has been my life for so long and I've made friendships that will last forever," Lloyd said.
"It has been a difficult decision to decide to leave but the opportunity to relocate and play closer to home in North Wales is what's best for my young family moving forward."
"I have enjoyed my time at Glamorgan and have made so many great memories, but I feel it's time for a change and the project at Derbyshire is one I'm really excited to be a part of."
The news is a boost for Derbyshire, who have had a disappointing first half of the summer. They missed out on the quarter-finals of the Blast with six wins and seven defeats, and are bottom of the second division of the County Championship after a winless start to the season.
Mickey Arthur, their head of cricket, said: "David is an experienced county cricketer and one who will bring a great level of leadership and ability into our squad. He has scored runs consistently throughout his career and gives us a different dimension at the top of the order.
"David's recruitment was key to our long-term plans and by getting the contract signed early, we've got time to continue shaping our squad ahead of next summer."
Mark Wallace, Glamorgan's director of cricket, said: "We will miss having David at the club both on and off the field but we fully respect and understand his decision to move closer to home for the benefit of his family."
In other county news, the New Zealand opener Will Young has joined Nottinghamshire on a three-match County Championship deal, beginning with a match against Surrey, the defending champions, at the Kia Oval.
And Paul Downton, the Kent director of cricket and former club captain and wicketkeeper, has announced he will be retiring from the role at the end of the season.