This commit is contained in:
2025-07-02 15:16:24 +00:00
parent 721319fa1a
commit 4f279de5fb
4 changed files with 129 additions and 12 deletions

6
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1751285371, "lastModified": 1751382304,
"narHash": "sha256-/hDU+2AUeFFu5qGHO/UyFMc4UG/x5Cw5uXO36KGTk6c=", "narHash": "sha256-p+UruOjULI5lV16FkBqkzqgFasLqfx0bihLBeFHiZAs=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b9c03fbbaf84d85bb28eee530c7e9edc4021ca1b", "rev": "d31a91c9b3bee464d054633d5f8b84e17a637862",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -7,7 +7,6 @@
with lib; let with lib; let
cfg = config.boot.loader.kboot-conf; cfg = config.boot.loader.kboot-conf;
# The builder used to write during system activation
# The builder used to write during system activation # The builder used to write during system activation
builder = pkgs.replaceVars ./generate-kboot-conf.sh { builder = pkgs.replaceVars ./generate-kboot-conf.sh {
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
@@ -19,6 +18,106 @@ with lib; let
path = with pkgs.buildPackages; [coreutils gnused gnugrep]; path = with pkgs.buildPackages; [coreutils gnused gnugrep];
inherit (pkgs.buildPackages) bash; inherit (pkgs.buildPackages) bash;
}; };
# Debug wrapper function that takes args as parameter
mkDebugBuilder = args: pkgs.writeScript "kboot-debug-wrapper" ''
#!${pkgs.bash}/bin/bash
# Set up PATH with required utilities
export PATH=${lib.makeBinPath (with pkgs; [ coreutils util-linux procps gnugrep gnused])}:$PATH
# Create unique log file
log_file="/tmp/kboot-debug-$(date +%Y%m%d-%H%M%S)-$.log"
# Function to log with timestamp
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S'): $*" | tee -a "$log_file"
}
# Start logging
{
log "=== KBOOT DEBUG START ==="
log "Script called with args: $*"
log "Current working directory: $(pwd)"
log "Current user: $(id)"
log "Environment variables:"
env | sort | sed 's/^/ /'
log "System information:"
log " Hostname: $(hostname)"
log " Uptime: $(uptime)"
log "Mount information:"
mount | grep -E "(boot|root|nix)" | sed 's/^/ /'
log "Checking system configuration path: $1"
if [[ -n "$1" ]]; then
if [[ -e "$1" ]]; then
log " System config exists: $1"
log " Real path: $(readlink -f "$1")"
log " Contents:"
ls -la "$1" 2>&1 | sed 's/^/ /'
# Check for required files
for file in kernel initrd dtbs nixos-version kernel-params; do
if [[ -e "$1/$file" ]]; then
log " Found $file"
if [[ "$file" == "dtbs" ]]; then
log " DTB contents:"
ls -la "$1/$file" 2>&1 | head -10 | sed 's/^/ /'
fi
else
log " Missing $file"
fi
done
else
log " ERROR: System config path does not exist: $1"
fi
else
log " ERROR: No system config path provided"
fi
log "Boot partition status:"
if mountpoint -q /boot 2>/dev/null; then
log " /boot is mounted"
log " /boot contents:"
ls -la /boot 2>&1 | head -10 | sed 's/^/ /'
# Test write permissions
if touch /boot/.kboot-write-test 2>/dev/null; then
log " /boot is writable"
rm -f /boot/.kboot-write-test
else
log " /boot is not writable"
fi
else
log " /boot is not mounted"
fi
log "Process information:"
ps aux | grep -E "(nixos-rebuild|systemd)" | head -5 | sed 's/^/ /'
log "Nix store status:"
log " Nix store mount: $(df -h /nix/store | tail -1)"
log "=== EXECUTING ORIGINAL BUILDER ==="
log "Command: ${builder} ${args} $*"
} 2>&1 | tee -a "$log_file"
# Execute the original builder and capture its output
if /run/current-system/sw/bin/bash ${builder} ${args} "$@" 2>&1 | tee -a "$log_file"; then
log "=== KBOOT DEBUG SUCCESS ==="
echo "Debug log saved to: $log_file" >&2
else
exit_code=$?
log "=== KBOOT DEBUG FAILED (exit code: $exit_code) ==="
echo "Debug log saved to: $log_file" >&2
echo "KBOOT INSTALLATION FAILED - Check $log_file for details" >&2
exit $exit_code
fi
'';
in { in {
options = { options = {
boot.loader.kboot-conf = { boot.loader.kboot-conf = {
@@ -29,6 +128,16 @@ in {
Whether to create petitboot-compatible /kboot.conf Whether to create petitboot-compatible /kboot.conf
''; '';
}; };
debug = mkOption {
default = false;
type = types.bool;
description = ''
Whether to enable debugging output for kboot configuration generation.
Logs will be written to /tmp/kboot-debug-*.log
'';
};
configurationLimit = mkOption { configurationLimit = mkOption {
default = 10; default = 10;
example = 5; example = 5;
@@ -37,6 +146,7 @@ in {
Maximum number of configurations in the generated kboot.conf. Maximum number of configurations in the generated kboot.conf.
''; '';
}; };
populateCmd = mkOption { populateCmd = mkOption {
type = types.str; type = types.str;
readOnly = true; readOnly = true;
@@ -49,14 +159,20 @@ in {
}; };
}; };
}; };
config = let config = let
args = "-g ${toString cfg.configurationLimit} -n ${config.hardware.deviceTree.name}"; args = "-g ${toString cfg.configurationLimit} -n ${config.hardware.deviceTree.name}";
in
# Choose between debug and normal builder
activeBuilder = if cfg.debug then (mkDebugBuilder args) else builder;
mkIf cfg.enable { in mkIf cfg.enable {
system.build.installBootLoader = lib.mkForce "${builder} ${args} -c"; system.build.installBootLoader = lib.mkForce "${activeBuilder} ${args} -c";
system.boot.loader.id = "kboot-conf"; system.boot.loader.id = "kboot-conf";
boot.loader.kboot-conf.populateCmd = "${populateBuilder} ${args}"; boot.loader.kboot-conf.populateCmd = "${populateBuilder} ${args}";
# Warn user about debug mode
warnings = lib.optional cfg.debug
"kboot-conf debug mode is enabled. Debug logs will be written to /tmp/kboot-debug-*.log";
}; };
} }

View File

@@ -66,7 +66,7 @@
server = { server = {
enabled = true; enabled = true;
bootstrap_expect = 3; bootstrap_expect = 3;
start_join = ["192.168.1.225" "192.168.1.226" "192.168.1.227" "192.168.1.228"]; start_join = ["192.168.4.225" "192.168.4.226" "192.168.4.227" "192.168.4.228"];
rejoin_after_leave = false; rejoin_after_leave = false;
enabled_schedulers = ["service" "batch" "system"]; enabled_schedulers = ["service" "batch" "system"];
num_schedulers = 4; num_schedulers = 4;
@@ -83,7 +83,7 @@
enabled = true; enabled = true;
node_class = ""; node_class = "";
no_host_uuid = false; no_host_uuid = false;
servers = ["192.168.1.221:4647" "192.168.1.225:4647" "192.168.1.226:4647" "192.168.1.227:4647" "192.168.1.222:4647" "192.168.1.223:4647" "192.168.1.224:4647"]; servers = ["192.168.4.221:4647" "192.168.4.225:4647" "192.168.4.226:4647" "192.168.4.227:4647" "192.168.4.222:4647" "192.168.4.223:4647" "192.168.4.224:4647"];
max_kill_timeout = "30s"; max_kill_timeout = "30s";
network_speed = 0; network_speed = 0;
cpu_total_compute = 0; cpu_total_compute = 0;

View File

@@ -11,6 +11,7 @@
boot.loader.grub.enable = false; boot.loader.grub.enable = false;
boot.loader.kboot-conf.enable = true; boot.loader.kboot-conf.enable = true;
boot.loader.kboot-conf.debug = true;
# Use kernel >6.6 # Use kernel >6.6
boot.kernelPackages = pkgs.linuxPackages_latest; boot.kernelPackages = pkgs.linuxPackages_latest;
# Stop ZFS breasking the build # Stop ZFS breasking the build