#!/usr/bin/env bash # # Pre-push hook: Validate builds # # This hook attempts to build the ops-jrz1 configuration # to ensure it's valid before pushing to remote. set -euo pipefail # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # Get repository root REPO_ROOT="$(git rev-parse --show-toplevel)" echo "==> Running build validation..." # Check if flake.nix exists if [ ! -f "$REPO_ROOT/flake.nix" ]; then echo -e "${YELLOW}⚠ WARNING: flake.nix not found, skipping build validation${NC}" exit 0 fi # Try to build ops-jrz1 configuration if nix build "$REPO_ROOT#nixosConfigurations.ops-jrz1.config.system.build.toplevel" --no-link --show-trace 2>&1 | head -20; then echo -e "${GREEN}✓ Build validation passed${NC}" exit 0 else echo -e "${RED}✗ Build validation failed${NC}" echo "" echo "Push blocked. Please fix the build errors and try again." echo "Debug with: nix build .#nixosConfigurations.ops-jrz1 --show-trace" exit 1 fi