How to provide input to DSL call in a plugin?

All of my Kotlin multiplatform build scripts starts with this boilerplate which declares the supported platforms and also sets the framework name for the iOS-specific platforms:

kotlin {
        android()
        listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach {
            it.binaries.framework {
                baseName = iosFrameworkName
            }
        }
}

I want to pull this code into a precompiled script plugin so that only iosFrameworkName is set by the build script. But how do you do this? I tried to set it using a Property in an extension in precompiled plugin, but that doesn’t work because it immediately tries to get the property while applying my plugin before I get a chance to set it.

I think what I want is a way to defer the kotlin call until after the build script applies my plugin, so the build script would look like

plugins {
    id("com.myproject.kmm")
}

kmm {
    iosFrameworkName = "MyFramework"
}

where kmm is a custom DSL call that runs the above kotlin call. But I can’t find any documentation about how to do this. All of the docs I’ve read only tell you how to do stuff like get/set properties and define tasks/extensions. But in this case I would need to call Project.kotlin. If I try to import that into a plugin it gets it from import gradle.kotlin.dsl.accessors._91c3ea59e5d2e7adad42047b60d6d606.kotlin which makes me think I’m doing something wrong.

Defining a custom extension does work.

open class KmmExtension(val project: Project) {
    fun configurePlatforms(iosFrameworkName: String) {
        // this feels a little hacky. mimic the normal `kotlin` extension
        project.extensions.configure<KotlinMultiplatformExtension>("kotlin") {
            listOf(iosX64(), iosSimulatorArm64(), iosArm64()).forEach {
                it.binaries.framework {
                    baseName = iosFrameworkName
                }
            }
        }
    }
}

then in my precompiled script plugin

val kmm = extensions.create<KmmExtension>("kmm")

kotlin {
    // create all of our platform targets
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()
}

and finally in my build script this works

kmm {
    configurePlatforms("FooBar")
}