Deriving spacetime from first principles