How do eyelids work?

During wakey time, my eyelids want to stay up. When sleepy time approaches, they want to stay down. During sleepy time, presumably, they stay down throughout. So, what controls the timing of these muscles? How’s it work?