lean4-htt/nix/lean-dev.in
Sebastian Ullrich 23b0e6ca5b fix: Nix: use stage 1 outside of src/
Hopefully we can solve this using a src/flake.nix as soon as relative flake inputs are supported
2020-12-03 18:49:29 +01:00

50 lines
1.3 KiB
Bash

#!@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\": \"<stdin>\", \"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"
# HACK: use stage 0 instead of 0 inside Lean's own `src/`
[[ -d "$root/src/Lean" && "$inputFile" == "$root/src/"* ]] && attrPath="stage0check-mod"
for dep in $deps; do
attrPath="$attrPath.\"$dep\""
done
echo -n "$input" | call nix run "$root#$attrPath" -- "$@"