about summary refs log tree commit diff
path: root/pkgs/profpatsch
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2019-09-26 13:20:21 +0200
committerProfpatsch <mail@profpatsch.de>2019-09-26 13:20:21 +0200
commitc7619161ac27e32f50edd76cf7f9434e7b1761f6 (patch)
tree9369548293847c65d6ac0be8e8cc837fc4c0a000 /pkgs/profpatsch
parent93f5d251eaf7d2944d542281ae6e54ccfa306fd0 (diff)
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.
Diffstat (limited to 'pkgs/profpatsch')
-rw-r--r--pkgs/profpatsch/default.nix14
1 files changed, 14 insertions, 0 deletions
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 $@