Sleep is a universal behavior in vertebrate and invertebrate animals, suggesting it originated in the very first life forms. Given the vital function of sleep, sleeping patterns and sleep architecture follow dynamic and adaptive processes reflecting trade-offs to different selective pressures. Here, we review responses in sleep and sleep-related behavior to environmental constraints across primate species, focusing on the role of great ape nest building in hominid evolution. We summarize and synthesize major hypotheses explaining the proximate and ultimate functions of great ape nest building across all species and subspecies; we draw on 46 original studies published between 2000 and 2017. In addition, we integrate the most recent data brought together by researchers from a complementary range of disciplines in the frame of the symposium "Burning the midnight oil" held at the 26th Congress of the International Primatological Society, Chicago, August 2016, as well as some additional contributors, each of which is included as a "stand-alone" article in this "Primate Sleep" symposium set. In doing so, we present crucial factors to be considered in describing scenarios of human sleep evolution: (a) the implications of nest construction for sleep quality and cognition; (b) the tree-to-ground transition in early hominids; (c) the peculiarities of human sleep. We propose bridging disciplines such as neurobiology, endocrinology, medicine, and evolutionary ecology, so that future research may disentangle the major functions of sleep in human and nonhuman primates, namely its role in energy allocation, health, and cognition.