Added error reason to ncli if rebuilds fail with memory overload

This commit is contained in:
2026-05-26 16:23:09 +02:00
parent b04faa3602
commit 6b60113552

35
modules/ncli.nix Executable file → Normal file
View File

@ -91,7 +91,32 @@ in
echo -e "''${YELLOW}[->]''${NOCOLOR} $1" echo -e "''${YELLOW}[->]''${NOCOLOR} $1"
} }
# --- Main Logic --- handle_build_error() {
local exit_code=$?
# Exit code 137 = 128+9 = SIGKILL, almost always OOM killer
if [ "$exit_code" -eq 137 ]; then
echo ""
echo -e "''${RED}''${NOCOLOR}"
echo -e "''${RED} BUILD KILLED Signal 9 (SIGKILL) detected ''${NOCOLOR}"
echo -e "''${RED}''${NOCOLOR}"
echo ""
echo -e "''${YELLOW}What happened:''${NOCOLOR}"
echo " The build process was forcefully terminated by the OS."
echo " This is almost always the Linux kernel OOM killer running out"
echo " of RAM + swap during Nix evaluation or compilation."
echo ""
echo -e "''${YELLOW}Suggested fixes (try in order):''${NOCOLOR}"
echo ""
echo -e " ''${GREEN}1. Reduce parallel jobs''${NOCOLOR} (lowest RAM usage):"
echo " sudo nixos-rebuild switch --flake . --max-jobs 1 --cores 1"
echo ""
echo -e " ''${GREEN}2. Confirm OOM killer fired:''${NOCOLOR}"
echo " journalctl -k --since '5 minutes ago' | grep -i oom"
echo ""
fi
}
# --- Main Logic ---
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
echo "Error: No command provided." >&2 echo "Error: No command provided." >&2
print_help print_help
@ -164,7 +189,8 @@ in
current=$(cat /etc/nixos-tags) current=$(cat /etc/nixos-tags)
fi fi
if sudo nixos-rebuild switch --flake .; then sudo nixos-rebuild switch --flake . ; _rebuild_exit=$?
if [ "$_rebuild_exit" -eq 0 ]; then
echo " Rebuild finished successfully for $HOST" echo " Rebuild finished successfully for $HOST"
if [ -n "$current" ]; then if [ -n "$current" ]; then
@ -177,6 +203,7 @@ in
echo -e "Running on new generation: $YELLOW $geno $NOCOLOR-> $GREEN$genn$NOCOLOR" echo -e "Running on new generation: $YELLOW $geno $NOCOLOR-> $GREEN$genn$NOCOLOR"
else else
( exit "$_rebuild_exit" ); handle_build_error
echo " Rebuild failed for $HOST" >&2 echo " Rebuild failed for $HOST" >&2
exit 1 exit 1
fi fi
@ -258,7 +285,8 @@ in
echo "Rebuilding system... Staying on current specialization" echo "Rebuilding system... Staying on current specialization"
fi fi
if sudo nixos-rebuild switch --flake .; then sudo nixos-rebuild switch --flake . ; _rebuild_exit=$?
if [ "$_rebuild_exit" -eq 0 ]; then
echo " Update and rebuild finished successfully for $HOST" echo " Update and rebuild finished successfully for $HOST"
if [ -n "$current" ]; then if [ -n "$current" ]; then
@ -271,6 +299,7 @@ in
echo -e "Running on new generation: $YELLOW $geno $NOCOLOR-> $GREEN$genn$NOCOLOR" echo -e "Running on new generation: $YELLOW $geno $NOCOLOR-> $GREEN$genn$NOCOLOR"
else else
( exit "$_rebuild_exit" ); handle_build_error
echo " Update and rebuild failed for $HOST" >&2 echo " Update and rebuild failed for $HOST" >&2
exit 1 exit 1
fi fi