Applying plugin in initscript fails

I’m perplexed about how init scripts work. Below is my init script where I try to apply a plugin. With the apply plugin ... line commented out everything works fine. In addition, if I add initscript.repositories.each { println "Name: " + it.name + "; url: " + it.url } outside the initscript block the correct values for the repository are printed. But with the apply plugin ... line I get the following error:

Could not find property 'repoUrl' on org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated@4d0fbb93.

My init script:

initscript {

    Properties props = new Properties()
    props.load(new File(gradle.gradleUserHomeDir, 'gradle.properties').newDataInputStream())

    def repoUrl = props.REPO_URL ?: System.env.REPO_URL
   
    repositories {
        maven {
            url repoUrl
        }
    }

    dependencies {
        classpath group: 'com.foo.gradle', name: 'gradle-init-plugin', version: '+'
    }
}

apply plugin: com.foo.gradle.GradleInitPlugin

Note that I am using Gradle 2.13 currently.