Nanostructures at surfaces from substrate-mediated interactions