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