#!/usr/bin/env bash # # Pre-push hook: Run nix flake check # # This hook validates that the flake configuration is valid # and all checks pass 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 nix flake check..." # Check if flake.nix exists if [ ! -f "$REPO_ROOT/flake.nix" ]; then echo -e "${YELLOW}⚠ WARNING: flake.nix not found, skipping nix flake check${NC}" exit 0 fi # Run nix flake check if nix flake check "$REPO_ROOT" --show-trace 2>&1; then echo -e "${GREEN}✓ nix flake check passed${NC}" exit 0 else echo -e "${RED}✗ nix flake check failed${NC}" echo "" echo "Push blocked. Please fix the flake errors and try again." echo "Debug with: nix flake check --show-trace" exit 1 fi