Skip to content

Instantly share code, notes, and snippets.

@balsoft
Created September 1, 2021 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balsoft/96e5a2bafaa0e48b915394385a4282aa to your computer and use it in GitHub Desktop.
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
#!/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