Slowly cook thinly sliced yellow onions in butter over low heat for 30-40 minutes, stirring occasionally, until they turn golden brown and develop a rich, sweet flavor.
Sprinkle flour over the caramelized onions and stir well to coat. Gradually whisk in the beef or vegetable broth and half-and-half or heavy cream until smooth and thickened. Add minced garlic and dried thyme, then melt in Gruyère and sharp white cheddar cheeses until creamy and combined. Season with salt and pepper to taste.
Boil elbow macaroni according to package instructions until al dente. Drain well, reserving a small amount of pasta water in case you need to loosen the sauce later.
Mix the cooked macaroni into the cheese sauce, ensuring every piece is evenly coated with the luscious, velvety sauce.
Transfer the mac & cheese to an oven-safe dish. Top with extra grated cheese and toasted baguette slices if desired. Broil briefly until the top is bubbly and golden brown, mimicking the classic French onion soup crouton finish. Watch carefully to avoid burning.