tvl-depot/tools/bin/__dispatch.sh
Vincent Ambo 892493a478 feat(tools): Add dispatcher script to transparently access tools
Initial version of tool provider via Nix. This requires two separate
steps for adding a new tool:

1. New symlink in tools/bin to point at the dispatch script.
2. Mapping of tool to Nix package set attribute in dispatch script.
2019-07-02 16:40:51 +01:00

31 lines
707 B
Bash
Executable file

#!/usr/bin/env bash
# This script dispatches invocations transparently to programs instantiated from
# Nix.
#
# To add a new tool, in
set -ueo pipefail
readonly REPO_ROOT=$(git rev-parse --show-toplevel)
readonly ARGS="$@"
readonly TARGET_TOOL=$(basename $0)
function nix_dispatch() {
local attr="${1}"
local result=$(nix-build --no-out-link --attr "${attr}" "${REPO_ROOT}")
PATH="${result}/bin:$PATH"
if [ -z "${ARGS}" ]; then
exec "${TARGET_TOOL}"
else
exec "${TARGET_TOOL}" "${ARGS}"
fi
}
case "${TARGET_TOOL}" in
git-appraise)
nix_dispatch "thirdParty.gitAppraise"
;;
*)
echo "The tool '${TARGET_TOOL}' is currently not installed in this repository."
;;
esac