The offenders tried to kick open the door to the post office and convenience store, in High Street, Barlborough, at about 3.25am on Tuesday.
When that failed, one of the men ran to the nearby Apollo pub and retrieved a beer barrel from the car park.
The would-be burglars then tried to force the post office door open by swinging the barrel at it, but they fled a short time later when the alarm went off.
Police investigating the offence want to hear from anyone who saw any suspicious activity in the area in the early hours of this morning.
Witnesses or anyone with information should call Derbyshire police on 101, quoting crime reference 50853/15.
You can also call Crimestoppers, anonymously, on 0800 555 111.