Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created November 20, 2017 16:53
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 grahamc/d7938afa50ecbc3307f87b4d1c5f9ec6 to your computer and use it in GitHub Desktop.
Save grahamc/d7938afa50ecbc3307f87b4d1c5f9ec6 to your computer and use it in GitHub Desktop.
{ 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