Merge pull request #85 from nix-community/revert-async-nix-shell

Revert "async nix-shell"
This commit is contained in:
Jörg Thalheim 2021-05-14 07:44:20 +01:00 committed by GitHub
commit f6fd4a4d48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -130,6 +130,21 @@ use_flake() {
export XDG_DATA_DIRS=$XDG_DATA_DIRS${old_xdg_data_dirs:+":"}$old_xdg_data_dirs
}
_nix_extract_direnv() {
local found_direnv
found_direnv=0
while read -r line; do
if [[ "$found_direnv" == "1" ]]; then
echo "$line"
break
elif [[ "$line" == "_____direnv_____" ]]; then
found_direnv=1
else
echo "$line" >&2
fi
done
}
use_nix() {
local path layout_dir
path=$("${NIX_BIN_PREFIX}nix-instantiate" --find-file nixpkgs)
@ -164,6 +179,7 @@ use_nix() {
local cache="${layout_dir}/cache-${version:-unknown}"
local update_drv=0
if [[ ! -e "$cache"
|| "$HOME/.direnvrc" -nt "$cache"
|| .envrc -nt "$cache"
@ -172,49 +188,30 @@ use_nix() {
]];
then
[[ -d "$layout_dir" ]] || mkdir -p "$layout_dir"
bash -c '
cache=$1
shift
direnv=$1
shift
_nix_extract_direnv() {
local found_direnv
found_direnv=0
while read -r line; do
if [[ "$found_direnv" == "1" ]]; then
echo "$line"
break
elif [[ "$line" == "_____direnv_____" ]]; then
found_direnv=1
else
echo "$line" >&2
fi
done
}
dump_cmd="echo _____direnv_____; $direnv dump bash"
tmp=$("${NIX_BIN_PREFIX}nix-shell" \
"${experimental_flags[@]}" \
--show-trace --pure "$@" --run "$dump_cmd")
# show original shell hook output
echo "$tmp" | _nix_extract_direnv >&2 > "$cache"
# retrigger direnv
[[ -f .envrc ]] && touch .envrc
' -- "$cache" "$direnv" "$@" 3>- &
echo "renew cache in background"
local dump_cmd tmp
dump_cmd="echo _____direnv_____; \"$direnv\" dump bash"
tmp=$("${NIX_BIN_PREFIX}nix-shell" \
"${experimental_flags[@]}" \
--show-trace --pure "$@" --run "$dump_cmd")
# show original shell hook output
echo "$tmp" | _nix_extract_direnv >&2 > "$cache"
update_drv=1
else
log_status eval "$cache"
read -r cache_content < "$cache"
_nix_import_env "$cache_content"
log_status using cached derivation
fi
# This part is based on https://discourse.nixos.org/t/what-is-the-best-dev-workflow-around-nix-shell/418/4
if [[ "${out:-}" != "" ]]; then
local drv_link="${layout_dir}/drv" drv
drv=$("${NIX_BIN_PREFIX}nix" show-derivation "$out" \
"${experimental_flags[@]}" \
| grep -E -o -m1 '/nix/store/.*.drv')
_nix_add_gcroot "$drv" "$drv_link"
log_status update derivation link
fi
log_status eval "$cache"
read -r cache_content < "$cache"
_nix_import_env "$cache_content"
# This part is based on https://discourse.nixos.org/t/what-is-the-best-dev-workflow-around-nix-shell/418/4
if [[ "${out:-}" != "" ]] && (( update_drv )); then
local drv_link="${layout_dir}/drv" drv
drv=$("${NIX_BIN_PREFIX}nix" show-derivation "$out" \
"${experimental_flags[@]}" \
| grep -E -o -m1 '/nix/store/.*.drv')
_nix_add_gcroot "$drv" "$drv_link"
log_status renewed cache and derivation link
fi
if [[ "$#" == 0 ]]; then