We present, for the first time, a Lagrangian multiform for the complete Kadomtsev-Petviashvili (KP) hierarchy -a single variational object that generates the whole hierarchy and encapsulates its integrability. By performing a reduction on this Lagrangian multiform, we also obtain Lagrangian multiforms for the Gelfand-Dickey hierarchy of hierarchies, comprising, amongst others, the Korteweg-de Vries and Boussinesq hierarchies.