US slang, from the WWII
era (first printed record in the US Air Force in the 1950's). Similar expressions like buy the plot and buy the lot also existed, although buy the farm
is the only one to have survived. Probably related to older British slang buy it, buy one or buy the packet, both seemingly ironic references to something that one does not want to buy. May come from the common reflection that once someone had finished his service he would go home and buy a farm to settle on. Also, it may be in reference to the book Of Mice and Men
by John Steinbeck. Main characters George and Lennie always talk about owning their own farm where they will have to answer to no one and "live off the fatt'a the land." Later, when George must kill Lennie they talk about how they will buy the farm when George pulls the trigger and shoots Lennie to kill him painlessly.