The formation of lava tubes is a common phenomenon on some basaltic volcanoes, such as Etna. A model for tube formation by roofing of a channel is proposed and involves first describing lava as a Bingham liquid flowing down a slope. It is further assumed that lava flows in a channel with rectangular cross section: as a result of heat loss into the atmosphere, a crust is gradually formed on the upper surface of the flow and this crust eventually welds to the channel levées. We assume that a lava tube is formed when such a crust is sufficiently thick to resist the drag of the underlying flow and to sustain itself under its own weight. The minimum thickness of the crust satisfying such conditions depends on the tensile strength and shear strength of the crust itself. Assuming that the growth of the crust produces a downflow linear increase of the shear stress at the interface between flowing lava and the crust, the distance is evaluated between the eruption vent and the point where the tube is formed. The model predicts that if the flow rate is constant, the thickness of the flow increases as the crust fragments grow and weld to each other, and the velocity of the crust decreases to zero. Once the lava tube is formed, the initial flow rate can be achieved by a flow thickness smaller than the vertical size of the tube, with the same viscous dissipation: this may explain why under steady state conditions, the lava level inside a tube is frequently lower than the roof of the tube itself.