.files/nix/packages/by-name/nix-which/package.nix

27 lines
598 B
Nix

{
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
'';
}