-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrapProgram & friends depend on linux kernel shebang feature #11133
Comments
wrapProgram
& friends depend on linux kernel shebang feature
wrapProgram
& friends depend on linux kernel shebang feature
👍 I can work on this if we agree... @edolstra ? I know you don't like wrappers, but... :) |
Related is In other words, originally
After
|
Related: #2146. I attempted to make patchShebangs change "/usr/bin/env prog" into "/nix/store/.../env /nix/store/.../prog", but that hit the default kernel shebang size limit. (See discussion in the mentioned issue.) |
Yeah, it would solve multiple issues at once. Still, we probably want a simple way of inspecting what the wrapper does – options off the top of my head:
|
@vcunat which is basically exec bash and source that file :) |
Yes, that wouldn't really change much from the current state. EDIT: ...except for fixing all those problems, of course. |
Thinking out loud:
Now, we could just use How does that sound? |
Whatever we do, I agree with @vcunat that we ought to have a way to inspect the flags used for a given wrapper. I've had cases where I would extend an existing package with an additional fixupPhase, use |
I just hit this issue as well. OS X seems to not mind the longer The one downside I can imagine for that approach is any derivation which uses patchShebangs on a script which itself uses a script interpreter (so, if (commenting here rather than #2146 as this discussion is more recent, but they seem like duplicate issues to me) |
Here is a (crappy) way to work around this issue: { stdenv, bundlerEnv}:
{
osxWrap = { name, script, bundlerEnvResult }: stdenv.mkDerivation {
inherit name;
buildCommand = ''
mkdir bin
sed \
-e "s#/bin/ruby #/bin/ruby ${script} #" \
${bundlerEnvResult.wrappedRuby}/bin/ruby > ./bin/${name}
mkdir -p $out/bin
install -D -m755 ./bin/${name} $out/bin/${name}
'';
};
neato-script = osxWrap {
name = "my-neato-script";
script = ./my-neato-script.rb;
bundlerEnvResult = bundlerEnv rec {
name = "my-neato-script-env";
inherit ruby;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
};
} Here is another crappy workaround, for not ruby scripts: let
rewrap = { name, script, interpreter }:
stdenv.mkDerivation {
inherit name;
# The normal bundler wrapper uses a script in a shebang. This works
# fine on Linux, but OSX's kernel doesn't permit this.
#
# This wrapper copies the wrappedRuby script, which ends in:
#
# exec /nix/store/.../bin/.foo-wrapped" "${extraFlagsArray[@]}" "$@"
#
# and adds the script between `bin/.foo-wrapped"` and `"${extraFlagsArray`:
#
# exec /nix/store/.../bin/.foo-wrapped" /nix/store/...-my-script "${extraFlagsArray[@]}" "$@"
# and since the wrapped script uses bash directly in the
# shebang (and not another script) this works on macOS and Linux.
buildCommand = ''
sed \
-e "s#-wrapped\" #-wrapped\" ${script} #" \
${interpreter} > ./working
if ! grep -q "${script}" ./working; then
echo " ABORTING:"
echo " sed appears to not have correctly added the script on"
echo " the exec line, which breaks this tool."
exit 1
fi
mkdir -p $out/bin
install -D -m755 ./working $out/bin/${name}
'';
};
in
rewrap {
name = "timeout";
script = ./timeout.tcl;
interpreter = "${expect}/bin/expect";
} |
Just ran into the same issue, a Python script got patchShebang'd to point to the python2.7 wrapper. On Darwin and Solaris, shebang cannot point to a script. On top of that, using custom shebangs adds changes to otherwise completely unchanged scripts, and it makes the store deduplication work less well. How about making a Then
|
Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:
|
On Darwin a script cannot be used as an interpreter in a shebang line, which causes scripts produced with makeScriptWriter (and its derivatives) to fail at run time if the used interpreter was wrapped with makeWrapper (as in the case of python3.withPackages). This commit fixes the problem by detecting if the interpreter is a script and prepending its shebang to the final interpreter line. For example if used interpreter is; ``` /nix/store/ynwv137n2650qy39swcflxbcygk5jwv1-python3-3.8.3-env/bin/python ``` which is a script with following shebang: ``` #! /nix/store/knd85yc7iwli8344ghav3zli8d9gril0-bash-4.4-p23/bin/bash -e ``` then the shebang line in the produced script will be ``` #! /nix/store/knd85yc7iwli8344ghav3zli8d9gril0-bash-4.4-p23/bin/bash -e /nix/store/ynwv137n2650qy39swcflxbcygk5jwv1-python3-3.8.3-env/bin/python ``` This works on Darwin since there does not seem to be a limit to the length of the shabang line and the shebang lines support multiple arguments to the interpreters (as opposed to linux where the kernel imposes a strict limit on shebang lengh and everything following the interpreter is passed to it as a single string). fixes; NixOS#93609 related to: NixOS#65351 NixOS#11133 (and probably a bunch of others) NOTE: scripts produced on platforms other tha Darwin will remain unmodified by this PR. However it might worth considering extending this fix to BSD systems in general. I didn't do it since I have no way of testing it on systems other than MacOS and linux.
* writers.makeScriptWriter: fix on Darwin\MacOS On Darwin a script cannot be used as an interpreter in a shebang line, which causes scripts produced with makeScriptWriter (and its derivatives) to fail at run time if the used interpreter was wrapped with makeWrapper (as in the case of python3.withPackages). This commit fixes the problem by detecting if the interpreter is a script and prepending its shebang to the final interpreter line. For example if used interpreter is; ``` /nix/store/ynwv137n2650qy39swcflxbcygk5jwv1-python3-3.8.3-env/bin/python ``` which is a script with following shebang: ``` #! /nix/store/knd85yc7iwli8344ghav3zli8d9gril0-bash-4.4-p23/bin/bash -e ``` then the shebang line in the produced script will be ``` #! /nix/store/knd85yc7iwli8344ghav3zli8d9gril0-bash-4.4-p23/bin/bash -e /nix/store/ynwv137n2650qy39swcflxbcygk5jwv1-python3-3.8.3-env/bin/python ``` This works on Darwin since there does not seem to be a limit to the length of the shabang line and the shebang lines support multiple arguments to the interpreters (as opposed to linux where the kernel imposes a strict limit on shebang lengh and everything following the interpreter is passed to it as a single string). fixes; #93609 related to: #65351 #11133 (and probably a bunch of others) NOTE: scripts produced on platforms other than Darwin will remain unmodified by this PR. However it might worth considering extending this fix to BSD systems in general. I didn't do it since I have no way of testing it on systems other than MacOS and linux. * writers.makeScriptWriter: fix typo in comment * writers.makeScriptWriter: fail build if interpreter of interpreter is a script
* writers.makeScriptWriter: fix on Darwin\MacOS On Darwin a script cannot be used as an interpreter in a shebang line, which causes scripts produced with makeScriptWriter (and its derivatives) to fail at run time if the used interpreter was wrapped with makeWrapper (as in the case of python3.withPackages). This commit fixes the problem by detecting if the interpreter is a script and prepending its shebang to the final interpreter line. For example if used interpreter is; ``` /nix/store/ynwv137n2650qy39swcflxbcygk5jwv1-python3-3.8.3-env/bin/python ``` which is a script with following shebang: ``` #! /nix/store/knd85yc7iwli8344ghav3zli8d9gril0-bash-4.4-p23/bin/bash -e ``` then the shebang line in the produced script will be ``` #! /nix/store/knd85yc7iwli8344ghav3zli8d9gril0-bash-4.4-p23/bin/bash -e /nix/store/ynwv137n2650qy39swcflxbcygk5jwv1-python3-3.8.3-env/bin/python ``` This works on Darwin since there does not seem to be a limit to the length of the shabang line and the shebang lines support multiple arguments to the interpreters (as opposed to linux where the kernel imposes a strict limit on shebang lengh and everything following the interpreter is passed to it as a single string). fixes; NixOS#93609 related to: NixOS#65351 NixOS#11133 (and probably a bunch of others) NOTE: scripts produced on platforms other than Darwin will remain unmodified by this PR. However it might worth considering extending this fix to BSD systems in general. I didn't do it since I have no way of testing it on systems other than MacOS and linux. * writers.makeScriptWriter: fix typo in comment * writers.makeScriptWriter: fail build if interpreter of interpreter is a script
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
Fixed by #124556 ? |
While trying to package JRuby as a more ruby like package, I discovered that OSX does not support shebangs at the kernel level.
Running
jruby
(which is a bash script that starts java) works fine on any unix.Trying to run
gem
which hasjruby
in it's shebang:And apparantly bash has a fallback mode where it interprets the script as a bash script:
More details:
Suggested fix
If jruby were a binary, it would probably work fine. Maybe
wrapProgram
can generate and compile a tiny C program that runs the wrapped script.The text was updated successfully, but these errors were encountered: