packages/nix-which: init

This commit is contained in:
Primrose 2025-05-29 22:27:45 +02:00
parent c031e42fd2
commit 7dccaa90e5
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -0,0 +1,27 @@
{
writeShellApplication,
which,
lib,
}: let
# Use this to not pollute the PATH inside
# Otherwise nix-which which will be an edge case
whichExe = "${lib.getExe which}";
in
writeShellApplication {
name = "nix-which";
text = ''
if [ "$#" -ne 1 ]; then
echo "Must provide exactly one argument, the package to be dereferenced"
exit 1
fi
target="$1"
target="$(${whichExe} "$target")"
echo "==> $target"
while [ -L "$target" ]; do
target="$(readlink "$target")"
echo "==> $target"
done
'';
}