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:
parent
c31a0b552b
commit
892493a478
3 changed files with 36 additions and 0 deletions
4
.envrc
Normal file
4
.envrc
Normal 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
31
tools/bin/__dispatch.sh
Executable 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
1
tools/bin/git-appraise
Symbolic link
|
@ -0,0 +1 @@
|
|||
__dispatch.sh
|
Loading…
Reference in a new issue