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
103 lines
3.1 KiB
C++
103 lines
3.1 KiB
C++
#include "kappa/config/eval.hpp"
|
|
#include "kappa/service/types.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
namespace kappa::config {
|
|
|
|
std::string resolve_field(const dsl::SystemConfig& cfg, std::string_view path) {
|
|
auto dot = path.find('.');
|
|
auto ns = path.substr(0, dot);
|
|
|
|
if (ns == "boot") {
|
|
auto key = path.substr(dot + 1);
|
|
if (key == "kernel") { return cfg.boot.kernel; }
|
|
if (key == "init") { return cfg.boot.init; }
|
|
if (key == "efi") { return cfg.boot.efi; }
|
|
if (key == "swap") { return cfg.boot.swap; }
|
|
if (key == "root") { return cfg.boot.root; }
|
|
if (key == "bootloader") { return cfg.boot.bootloader; }
|
|
auto it = cfg.boot.params.find(std::string(key));
|
|
if (it != cfg.boot.params.end()) { return it->second; }
|
|
}
|
|
|
|
if (ns == "system") {
|
|
auto key = path.substr(dot + 1);
|
|
if (key == "hostname") { return cfg.system.hostname; }
|
|
if (key == "timezone") { return cfg.system.timezone; }
|
|
}
|
|
|
|
if (ns == "features") {
|
|
auto key = path.substr(dot + 1);
|
|
auto it = cfg.system.features.find(std::string(key));
|
|
if (it != cfg.system.features.end()) {
|
|
return it->second.enabled ? "true" : "false";
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
std::vector<AssertFailure> evaluate_assertions(const dsl::SystemConfig& cfg) {
|
|
std::vector<AssertFailure> failures;
|
|
|
|
for (auto& a : cfg.assertions) {
|
|
auto actual = resolve_field(cfg, a.field);
|
|
bool pass = false;
|
|
|
|
if (a.op == "==") {
|
|
pass = (actual == a.value);
|
|
} else if (a.op == "!=") {
|
|
pass = (actual != a.value);
|
|
}
|
|
|
|
if (!pass) {
|
|
failures.push_back({a.message, a.field, a.value, actual});
|
|
}
|
|
}
|
|
|
|
return failures;
|
|
}
|
|
std::unordered_map<std::string, dsl::NamedService> resolve_services(
|
|
const dsl::SystemConfig& cfg,
|
|
const std::unordered_map<std::string, dsl::PackageDef>& packages)
|
|
{
|
|
std::unordered_map<std::string, dsl::NamedService> resolved;
|
|
auto init_system = cfg.boot.init;
|
|
|
|
auto is = kappa::service::parse_init_system(init_system);
|
|
if (is == kappa::service::InitSystem::Unknown) {
|
|
std::cerr << "warning: unknown init system '" << init_system
|
|
<< "' — no services will be configured\n";
|
|
return {};
|
|
}
|
|
|
|
for (auto& svc : cfg.services) {
|
|
if (!svc.enable) { continue; }
|
|
|
|
// svc.name can be "postgresql" or "postgresql.checkpointer"
|
|
auto dot = svc.name.find('.');
|
|
auto pkg_name = (dot != std::string::npos)
|
|
? svc.name.substr(0, dot)
|
|
: svc.name;
|
|
auto svc_name = (dot != std::string::npos)
|
|
? svc.name.substr(dot + 1)
|
|
: std::string("main");
|
|
|
|
auto pit = packages.find(std::string(pkg_name));
|
|
if (pit == packages.end()) { continue; }
|
|
|
|
auto& pkg = pit->second;
|
|
for (auto& ns : pkg.services) {
|
|
if (ns.name == svc_name) {
|
|
resolved[svc.name] = ns;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return resolved;
|
|
}
|
|
|
|
} // namespace kappa::config
|