For the pierogi dough: Combine the egg, butter, sour cream, chives and salt with your hands in a bowl. Don't worry if the mixture is not uniform and, as with pie dough, don't overwork it. Add the flour and mix with your hands until a dough forms. Wrap in plastic and refrigerate the dough at least 2 hours and up to 2 days.
For the filling: Put the potatoes in a large pot and cover with 2 inches of cold water. Bring to a boil. Season the water generously with salt. Reduce the heat to maintain a simmer and cook until a knife easily pierces the potatoes. Drain and return the potatoes to the pot. Mash, slowly mixing in the hot cream and cold butter. Season with salt and pepper to taste and set aside.
Warm the olive oil in a large skillet over medium-high heat. Cook the bacon, stirring occasionally, until crisp, about 10 minutes. Transfer to a plate with a slotted spoon. Reduce the heat to medium, add the onions and toss to coat with the bacon fat. Season with salt and pepper. Cook, stirring frequently, until the onions are caramelized and sweet. Let cool.
Preheat the oven to 350 degrees F. Butter a 13-by-9-inch casserole dish or metal pan.
Roll out the pierogi dough with a rolling pin on a lightly floured work surface to a 1/8-inch-thick rectangle. Cut into 4-by-13-inch strips, re-rolling the scraps as necessary. You will need 14 to 20 strips.
To assemble: Have the mashed potatoes, crisp bacon, caramelized onions, pasta strips and cheeses ready on a work surface. Arrange one layer of pierogi dough strips on the bottom of the buttered casserole dish, slightly overlapping the edges of the strips. Spread a 1/2-inch layer of potatoes on top of the dough. Top with some caramelized onions, bacon and a sprinkling of both Gruyere and farmer's cheese. Repeat the layers to use the remaining ingredients, finishing with the dough, followed by some Gruyere and farmer's cheese. Season the top with pepper.
Bake until the casserole is bubbly and the cheese on top is golden brown, about 40 minutes. Let rest 15 to 20 minutes and then serve with a dollop of sour cream and a sprinkle of chives if using.
For more ingredient substitution ideas, see the article below.