#!/usr/bin/env bash
# example usage:
#     $ tools nix package_path_for 'glib'
#     >>> /nix/store/dcb3cyba5wl6qimv6vwdpbi0kg0g1nlb-glib-2.68.2/lib

output=""
# check if file exists
if [ -f "$__FORNIX_NIX_PATH_EXPORT_FILE" ]
then
    # the sed part just removes the quotes
    output="$(cat "$__FORNIX_NIX_PATH_EXPORT_FILE" | jq ".packagePathFor.\"$1\"" | sed -E 's/^"|"$//g')"
fi 

if [ -z "$output" ]
then
    echo "" 1>&2
    echo "there was an issue when calling:" 1>&2
    echo "    nix package_path_for $1" 1>&2
    echo "it is possible that package doesnt exist inside of this file: $__FORNIX_NIX_PATH_EXPORT_FILE" 1>&2
    echo "(which is autogenerated based on system_tools.toml)" 1>&2
    echo "" 1>&2
else
    printf '%s' "$output"
fi