Information about the apply method

I’m curious about what happens with script plugins when I do something like
buildscript { sh ->
apply from ‘repos.gradle’, to: sh
Here my repos.gradle might configure some repositories:
repositories {
// various repositories defined
It seems to work, but how it works isn’t obvious. Can someone point me at the Gradle code that implements this? Or even provide an explanation?