Skip to content

Instantly share code, notes, and snippets.

@gabyx
Created April 22, 2025 06:59
Show Gist options
  • Save gabyx/6df210f3f67ea24ca826697a0c6cb845 to your computer and use it in GitHub Desktop.
Save gabyx/6df210f3f67ea24ca826697a0c6cb845 to your computer and use it in GitHub Desktop.
Check Nix paths in executable
#!/usr/bin/env bash
set -eu
binary="$1"
with_strings="${2:-}"
strings=$(strings "$binary")
linking=$(ldd "$binary")
rpaths=$(readelf -d "$binary")
rpaths2=$(objdump -x "$binary")
rpaths3=$(patchelf --print-rpath "$binary")
echo ">>> RPATHS:"
echo "$rpaths3" | tr ':' '\n' | xargs printf "- '%s'\n"
echo ">>> All found /nix/store..."
{
echo "Strings ================"
[ "$with_strings" = "--with-strings" ] && echo "$strings"
echo "======================="
echo "Linking"
echo "$linking"
echo "======================="
echo "RPATHS etc"
echo "$rpaths"
echo "$rpaths2"
echo "$rpaths3"
echo "======================="
} | grep -o -P '/nix/store/[\w\.-]+\b' | sort -u
if echo "$binary" | grep -q "/nix/store"; then
echo ">>> Nix reported dependencies"
nix path-info --recursive "$binary"
fi
read -rp "Do you want to open nix-tree? (yes/no): " answer
case "$answer" in
[Yy][Ee][Ss] | [Yy])
nix-tree "$binary"
;;
*) ;;
esac
@gabyx
Copy link
Author

gabyx commented Apr 22, 2025

Usage:

anaylze-binary.sh "$(nix build -L "<installable>" --print-out-paths)/bin/<your-exe-name>" --with-strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment