Skip to content

Commit

Permalink
drop dependency on jq
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Nov 26, 2023
1 parent 4248f77 commit 6366a95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
5 changes: 2 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, nix, gnugrep, gzip, jq, lib }:
{ stdenv, nix, gnugrep, lib }:

stdenv.mkDerivation {
name = "nix-direnv";
Expand All @@ -8,8 +8,7 @@ stdenv.mkDerivation {
postPatch = ''
sed -i "2iNIX_BIN_PREFIX=${nix}/bin/" direnvrc
substituteInPlace direnvrc \
--replace "grep" "${gnugrep}/bin/grep" \
--replace JQ= "JQ=${jq}/bin/jq"
--replace "grep" "${gnugrep}/bin/grep"
'';

installPhase = ''
Expand Down
35 changes: 14 additions & 21 deletions direnvrc
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,21 @@ nix_direnv_watch_file() {
watch_file "$@"
}

# set by nix build - see ./default.nix
JQ=

_jq() {
if [[ -n $JQ ]]; then
$JQ "$@"
elif has jq; then
jq "$@"
else
nix-shell --packages jq --run "$(join_args jq "$@")"
fi
}

_nix_direnv_watches() {
local -n _watches=$1
# allow files under $XDG_DATA_HOME/direnv/allow are filtered out as not relevant
mapfile -td "" _watches < <(
# shellcheck disable=2016
direnv show_dump "${DIRENV_WATCHES}" \
| _jq --join-output '.[] | select(.Exists ) | .Path | select(. | test($ENV.XDG_DATA_HOME + "/direnv/allow") | not) | (. + "\u0000")'
)
while IFS= read -r line; do
local regex='"path": "(.+)"$'
if [[ "$line" =~ $regex ]]; then
local path="${BASH_REMATCH[1]}"
if [[ "$path" == "$XDG_DATA_HOME/direnv/allow/"* ]]; then
continue
fi
# expand new lines and other json escapes
# shellcheck disable=2059
path=$(printf "$path")
_watches+=("$path")
fi
done < <(direnv show_dump "${DIRENV_WATCHES}")
}

_nix_direnv_manual_reload=0
Expand Down Expand Up @@ -477,7 +471,6 @@ use_nix() {


if [[ "$#" == 0 ]]; then
watch_file default.nix
watch_file shell.nix
watch_file default.nix shell.nix
fi
}

0 comments on commit 6366a95

Please sign in to comment.