mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-12-03 07:31:10 +01:00
Merge pull request #64 from nix-community/fixes
This commit is contained in:
commit
52802adf85
2 changed files with 23 additions and 6 deletions
|
|
@ -7,8 +7,8 @@ stdenv.mkDerivation {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
postPatch = ''
|
postPatch = ''
|
||||||
|
sed -i "2iNIX_BIN_PREFIX=${nixFlakes}/bin/" direnvrc
|
||||||
substituteInPlace direnvrc \
|
substituteInPlace direnvrc \
|
||||||
--replace "\''${NIX_BIN_PREFIX:-}" "\''${NIX_BIN_PREFIX:-${nixFlakes}/bin/}" \
|
|
||||||
--replace "grep" "${gnugrep}/bin/grep"
|
--replace "grep" "${gnugrep}/bin/grep"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
|
||||||
27
direnvrc
27
direnvrc
|
|
@ -1,6 +1,9 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
NIX_BIN_PREFIX=${NIX_BIN_PREFIX:-}
|
if [[ -z ${NIX_BIN_PREFIX:-} ]]; then
|
||||||
|
NIX_BIN_PREFIX=$(command -v nix-shell)
|
||||||
|
NIX_BIN_PREFIX="${NIX_BIN_PREFIX%/*}/"
|
||||||
|
fi
|
||||||
|
|
||||||
_nix_export_or_unset() {
|
_nix_export_or_unset() {
|
||||||
local key=$1 value=$2
|
local key=$1 value=$2
|
||||||
|
|
@ -118,12 +121,27 @@ use_flake() {
|
||||||
_nix_export_or_unset TEMPDIR "$old_tempdir"
|
_nix_export_or_unset TEMPDIR "$old_tempdir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_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)
|
||||||
layout_dir=$(direnv_layout_dir)
|
layout_dir=$(direnv_layout_dir)
|
||||||
local experimental_flags=()
|
local experimental_flags=()
|
||||||
if nix-shell --experimental-features '' --version 2>/dev/null >&2; then
|
if "${NIX_BIN_PREFIX}nix-shell" --experimental-features '' --version 2>/dev/null >&2; then
|
||||||
experimental_flags+=('--experimental-features' 'nix-command flakes')
|
experimental_flags+=('--experimental-features' 'nix-command flakes')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -157,13 +175,12 @@ use_nix() {
|
||||||
then
|
then
|
||||||
[[ -d "$layout_dir" ]] || mkdir -p "$layout_dir"
|
[[ -d "$layout_dir" ]] || mkdir -p "$layout_dir"
|
||||||
local dump_cmd tmp
|
local dump_cmd tmp
|
||||||
dump_cmd="echo -n _____direnv_____; \"$direnv\" dump bash"
|
dump_cmd="echo _____direnv_____; \"$direnv\" dump bash"
|
||||||
tmp=$("${NIX_BIN_PREFIX}nix-shell" \
|
tmp=$("${NIX_BIN_PREFIX}nix-shell" \
|
||||||
"${experimental_flags[@]}" \
|
"${experimental_flags[@]}" \
|
||||||
--show-trace --pure "$@" --run "$dump_cmd")
|
--show-trace --pure "$@" --run "$dump_cmd")
|
||||||
# show original shell hook output
|
# show original shell hook output
|
||||||
echo "$tmp" | grep -vP '(?<=_____direnv_____).*'
|
echo "$tmp" | _nix_extract_direnv >&2 > "$cache"
|
||||||
echo "$tmp" | grep -oP '(?<=_____direnv_____).*' > "$cache"
|
|
||||||
update_drv=1
|
update_drv=1
|
||||||
else
|
else
|
||||||
log_status using cached derivation
|
log_status using cached derivation
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue