refactor(nix/lazy-deps): use runCommand
writeTextFile is nice, but not flexible enough to allow the passthru argument needed for a follow-up change. Change-Id: I4f0cffd0f29b2c06b0155101d3806c9c5745c37a Reviewed-on: https://cl.tvl.fyi/c/depot/+/5854 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
71174f6626
commit
99030d10ce
1 changed files with 37 additions and 29 deletions
|
@ -38,38 +38,46 @@ in
|
||||||
# derivation.
|
# derivation.
|
||||||
tools:
|
tools:
|
||||||
|
|
||||||
pkgs.writeTextFile {
|
let
|
||||||
name = "lazy-dispatch";
|
self = pkgs.runCommandNoCC "lazy-dispatch"
|
||||||
executable = true;
|
{
|
||||||
destination = "/bin/__dispatch";
|
text = ''
|
||||||
|
#!${pkgs.runtimeShell}
|
||||||
|
set -ue
|
||||||
|
|
||||||
text = ''
|
if ! type git>/dev/null || ! type nix-build>/dev/null; then
|
||||||
#!${pkgs.runtimeShell}
|
echo "The 'git' and 'nix-build' commands must be available." >&2
|
||||||
set -ue
|
exit 127
|
||||||
|
fi
|
||||||
|
|
||||||
if ! type git>/dev/null || ! type nix-build>/dev/null; then
|
readonly REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||||
echo "The 'git' and 'nix-build' commands must be available." >&2
|
TARGET_TOOL=$(basename "$0")
|
||||||
exit 127
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly REPO_ROOT=$(git rev-parse --show-toplevel)
|
case "''${TARGET_TOOL}" in
|
||||||
TARGET_TOOL=$(basename "$0")
|
${invocations tools}
|
||||||
|
*)
|
||||||
|
echo "''${TARGET_TOOL} is currently not installed in this repository." >&2
|
||||||
|
exit 127
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case "''${TARGET_TOOL}" in
|
result=$(nix-build --no-out-link --attr "''${attr}" "''${REPO_ROOT}")
|
||||||
${invocations tools}
|
PATH="''${result}/bin:$PATH"
|
||||||
*)
|
exec "''${TARGET_TOOL}" "''${@}"
|
||||||
echo "''${TARGET_TOOL} is currently not installed in this repository." >&2
|
'';
|
||||||
exit 127
|
}
|
||||||
;;
|
''
|
||||||
esac
|
# Write the dispatch code
|
||||||
|
target=$out/bin/__dispatch
|
||||||
|
mkdir -p "$(dirname "$target")"
|
||||||
|
echo "$text" > $target
|
||||||
|
chmod +x $target
|
||||||
|
|
||||||
result=$(nix-build --no-out-link --attr "''${attr}" "''${REPO_ROOT}")
|
# Add symlinks from all the tools to the dispatch
|
||||||
PATH="''${result}/bin:$PATH"
|
${concatStringsSep "\n" (map link (attrNames tools))}
|
||||||
exec "''${TARGET_TOOL}" "''${@}"
|
|
||||||
'';
|
|
||||||
|
|
||||||
checkPhase = ''
|
# Check that it's working-ish
|
||||||
${pkgs.stdenv.shellDryRun} "$target"
|
${pkgs.stdenv.shellDryRun} $target
|
||||||
${concatStringsSep "\n" (map link (attrNames tools))}
|
'';
|
||||||
'';
|
in
|
||||||
}
|
self
|
||||||
|
|
Loading…
Reference in a new issue