Slice the onions into thin half-moons. Mince the garlic. Grate the cheeses and set aside.
Melt the butter with olive oil in a large heavy pot. Add the onions and salt. Cook slowly over medium-low heat for 30–35 minutes, stirring often, until golden brown. Halfway through, add the garlic and cook for 1 minute.
Sprinkle over the flour and thyme and stir, and cook for 2 minutes. (For gluten-free: use rice flour, or add cornstarch slurry later.)
Add brown sugar and cook for 1 minute. Deglaze with the wine or stock, scraping the base of the pot. Reduce by half.
Add the beef stock and simmer uncovered for 10 minutes until glossy and slightly thickened—season generously with cracked black pepper.
Cook the rigatoni in salted water until just under al dente. Reserve some pasta water before draining.
Toss the pasta with the onion sauce, loosening with reserved water until evenly coated.
Transfer to a greased baking dish. Top with Gruyère, mozzarella, and parmesan in layers.
Bake at 200°C (400°F), or 180°C fan (350°F fan), for 20 minutes until bubbling and golden. Rest for 5 minutes before serving. Dig in.