From 7bd72b0bbc7c64073a04a9d9ded608e81c15423a Mon Sep 17 00:00:00 2001 From: David Arnold Date: Fri, 29 Jul 2022 22:18:20 -0500 Subject: [PATCH] fix: don't leave traces in the hook's environment fixes: #45 --- lib/hooks/default.nix | 21 +++++++++++++++------ lib/make_all.nix | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/hooks/default.nix b/lib/hooks/default.nix index 2e001e9..2725c3a 100644 --- a/lib/hooks/default.nix +++ b/lib/hooks/default.nix @@ -1,5 +1,6 @@ { pkgs, lib }: { name, configFile, hookConfig }: +with pkgs.lib; let # Common contains shared code across hooks common = import ./common.nix; @@ -10,16 +11,24 @@ let # Use writeShellScript for integrated error checking shellScript = pkgs.writeShellScript "nixago_${name}_hook" hook; + + prefixStringLines = prefix: str: + concatMapStringsSep "\n" (line: prefix + line) (splitString "\n" str); + indent = prefixStringLines " "; in { inherit shellScript; shellHook = '' - # Common shell code - ${common} + nixago() ( + # Common shell code + ${indent common} - # Enable tracing if NIXAGO_TRACE==1 - run_if_trace set -x - source ${shellScript} - run_if_trace set +x + # Enable tracing if NIXAGO_TRACE==1 + run_if_trace set -x + source ${shellScript} + run_if_trace set +x + ) + nixago + unset -f nixago ''; } diff --git a/lib/make_all.nix b/lib/make_all.nix index 50b70bd..c76f898 100644 --- a/lib/make_all.nix +++ b/lib/make_all.nix @@ -6,10 +6,25 @@ with pkgs.lib; let result = builtins.map lib.make all; + prefixStringLines = prefix: str: + concatMapStringsSep "\n" (line: prefix + line) (splitString "\n" str); + indent = prefixStringLines " "; + # Only include common shell code once common = (import ./hooks/common.nix); - shellHook = common + "\nsource " + - (concatStringsSep "\nsource " (catAttrs "shellScript" result)); + shellHook = '' + nixago() ( + # Common shell code + ${indent common} + + # Enable tracing if NIXAGO_TRACE==1 + run_if_trace set -x + source ${concatStringsSep "\n source " (catAttrs "shellScript" result)} + run_if_trace set +x + ) + nixago + unset -f nixago + ''; in { inherit shellHook;