Move realpath into a function

Using ls to resolve the path does not work if the next level is also a symlink
This commit is contained in:
Bryan Bennett 2022-04-03 20:20:09 -04:00
parent 7133709885
commit deb345be82
No known key found for this signature in database
GPG key ID: EF90E3E98B8F5C0B

View file

@ -68,6 +68,13 @@ if [[ -z ${NIX_BIN_PREFIX:-} ]]; then
NIX_BIN_PREFIX=$(command -v nix-shell)
NIX_BIN_PREFIX="${NIX_BIN_PREFIX%/*}/"
fi
_nix_direnv_realpath () {
if has realpath; then
realpath "$1"
else
perl -e 'use Cwd "abs_path";print abs_path(shift)' "$1"
fi
}
_nix_export_or_unset() {
local key=$1 value=$2
@ -191,6 +198,8 @@ use_flake() {
drv=$(ls -dl "$tmp_profile")
drv=${tmp_profile#*-> }
local drv
drv=$(_nix_direnv_realpath "$tmp_profile")
echo "$tmp_profile_rc" > "$profile_rc"
rm -f "$tmp_profile" "$tmp_profile"*
@ -318,6 +327,8 @@ use_nix() {
# show original shell hook output
echo "$tmp" | _nix_extract_direnv >&2 > "$cache"
update_drv=1
local drv
drv=$(_nix_direnv_realpath "$tmp_profile")
else
log_status using cached derivation
fi