From c7619161ac27e32f50edd76cf7f9434e7b1761f6 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Thu, 26 Sep 2019 13:20:21 +0200 Subject: pkgs/profpatsch/execlinebWithBuiltins: fix path amending Earlier, it would just append the execline bin path on every invocation, which would clobber the path on nested invocations. We (ab)use the fact that nix paths have a known hash to check whether it was already added before. --- pkgs/profpatsch/default.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pkgs/profpatsch/default.nix') diff --git a/pkgs/profpatsch/default.nix b/pkgs/profpatsch/default.nix index 69977fff..dc746c2e 100644 --- a/pkgs/profpatsch/default.nix +++ b/pkgs/profpatsch/default.nix @@ -5,11 +5,25 @@ let # wrapper for execlineb that doesn’t need the execline commands # in PATH to work (making them appear like “builtins”) + # TODO: upstream into nixpkgs + # TODO: the grep could be nicer execlineb-with-builtins = let eldir = "${pkgs.execline}/bin"; in pkgs.writeScriptBin "execlineb" '' #!${eldir}/execlineb -s0 + # appends the execlineb bin dir to PATH if not yet in PATH ${eldir}/define eldir ${eldir} + ''${eldir}/ifelse + { + # since this is nix, we can grep for the execline drv hash in PATH + # to see whether it’s already in there + ''${eldir}/pipeline + { ${pkgs.coreutils}/bin/printenv PATH } + ${pkgs.gnugrep}/bin/grep --quiet "${eldir}" + } + # it’s there already + { ''${eldir}/execlineb $@ } + # not there yet, add it ''${eldir}/importas oldpath PATH ''${eldir}/export PATH "''${eldir}:''${oldpath}" ''${eldir}/execlineb $@ -- cgit 1.4.1