mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
Fix nix-direnv-reload
No longer assumes location of layout directory relative to code.
This commit is contained in:
parent
62921f8e95
commit
f452533db5
1 changed files with 27 additions and 9 deletions
36
direnvrc
36
direnvrc
|
|
@ -37,16 +37,34 @@ _nix_direnv_preflight () {
|
||||||
if [[ ! -d "$layout_dir/bin" ]]; then
|
if [[ ! -d "$layout_dir/bin" ]]; then
|
||||||
mkdir -p "$layout_dir/bin"
|
mkdir -p "$layout_dir/bin"
|
||||||
fi
|
fi
|
||||||
|
# N.B. This script relies on variable expansion in *this* shell.
|
||||||
|
# (i.e. The written out file will have the variables expanded)
|
||||||
|
# If the source path changes, the script becomes broken.
|
||||||
|
# Because direnv_layout_dir is user controlled,
|
||||||
|
# we can't assume to be able to reverse it to get the source dir
|
||||||
|
# So there's little to be done about this.
|
||||||
|
cat > "${layout_dir}/bin/nix-direnv-reload" <<-EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
if [[ ! -d "$PWD" ]]; then
|
||||||
|
echo "Cannot find source directory; Did you move it?"
|
||||||
|
echo "(Looking for "$PWD")"
|
||||||
|
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# rebuild the cache forcefully
|
||||||
|
_nix_direnv_force_reload=1 direnv exec "$PWD" true
|
||||||
|
|
||||||
|
# Update the mtime for .envrc.
|
||||||
|
# This will cause direnv to reload again - but without re-building.
|
||||||
|
touch "$PWD/.envrc"
|
||||||
|
|
||||||
|
# Also update the timestamp of whatever profile_rc we have.
|
||||||
|
# This makes sure that we know we are up to date.
|
||||||
|
touch -r "$PWD/.envrc" ${layout_dir}/*.rc
|
||||||
|
EOF
|
||||||
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
echo > "${layout_dir}/bin/nix-direnv-reload" '#!/usr/bin/env bash
|
|
||||||
dir="$(realpath $(dirname ${BASH_SOURCE[0]})/../..)"
|
|
||||||
_nix_direnv_force_reload=1 direnv exec "$dir" true
|
|
||||||
direnv reload
|
|
||||||
# direnv reload updates the mtime of .envrc. Also update the timestamp of the
|
|
||||||
# profile_rc file to keep track that we actually are up to date.
|
|
||||||
touch $dir/.direnv/{nix,flake}-profile-*.rc
|
|
||||||
'
|
|
||||||
if [[ ! -x "${layout_dir}/bin/nix-direnv-reload" ]]; then
|
if [[ ! -x "${layout_dir}/bin/nix-direnv-reload" ]]; then
|
||||||
chmod +x "${layout_dir}/bin/nix-direnv-reload"
|
chmod +x "${layout_dir}/bin/nix-direnv-reload"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue