Created
April 22, 2025 06:59
-
-
Save gabyx/6df210f3f67ea24ca826697a0c6cb845 to your computer and use it in GitHub Desktop.
Check Nix paths in executable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
anaylze-binary.sh "$(nix build -L "<installable>" --print-out-paths)/bin/<your-exe-name>" --with-strings