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 <service@aaschmid.de>
This commit is contained in:
Andreas Schmid 2021-02-28 08:30:34 +01:00
parent 7fd3356809
commit d81d591d13

View File

@ -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 = ''