Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't leave traces in the hook's environment #46

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: don't leave traces in the hook's environment
fixes: #45
  • Loading branch information
blaggacao committed Jul 30, 2022
commit 7bd72b0bbc7c64073a04a9d9ded608e81c15423a
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