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.
This commit is contained in:
Vincent Ambo 2019-07-02 16:40:51 +01:00
parent c31a0b552b
commit 892493a478
3 changed files with 36 additions and 0 deletions

4
.envrc Normal file
View file

@ -0,0 +1,4 @@
# Configure the local PATH to contain tools which are fetched ad-hoc
# from Nix.
export PATH="${PWD}/tools/bin:${PATH}"

31
tools/bin/__dispatch.sh Executable file
View file

@ -0,0 +1,31 @@
#!/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

1
tools/bin/git-appraise Symbolic link
View file

@ -0,0 +1 @@
__dispatch.sh