direnv_layout_dir is actually a function

This commit is contained in:
Jörg Thalheim 2020-04-10 13:36:45 +01:00
parent ae191f0cd4
commit a95abd152a
No known key found for this signature in database
GPG key ID: 003F2096411B5F92

View file

@ -1,10 +1,9 @@
# shellcheck shell=bash # shellcheck shell=bash
: "${direnv_layout_dir:=.direnv}"
use_nix() { use_nix() {
local path local path direnv_dir
path="$(nix-instantiate --find-file nixpkgs)" path=$(nix-instantiate --find-file nixpkgs)
direnv_dir=$(direnv_layout_dir)
if [[ "${direnv:-}" == "" ]]; then if [[ "${direnv:-}" == "" ]]; then
log_status "\$direnv environment variable was not defined. Was this script run inside direnv?" log_status "\$direnv environment variable was not defined. Was this script run inside direnv?"
@ -24,7 +23,7 @@ use_nix() {
fi fi
fi fi
local cache="${direnv_layout_dir}/cache-${version:-unknown}" local cache="$direnv_dir/cache-${version:-unknown}"
local update_drv=0 local update_drv=0
if [[ ! -e "$cache" ]] || \ if [[ ! -e "$cache" ]] || \
@ -33,7 +32,7 @@ use_nix() {
[[ default.nix -nt "$cache" ]] || \ [[ default.nix -nt "$cache" ]] || \
[[ shell.nix -nt "$cache" ]]; [[ shell.nix -nt "$cache" ]];
then then
[[ -d "${direnv_layout_dir}" ]] || mkdir "${direnv_layout_dir}" [[ -d "$direnv_dir" ]] || mkdir "$direnv_dir"
local dump_cmd tmp local dump_cmd tmp
dump_cmd="echo -n _____direnv_____; \"$direnv\" dump bash" dump_cmd="echo -n _____direnv_____; \"$direnv\" dump bash"
tmp=$(nix-shell --show-trace --pure "$@" --run "$dump_cmd" \ tmp=$(nix-shell --show-trace --pure "$@" --run "$dump_cmd" \
@ -79,7 +78,7 @@ use_nix() {
# This part is based on https://discourse.nixos.org/t/what-is-the-best-dev-workflow-around-nix-shell/418/4 # 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 if [[ "${out:-}" != "" ]] && (( update_drv )); then
local drv_link="${direnv_layout_dir}/drv" drv local drv_link="${direnv_dir}/drv" drv
drv=$(nix show-derivation "$out" | grep -E -o -m1 '/nix/store/.*.drv') drv=$(nix show-derivation "$out" | grep -E -o -m1 '/nix/store/.*.drv')
local stripped_pwd=${PWD/\//} local stripped_pwd=${PWD/\//}
local escaped_pwd=${stripped_pwd//-/--} local escaped_pwd=${stripped_pwd//-/--}