Prepare macaroni according to package directions; set aside.
Melt 2 tablespoons butter in a large skillet over medium-high heat. Add sliced onions and 1 teaspoon sugar. Cook, stirring often, 15 to 20 minutes or until onions are caramel colored.
Layer half each of cooked macaroni, onions, cheeses, and cracker crumbs in a lightly greased 13- x 9-inch baking dish. Layer with remaining macaroni, onions, and cheeses.
Whisk together eggs and next 3 ingredients; pour over macaroni mixture.
Stir together remaining half of cracker crumbs, 2 tablespoons melted butter, and, if desired, pecans. Sprinkle evenly over macaroni mixture.
Bake at 350° for 1 hour or until golden brown and set. Let stand 10 minutes before serving.