write hakurei config representation

This commit is contained in:
mae
2025-09-27 03:33:23 -05:00
parent b57edb8d3a
commit bc1c7172d4
8 changed files with 163 additions and 5 deletions

View File

@@ -1,5 +1,2 @@
package moe.rosa.planterette
fun main() {
}

View File

@@ -0,0 +1,62 @@
package moe.rosa.planterette.hakurei
import kotlinx.serialization.Serializable
@Serializable
data class AbsolutePath(private val path: String) {
override fun toString(): String {
return path
}
}
interface FSType {
val type: String
}
data class ApplyState(val autoEtcPrefix: String)
@Serializable
data class FSBind(
val target: AbsolutePath,
val source: AbsolutePath,
val write: Boolean,
val device: Boolean,
val ensure: Boolean,
val optional: Boolean,
val special: Boolean,
override val type: String = "bind",
) : FSType
@Serializable
data class FSEphemeral(
val target: AbsolutePath,
val write: Boolean,
val size: Int,
val perm: Int,
override val type: String = "ephemeral"
) : FSType
@Serializable
data class FSLink(
val target: AbsolutePath,
val linkname: String,
val dereference: Boolean,
override val type: String = "link"
) : FSType
@Serializable
data class FSOverlay(
val target: AbsolutePath,
val lower: List<AbsolutePath>,
val upper: AbsolutePath,
val work: AbsolutePath,
override val type: String = "overlay"
) : FSType
@Serializable
data class FilesystemConfig(
val config: FSType
)

View File

@@ -0,0 +1,93 @@
package moe.rosa.planterette.hakurei
import kotlinx.serialization.Serializable
@Serializable
data class HakureiConfig(
val id: String,
val path: AbsolutePath,
val args: List<String>,
val enablements: Enablements,
val sessionBus: DBusConfig,
val systemBus: DBusConfig,
val directWayland: Boolean,
val username: String,
val shell: AbsolutePath,
val home: AbsolutePath,
val extraPerms: ExtraPermsConfig,
val identity: Int,
val groups: List<String>,
val container: ContainerConfig,
)
@Serializable
data class DBusConfig(
val see: List<String>,
val talk: List<String>,
val own: List<String>,
val call: Map<String, String>,
val broadcast: Map<String, String>,
val log: Boolean,
val filter: Boolean,
)
@Serializable
data class Enablements(
val wayland: Boolean,
val x11: Boolean,
val dbus: Boolean,
val pulse: Boolean,
)
@Serializable
data class ContainerConfig(
val hostname: String,
val waitDelay: Long,
val seccompFlags: Int,
val seccompPresets: Int,
val seccompCompat: Boolean,
val devel: Boolean,
val userns: Boolean,
val hostNet: Boolean,
val hostAbstract: Boolean,
val tty: Boolean,
val multiarch: Boolean,
val env: Map<String, String>,
val mapRealUid: Boolean,
val device: Boolean,
val filesystem: List<FilesystemConfig>,
)
@Serializable
data class ExtraPermsConfig(
val ensure: Boolean,
val path: AbsolutePath,
val read: Boolean,
val write: Boolean,
val execute: Boolean,
) {
override fun toString(): String {
val buffer = StringBuffer(5 + path.toString().length)
buffer.append("---")
if(ensure) {
buffer.append("+")
}
buffer.append(":")
buffer.append(path.toString())
if(read) {
buffer.setCharAt(0, 'r')
}
if(write) {
buffer.setCharAt(1, 'w')
}
if(execute) {
buffer.setCharAt(2, 'x')
}
return buffer.toString()
}
}

View File