Skip to content

Commit

Permalink
feat: factorize shell scripts so that they can be composed more freely (
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jul 26, 2022
1 parent c893573 commit dd3c333
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
make = import ./make.nix { inherit pkgs lib; };
makeAll = import ./make_all.nix { inherit pkgs lib; };
makeHook = import ./hooks { inherit pkgs lib; };
commonHook = import ./hooks/common.nix;
}
21 changes: 12 additions & 9 deletions lib/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ let
# Use writeShellScript for integrated error checking
shellScript = pkgs.writeShellScript "nixago_${name}_hook" hook;
in
''
# Common shell code
${common}
# Enable tracing if NIXAGO_TRACE==1
run_if_trace set -x
source ${shellScript}
run_if_trace set +x
''
{
inherit shellScript;
shellHook = ''
# Common shell code
${common}
# Enable tracing if NIXAGO_TRACE==1
run_if_trace set -x
source ${shellScript}
run_if_trace set +x
'';
}
5 changes: 2 additions & 3 deletions lib/make.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ let
};

# Builds the shell hook for managing the generated file.
shellHook =
lib.makeHook { inherit configFile name hookConfig; };
inherit (lib.makeHook { inherit configFile name hookConfig; }) shellHook shellScript;
in
{
inherit configFile shellHook;
inherit configFile shellHook shellScript;
}
7 changes: 3 additions & 4 deletions lib/make_all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ let

# Only include common shell code once
common = (import ./hooks/common.nix);
shellHook = common + "\n" +
builtins.replaceStrings [ common ] [ "" ]
(concatStringsSep "\n"
(pkgs.lib.catAttrs "shellHook" result));
shellHook = common + "\nsource " +
(concatStringsSep "\nsource " (catAttrs "shellScript" result));
in
{
inherit shellHook;
scripts = catAttrs "shellScript" result;
configs = catAttrs "configFile" result;
}

0 comments on commit dd3c333

Please sign in to comment.