How to set the value of $0 inside wrapped script when using makeWrapper/wrapProgram?

I’m trying to wrap an executable with makeWrapper or wrapProgram like:

wrapProgram $out/bin/the-exe <some_more_args>

My problem is that the program the-exe acts differently depending on the value of $0: there are different symlinks pointing to it, and depending on the symlink that is called, the value of $0 inside the-exe is equal to the symlink name… But when i use wrapProgram this way, the value of $0 is always $out/bin/.the-exe-wrapped, no matter what symlink I use to call the-exe. Is there a way to change the value of $0 as seen inside the-exe?

I know that makeWrapper has the option --argv0, but when I do

echo $0

inside the-exe, the value is always “$out/bin/.the-exe-wrapped” and not the value I passed to --argv0.

This is unfortunately a limitation of Linux. It discards passed argv[0] when executing a script with shebang – it will only apply to ELF programs.

Cannot find any reference to the behaviour other than at the moment.

In case of Python we use NIX_PYTHONEXECUTABLE and set sys.argv[0] to it in a

Maybe you can move the binaries and symlinks into another directory without changing the names, and use makeWrapper to create wrappers in /bin