feat: system-agnostic package manager — 5 inits, 2 bootloaders, parallel scheduler

Complete rewrite of kappa from a sequential build tool into a
system-agnostic package manager with runtime init switching.

Core additions:
- 5 init system backends: systemd, openrc, s6, runit, dinit
  (service file generation, enable/disable, init_paths)
- 2 bootloader backends: grub, limine (config generation, fallback entries)
- Parallel scheduler with worker pool, depth-based priority (Beta/Alpha/Zeta),
  atomic claiming, dependency tracking, deduplication, and failure propagation
- Init-switch impact analysis: only rebuild packages using ${enabledinit}
- Init-agnostic service definitions: flat NamedService blocks replace
  per-init nesting
- Package conflicts: mutual incompatibility detection in resolver
- System groups: init-agnostic group creation in DSL
- Init-agnostic hostname/timezone: direct /etc/hostname and /etc/localtime writes
- Source tarball caching at /kappa/cache/ with atomic write-then-rename
- Package recipe caching with remote fetching and version comparison
- remotes = [...] block in system config for package repositories
- Auto-fetch: rebuild resolves missing packages from remotes
- uninstall phase in package definitions
- ${enabledinit} eval variable for init-conditional builds
- Shared util module (to_lower, shell_escape)
- 54 integration tests across two shell test suites
- Comprehensive README and CONTRIBUTING guide

Bug fixes from review:
- CRITICAL: Replace std::system() with fork+execvp (command injection)
- CRITICAL: Fix scheduler deadlock on successful completion
- CRITICAL: Fix rebuild init/kernel/bootloader change detection
- HIGH: Fix path traversal via unsanitized package names in cache
- HIGH: Fix TOCTOU race in cache write with atomic rename
- HIGH: Fix formatter dropping remotes/imports blocks
- HIGH: Fix formatter stripping empty-string assert values
- HIGH: Fix formatter non-idempotent output (sorted key iteration)
- HIGH: Populate ${enabledinit} from boot.init in BuildStep
- MEDIUM: Fix data race on non-atomic scheduler stop flag
- MEDIUM: Fix compute_depths() traversal direction
- MEDIUM: Add runit to doctor supported-init warning
- MEDIUM: Extract to_lower/shell_escape to shared kappa::util
- MEDIUM: Consolidate generator declarations in headers
This commit is contained in:
2026-07-31 05:32:57 -04:00
parent d6612d0a4a
commit dd984f96d4
40 changed files with 3047 additions and 117 deletions
+69 -23
View File
@@ -27,8 +27,12 @@ static void write_env(std::ostream& os, int d,
static void write_features(std::ostream& os, int d,
const std::unordered_map<std::string, dsl::FeatureDef>& feats) {
if (feats.empty()) { return; }
std::vector<std::string> keys;
for (auto& [k, _] : feats) keys.push_back(k);
std::sort(keys.begin(), keys.end());
os << Indent(d) << "features {\n";
for (auto& [k, f] : feats) {
for (auto& k : keys) {
auto& f = feats.at(k);
if (f.flag.empty() && !f.force) {
os << Indent(d + 1) << k << " = " << (f.enabled ? "true" : "false") << "\n";
} else {
@@ -105,6 +109,15 @@ void format_package(std::ostream& os, const dsl::PackageDef& pkg) {
os << "]\n";
}
if (!pkg.conflicts.empty()) {
os << Indent(d) << "conflicts = [";
for (std::size_t i = 0; i < pkg.conflicts.size(); ++i) {
if (i > 0) { os << ", "; }
os << '"' << pkg.conflicts[i] << '"';
}
os << "]\n";
}
if (!pkg.patches.empty()) {
os << Indent(d) << "patches = [\n";
for (auto& p : pkg.patches) {
@@ -151,27 +164,33 @@ void format_package(std::ostream& os, const dsl::PackageDef& pkg) {
os << Indent(d) << "}\n";
}
if (!pkg.service.empty()) {
os << Indent(d) << "service {\n";
for (auto& [init, si] : pkg.service) {
os << Indent(d + 1) << init << " {\n";
if (!si.exec.empty()) { os << Indent(d + 2) << "exec = \"" << si.exec << "\"\n"; }
if (!si.type.empty()) { os << Indent(d + 2) << "type = \"" << si.type << "\"\n"; }
if (!si.user.empty()) { os << Indent(d + 2) << "user = \"" << si.user << "\"\n"; }
if (!si.ports.empty()) {
os << Indent(d + 2) << "ports = [";
for (std::size_t i = 0; i < si.ports.size(); ++i) {
if (!pkg.services.empty()) {
for (auto& ns : pkg.services) {
if (ns.name != "main") {
os << Indent(d) << "service " << ns.name << " {\n";
} else {
os << Indent(d) << "service {\n";
}
if (!ns.exec.empty()) { os << Indent(d + 1) << "exec = \"" << ns.exec << "\"\n"; }
if (!ns.type.empty()) { os << Indent(d + 1) << "type = \"" << ns.type << "\"\n"; }
if (!ns.user.empty()) { os << Indent(d + 1) << "user = \"" << ns.user << "\"\n"; }
if (!ns.ports.empty()) {
os << Indent(d + 1) << "ports = [";
for (std::size_t i = 0; i < ns.ports.size(); ++i) {
if (i > 0) { os << ", "; }
os << si.ports[i];
os << ns.ports[i];
}
os << "]\n";
}
for (auto& [k, v] : si.env) {
os << Indent(d + 2) << k << " = \"" << v << "\"\n";
if (!ns.description.empty()) { os << Indent(d + 1) << "description = \"" << ns.description << "\"\n"; }
if (!ns.after.empty()) { os << Indent(d + 1) << "after = \"" << ns.after << "\"\n"; }
if (!ns.restart.empty()) { os << Indent(d + 1) << "restart = \"" << ns.restart << "\"\n"; }
if (!ns.working_dir.empty()) { os << Indent(d + 1) << "working_dir = \"" << ns.working_dir << "\"\n"; }
for (auto& [k, v] : ns.env) {
os << Indent(d + 1) << k << " = \"" << v << "\"\n";
}
os << Indent(d + 1) << "}\n";
os << Indent(d) << "}\n";
}
os << Indent(d) << "}\n";
}
if (!pkg.assertions.empty()) {
@@ -189,6 +208,7 @@ void format_package(std::ostream& os, const dsl::PackageDef& pkg) {
write_phase(os, d, "build", pkg.build);
write_phase(os, d, "check", pkg.check);
write_phase(os, d, "install", pkg.install);
write_phase(os, d, "uninstall", pkg.uninstall);
os << "}\n";
}
@@ -203,13 +223,20 @@ void format_config(std::ostream& os, const dsl::SystemConfig& cfg) {
os << "]\n\n";
}
if (!cfg.remotes.empty()) {
os << "remotes = [\n";
for (auto& r : cfg.remotes) {
os << " \"" << r << "\",\n";
}
os << "]\n\n";
}
if (!cfg.assertions.empty()) {
os << "assert {\n";
for (auto& a : cfg.assertions) {
os << " \"" << a.message << "\" : "
<< a.field << " " << a.op;
if (!a.value.empty()) { os << " \"" << a.value << '"'; }
os << "\n";
<< a.field << " " << a.op
<< " \"" << a.value << '"' << "\n";
}
os << "}\n\n";
}
@@ -222,8 +249,11 @@ void format_config(std::ostream& os, const dsl::SystemConfig& cfg) {
write_env(os, 1, s.env);
if (!s.config.empty()) {
os << " config {\n";
for (auto& [k, v] : s.config) {
os << " " << k << " = \"" << v << "\"\n";
std::vector<std::string> cfg_keys;
for (auto& [k, _] : s.config) cfg_keys.push_back(k);
std::sort(cfg_keys.begin(), cfg_keys.end());
for (auto& k : cfg_keys) {
os << " " << k << " = \"" << s.config.at(k) << "\"\n";
}
os << " }\n";
}
@@ -245,8 +275,11 @@ void format_config(std::ostream& os, const dsl::SystemConfig& cfg) {
write_features(os, 2, p.features);
if (!p.config.empty()) {
os << " config {\n";
for (auto& [k, v] : p.config) {
os << " " << k << " = " << v << "\n";
std::vector<std::string> pcfg_keys;
for (auto& [k, _] : p.config) pcfg_keys.push_back(k);
std::sort(pcfg_keys.begin(), pcfg_keys.end());
for (auto& k : pcfg_keys) {
os << " " << k << " = " << p.config.at(k) << "\n";
}
os << " }\n";
}
@@ -268,6 +301,19 @@ void format_config(std::ostream& os, const dsl::SystemConfig& cfg) {
os << "}\n\n";
}
if (!cfg.groups.empty()) {
os << "groups {\n";
for (auto& g : cfg.groups) {
os << " " << g.name;
if (g.gid < 0) {
os << " {}\n";
} else {
os << " {\n gid = " << g.gid << "\n }\n";
}
}
os << "}\n\n";
}
write_boot_block(os, 0, cfg.boot);
os << "\n";