Created
September 1, 2021 14:56
-
-
Save balsoft/96e5a2bafaa0e48b915394385a4282aa to your computer and use it in GitHub Desktop.
Semi-automatically patchelf a binary to run on NixOS, allowing the user to choose the right packages with dmenu
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 nix-shell | |
#!nix-shell -p coreutils nix-index patchelf dmenu -i bash | |
file=$1 | |
patchelf --set-interpreter `nix-build --no-out-link "<nixpkgs>" -A glibc`/bin/ld-linux-x86-64.so.2 $file | |
rpath=$(ldd $file | sed -r "/^$/d" | cut -f1 -d' ' | cut -f2 | xargs -L 1 sh -c "nix-locate \$0 | dmenu -l 40 | awk '{print \$4;}' | xargs -L 1 dirname" | tr "\n" ":") | |
echo $rpath | |
patchelf --set-rpath $rpath $file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment