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:
@@ -0,0 +1,62 @@
|
||||
#include "kappa/service/service.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
namespace kappa::service {
|
||||
|
||||
std::string generate_systemd_service(const ServiceSpec& spec) {
|
||||
std::ostringstream out;
|
||||
|
||||
// --- [Unit] ---
|
||||
out << "[Unit]\n";
|
||||
out << std::format("Description={}\n",
|
||||
spec.description.empty() ? spec.name : spec.description);
|
||||
if (!spec.after.empty()) {
|
||||
out << std::format("After={}\n", spec.after);
|
||||
}
|
||||
|
||||
// --- [Service] ---
|
||||
out << "\n[Service]\n";
|
||||
out << std::format("ExecStart={}\n", spec.exec);
|
||||
|
||||
if (spec.type == "simple") {
|
||||
out << "Type=simple\n";
|
||||
} else if (spec.type == "forking") {
|
||||
out << "Type=forking\n";
|
||||
} else if (spec.type == "oneshot") {
|
||||
out << "Type=oneshot\n";
|
||||
} else if (spec.type == "notify") {
|
||||
out << "Type=notify\n";
|
||||
} else {
|
||||
out << "Type=simple\n";
|
||||
}
|
||||
|
||||
if (!spec.user.empty()) {
|
||||
out << std::format("User={}\n", spec.user);
|
||||
}
|
||||
|
||||
if (spec.restart_policy == "always") {
|
||||
out << "Restart=always\n";
|
||||
} else if (spec.restart_policy == "on-failure") {
|
||||
out << "Restart=on-failure\n";
|
||||
} else if (spec.restart_policy == "never") {
|
||||
out << "Restart=no\n";
|
||||
}
|
||||
|
||||
if (!spec.working_dir.empty()) {
|
||||
out << std::format("WorkingDirectory={}\n", spec.working_dir);
|
||||
}
|
||||
|
||||
for (const auto& [key, value] : spec.env) {
|
||||
out << std::format("Environment=\"{0}={1}\"\n", key, value);
|
||||
}
|
||||
|
||||
// --- [Install] ---
|
||||
out << "\n[Install]\n";
|
||||
out << "WantedBy=multi-user.target\n";
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
} // namespace kappa::service
|
||||
Reference in New Issue
Block a user