Cohomology of groups relative to a variety