From d81d591d13df3d609b8fa05695882edce3a91244 Mon Sep 17 00:00:00 2001 From: Andreas Schmid Date: Sun, 28 Feb 2021 08:30:34 +0100 Subject: [PATCH] nix-direnv: fix NIX_BIN_PREFIX substitution in built direnvrc * Reason: statically set `${NIX_BIN_PREFIX}` within generated `direnvrc`. * Before it only replaced the `-z ${NIX_BIN_PREFIX:-}` check which therefore never was `true`. So, also `NIX_BIN_PREFIX` never got set such that its usage later always failed execution with `NIX_BIN_PREFIX: unbound variable`. With the fix, the line containing the check will no longer be replaced. * Solves https://github.com/nix-community/nix-direnv/issues/70 * See also discussion on #114622 Signed-off-by: Andreas Schmid --- pkgs/tools/misc/nix-direnv/default.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkgs/tools/misc/nix-direnv/default.nix b/pkgs/tools/misc/nix-direnv/default.nix index 833f8313f61..3fe8e3f3870 100644 --- a/pkgs/tools/misc/nix-direnv/default.nix +++ b/pkgs/tools/misc/nix-direnv/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, gnugrep, nix }: +{ lib, stdenv, fetchFromGitHub, gnugrep, nix, nixFlakes }: stdenv.mkDerivation rec { pname = "nix-direnv"; @@ -14,9 +14,8 @@ stdenv.mkDerivation rec { # Substitute instead of wrapping because the resulting file is # getting sourced, not executed: postPatch = '' - substituteInPlace direnvrc \ - --replace "\''${NIX_BIN_PREFIX:-}" "\''${NIX_BIN_PREFIX:-${nix}/bin/}" \ - --replace "grep" "${gnugrep}/bin/grep" + sed -i "1a NIX_BIN_PREFIX=${nixFlakes}/bin/" direnvrc + substituteInPlace direnvrc --replace "grep" "${gnugrep}/bin/grep" ''; installPhase = ''