Skip to content

Commit

Permalink
fix: don't leave traces in the hook's environment (#46)
Browse files Browse the repository at this point in the history
fixes: #45
  • Loading branch information
blaggacao committed Jul 30, 2022
1 parent e157f2e commit 21272c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
21 changes: 15 additions & 6 deletions lib/hooks/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ pkgs, lib }:
{ name, configFile, hookConfig }:
with pkgs.lib;
let
# Common contains shared code across hooks
common = import ./common.nix;
Expand All @@ -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
'';
}
19 changes: 17 additions & 2 deletions lib/make_all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 21272c3

Please sign in to comment.