Skip to content
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

TeX Live: mptopdf is broken #24343

Closed
williamyaoh opened this issue Mar 26, 2017 · 2 comments
Closed

TeX Live: mptopdf is broken #24343

williamyaoh opened this issue Mar 26, 2017 · 2 comments

Comments

@williamyaoh
Copy link

williamyaoh commented Mar 26, 2017

Issue description

The mptopdf executable installed as part of texlive.combined.scheme-basic errors out no matter
what arguments it's called with, with an error:

/nix/store/.../bin/bash -S: invalid option

Steps to reproduce

  1. Install the basic TeX Live setup
    nix-env -f '<nixpkgs>' -iA texlive.combined.scheme-basic
  2. Run mptopdf

Notes

The problem seems to come from these lines at the very beginning of the mptopdf.pl Perl script that
the TeX Live derivation wraps around:

eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q'
        if 0;

It's using exec and $0 to do what a shebang does instead of... just using a shebang.
The Perl call is expecting $0 to point directly to the mptopdf.pl script, but the Nix wrapper
script is setting $0 to whatever command it was called with; in this case, the raw string "mptopdf".

Placing these lines in a separate executable file (let's say mptopdf.sh) and simulating
what the wrapper script does, reproduces the error message:

$ bash -c 'exec -a mptopdf ./mptopdf.sh
/nix/store/.../bin/bash -S: invalid option

After replacing the instance of perl in the first exec call with an absolute store path,
and $0 with the store path to mptopdf.pl, the command above then works and calls mptopdf
as intended.

The TeX Live distribution installed on my Ubuntu setup looks like it just replaced those first
two lines in mptopdf.pl with #! /usr/bin/perl -w. So it seems like the easiest way would be either
to patch mptopdf.pl to use a shebang line pointing directly to Perl, or to patch the wrapper script
created around mptopdf to pass something else as $0; that is, change this line in the wrapper
script:

exec -a "$0" "/nix/store/...-mptopdf-2016/scripts/context/perl/mptopdf.pl"  "${extraFlagsArray[@]}" "$@"

to this:

exec "/nix/store/...-mptopdf-2016/scripts/context/perl/mptopdf.pl"  "${extraFlagsArray[@]}" "$@"

so that the Perl script can find and call itself.

Technical details

  • System: 17.03beta685.1dbb962 (Gorilla)
  • Nix version: 1.11.8
  • Nixpkgs version: 17.03beta685.1dbb962
@williamyaoh
Copy link
Author

There are some other Perl scripts in the TeX Live source repo that also have this weird
pseudo-shebang line:

https://www.tug.org/svn/texlive/trunk/Master/texmf-dist/scripts/context/perl/

They're not installed as part of the basic-scheme derivation, but they might be installed as
part of other TeX packages, and would likely need patching as well.

vcunat added a commit that referenced this issue Jul 1, 2017
Fixes #24343.  These parts of upstream texlive are really ugly.
Also improve variable quoting in the code around.

(cherry picked from commit 8dddd2b)
The change seems safe enough.
@vcunat vcunat closed this as completed in 8dddd2b Jul 1, 2017
@vcunat
Copy link
Member

vcunat commented Jul 1, 2017

I haven't noticed this ticket; it should be OK now on both master and 17.03.

These ugly pseudo-shebangs are now detected and wrapped by perl -w instead of bash.

adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
Fixes NixOS#24343.  These parts of upstream texlive are really ugly.
Also improve variable quoting in the code around.

(cherry picked from commit 8dddd2b)
The change seems safe enough.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants