- Simplified command cases by removing unnecessary semicolons.

- Improved error handling in rebuild.nix for clarity and consistency.
This commit is contained in:
2026-05-29 09:29:31 +02:00
parent d989792774
commit 134fc441a5
8 changed files with 435 additions and 447 deletions

View File

@ -13,64 +13,76 @@ in
# --- Backup helper ---
handle_backups = ''
if [ ''${#BACKUP_FILES[@]} -eq 0 ]; then
echo "No backup files configured to check."
return
fi
echo "Checking for backup files to remove..."
for file_path in "''${BACKUP_FILES[@]}"; do
full_path="$HOME/$file_path"
if [ -f "$full_path" ]; then
echo "Removing stale backup file: $full_path"
rm "$full_path"
handle_backups() {
echo "Checking for backup files to remove..."
found=0
for file_path in "''${BACKUP_FILES[@]}"; do
full_path="$HOME/$file_path"
if [ -f "$full_path" ]; then
echo "Removing stale backup file: $full_path"
rm "$full_path"
found=1
fi
done
if [ "$found" -eq 0 ]; then
echo "No stale backup files found."
fi
done
}
'';
# --- OOM / build error handler ---
handle_build_error = ''
local exit_code=$?
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
handle_build_error() {
local exit_code=$?
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
}
'';
# --- Print helpers (used by dev init) ---
print_header = ''
echo ""
echo -e "''${BLUE}==============================================''${NOCOLOR}"
echo -e "''${BLUE} Nix Flake Development Environment Initializer''${NOCOLOR}"
echo -e "''${BLUE}==============================================''${NOCOLOR}"
echo ""
print_header() {
echo ""
echo -e "''${BLUE}==============================================''${NOCOLOR}"
echo -e "''${BLUE} Nix Flake Development Environment Initializer''${NOCOLOR}"
echo -e "''${BLUE}==============================================''${NOCOLOR}"
echo ""
}
'';
print_success = ''
echo -e "''${GREEN}[OK]''${NOCOLOR} $1"
print_success() {
echo -e "''${GREEN}[OK]''${NOCOLOR} $1"
}
'';
print_error = ''
echo -e "''${RED}[ERR]''${NOCOLOR} $1"
print_error() {
echo -e "''${RED}[ERR]''${NOCOLOR} $1"
}
'';
print_info = ''
echo -e "''${YELLOW}[->]''${NOCOLOR} $1"
print_info() {
echo -e "''${YELLOW}[->]''${NOCOLOR} $1"
}
'';
}