#!@bash@/bin/bash set -euo pipefail PATH=@nix@/bin:$PATH call() { if [[ $json == 1 ]]; then $@ 2>&1 | awk ' /{/ { print $0; next } # Hide some Nix warnings. You will still see them with `nix build` etc., but they are pretty annoying in the editor. /warning: ignoring/ { next } { gsub(/"/, "\\\"", $0); gsub(/\n/, "\\n", $0); printf "{\"severity\": \"error\", \"pos_line\": 0, \"pos_col\": 0, \"file_name\": \"\", \"text\": \"%s\"}\n", $0 }' else $@ fi } json=0 input= inputFile= for p in "$@"; do case "$p" in --json) json=1;; --stdin) input="$(< /dev/stdin)";; -*) ;; *) inputFile="$p";; esac done if [[ -z "$input" && -f "$inputFile" ]]; then input="$(< "$inputFile")" fi # find package root of input file root="$(dirname "${inputFile:-/}")" while [[ "$root" != / ]]; do [ -f "$root/flake.nix" ] && break root="$(realpath "$root/..")" done # fall back to current package [[ "$root" == / ]] && root="@srcRoot@" deps="$(echo -n "$input" | nix run "$root#print-lean-deps" 2> /dev/null)" attrPath="check-mod" for dep in $deps; do attrPath="$attrPath.\"$dep\"" done echo -n "$input" | call nix run "$root#$attrPath" -- "$@"