#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
cd ../

format() {
  nix_file="${1}"
  diff <(nixfmt < "${nix_file}") "${nix_file}" || {
    echo "The file '${nix_file}' is unformatted. To fix it, run:"
    echo "  nixfmt ${nix_file}"
    exit 1
  }
}
export -f format

find . -type f -name '*.nix' -print0 | xargs -0 -I% bash -c "format %"
