diff --git a/modules/ncli.nix b/modules/ncli.nix old mode 100755 new mode 100644 index 854f25d..a31ffd6 --- a/modules/ncli.nix +++ b/modules/ncli.nix @@ -91,7 +91,32 @@ in 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 echo "Error: No command provided." >&2 print_help @@ -164,7 +189,8 @@ in current=$(cat /etc/nixos-tags) 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" if [ -n "$current" ]; then @@ -177,6 +203,7 @@ in echo -e "Running on new generation: $YELLOW $geno $NOCOLOR-> $GREEN$genn$NOCOLOR" else + ( exit "$_rebuild_exit" ); handle_build_error echo "✗ Rebuild failed for $HOST" >&2 exit 1 fi @@ -258,7 +285,8 @@ in echo "Rebuilding system... Staying on current specialization" 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" if [ -n "$current" ]; then @@ -271,6 +299,7 @@ in echo -e "Running on new generation: $YELLOW $geno $NOCOLOR-> $GREEN$genn$NOCOLOR" else + ( exit "$_rebuild_exit" ); handle_build_error echo "✗ Update and rebuild failed for $HOST" >&2 exit 1 fi