Created
November 20, 2017 16:53
-
-
Save grahamc/d7938afa50ecbc3307f87b4d1c5f9ec6 to your computer and use it in GitHub Desktop.
This file contains 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
{ stdenv }: | |
{ name, script, bundlerEnvResult }: | |
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/...-ruby-2.3.3/bin/ruby "${extraFlagsArray[@]}" "$@" | |
# | |
# and adds the script between `bin/ruby` and `"${extraFlagsArray`: | |
# | |
# exec /nix/store/...-ruby-2.3.3/bin/ruby /nix/store/...-my-script "${extraFlagsArray[@]}" "$@" | |
# | |
# and since the wrappedRuby script uses bash directly in the | |
# shebang (and not another script) this works on macOS and Linux. | |
buildCommand = '' | |
sed \ | |
-e "s#/bin/ruby\" #/bin/ruby\" ${script} #" \ | |
${bundlerEnvResult.wrappedRuby}/bin/ruby > ./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} | |
''; | |
passthru.env = bundlerEnvResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment