Skip to content

Commit

Permalink
only set experimental features in old nix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Jan 2, 2021
1 parent 944585f commit 7faa010
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions direnvrc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ use_nix() {
local path layout_dir
path=$("${NIX_BIN_PREFIX}nix-instantiate" --find-file nixpkgs)
layout_dir=$(direnv_layout_dir)
local experimental_flags=()
if nix-shell --experimental-features '' --version 2>/dev/null; then
experimental_flags+=('--experimental-features' 'nix-command flakes')
fi

if [[ "${direnv:-}" == "" ]]; then
log_status "\$direnv environment variable was not defined. Was this script run inside direnv?"
Expand Down Expand Up @@ -155,7 +159,7 @@ use_nix() {
local dump_cmd tmp
dump_cmd="echo -n _____direnv_____; \"$direnv\" dump bash"
tmp=$("${NIX_BIN_PREFIX}nix-shell" \
--experimental-features "nix-command flakes" \
"${experimental_flags[@]}" \
--show-trace --pure "$@" --run "$dump_cmd")
# show original shell hook output
echo "$tmp" | grep -vP '(?<=_____direnv_____).*'
Expand All @@ -173,7 +177,7 @@ use_nix() {
if [[ "${out:-}" != "" ]] && (( update_drv )); then
local drv_link="${layout_dir}/drv" drv
drv=$("${NIX_BIN_PREFIX}nix" show-derivation "$out" \
--experimental-features "nix-command flakes" \
"${experimental_flags[@]}" \
| grep -E -o -m1 '/nix/store/.*.drv')
_nix_add_gcroot "$drv" "$drv_link"
log_status renewed cache and derivation link
Expand Down

0 comments on commit 7faa010

Please sign in to comment.