Skip to content

Commit

Permalink
patchShebangs: don't remove ".../bin/env" (fixes NixOS#2146)
Browse files Browse the repository at this point in the history
FIXME: The linux kernel limits the shebang to 128 bytes
("#define BINPRM_BUF_SIZE 128"), which is too small for
"/nix/store/.../env /nix/store/.../interpreter".

Currently, something like "/usr/bin/env python" is changed into
"/nix/store/<hash>/bin/python" ("env" is removed).

This works in linux systems, but does not work on BSD flavored systems
like OS X since they do not allow another shell script to play a role as
an interpreter. (Interpreters built with nixpkgs are typically shell
script wrappers for the real interpreter binaries.)

The new behaviour is to rewrite "/usr/bin/env python" to
"/nix/store/<hash>/bin/env /nix/store/<hash>/bin/python".
  • Loading branch information
bjornfor committed Jul 29, 2015
1 parent 4efbe96 commit e92ef89
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkgs/build-support/setup-hooks/patch-shebangs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# interpreter file names (`#! /path') to paths found in $PATH. E.g.,
# /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
# /usr/bin/env gets special treatment so that ".../bin/env python" is
# rewritten to /nix/store/<hash>/bin/python. Interpreters that are
# already in the store are left untouched.
# rewritten to "/nix/store/<hash>/bin/env /nix/store/<hash>/bin/python" (both
# "env" and "python" get absolute paths). Interpreters that are already in the
# store are left untouched.

fixupOutputHooks+=('if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi')

Expand Down Expand Up @@ -35,7 +36,9 @@ patchShebangs() {
echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
exit 1
fi
envPath="$(command -v env)"
newPath="$(command -v "$arg0" || true)"
newInterpreterLine="$envPath $newPath $args"
else
if [ "$oldPath" = "" ]; then
# If no interpreter is specified linux will use /bin/sh. Set
Expand All @@ -44,10 +47,9 @@ patchShebangs() {
fi
newPath="$(command -v "$(basename "$oldPath")" || true)"
args="$arg0 $args"
newInterpreterLine="$newPath $args"
fi

newInterpreterLine="$newPath $args"

if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
Expand Down

0 comments on commit e92ef89

Please sign in to comment.