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

ack installs, but reports "use: command not found" #47302

Closed
Calvin-L opened this issue Sep 24, 2018 · 11 comments
Closed

ack installs, but reports "use: command not found" #47302

Calvin-L opened this issue Sep 24, 2018 · 11 comments
Labels
6.topic: darwin Running or building packages on Darwin

Comments

@Calvin-L
Copy link
Contributor

Issue description

The ack tool can be installed, but reports errors like "use: command not found". These errors are symptoms of trying to execute a Perl script with Bash; I am not sure why the shebang line in the ack script is not working.

(Also, unrelated: while nix-shell -p ack works, nix-env -i ack instead reports "error: selector 'ack' matches no derivations". Perhaps I have some misunderstanding about what the arguments to these commands mean.)

Steps to reproduce

$ nix-shell --pure -p ack
$ ack --help
/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack: line 3: use: command not found
/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack: line 4: use: command not found
/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack: line 5: our: command not found
/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack: line 7: use: command not found
/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack: line 8: syntax error near unexpected token `('
/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack: line 8: `use Getopt::Long 2.38 ();'

Shebang line

$ type ack
ack is /nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack
$ head -n1 /nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/bin/ack
#!/nix/store/xhir85mv5mfwdkbisnx3bl9h6agjmix4-perl-5.28.0/bin/perl -I/nix/store/xhir85mv5mfwdkbisnx3bl9h6agjmix4-perl-5.28.0/lib/perl5/site_perl -I/nix/store/fm5qg2kljrks0m5jbba6f69ik4vad3bv-perl5.28.0-File-Next-1.16/lib/perl5/site_perl -I/nix/store/xhir85mv5mfwdkbisnx3bl9h6agjmix4-perl-5.28.0/lib/perl5/site_perl -I/nix/store/fm5qg2kljrks0m5jbba6f69ik4vad3bv-perl5.28.0-File-Next-1.16/lib/perl5/site_perl -I/nix/store/xhir85mv5mfwdkbisnx3bl9h6agjmix4-perl-5.28.0/lib/perl5/site_perl -I/nix/store/fm5qg2kljrks0m5jbba6f69ik4vad3bv-perl5.28.0-File-Next-1.16/lib/perl5/site_perl -I/nix/store/q82s26mj9z0j29kcd2w31ykssd9nc67b-perl5.28.0-ack-2.24/lib/perl5/site_perl

Technical details

  • system: "x86_64-darwin"
  • host os: Darwin 17.7.0, macOS 10.13.6
  • multi-user?: no
  • sandbox: no
  • version: nix-env (Nix) 2.1.1
  • channels(cloncari): "nixpkgs-19.03pre153206.f753852e11d"
  • nixpkgs: /Users/cloncari/.nix-defexpr/channels/nixpkgs
@kliu128
Copy link

kliu128 commented Sep 25, 2018

Seems to work for me on NixOS unstable.

[nix-shell:~/Documents/zero]$ ack --help                                                                                                                    
Usage: ack [OPTION]... PATTERN [FILES OR DIRECTORIES]                                                                                                       
                                                                                                                                                            
Search for PATTERN in each source file in the tree from the current                                                                                         
directory on down.  If any files or directories are specified, then                                                                                         
only those files and directories are checked.  ack may also search                                                                                          
STDIN, but only if no file or directory arguments are specified,                                                                                            
or if one of them is "-".                                                                                                                                   
                                                                                                                                                            
Default switches may be specified in ACK_OPTIONS environment variable or                                                                                    
an .ackrc file. If you want no dependency on the environment, turn it                                                                                       
off with --noenv.
  • system: "x86_64-linux"
  • host os: Linux 4.19.0-rc4, NixOS, 19.03.git.77f3f43 (Koi)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.1.2
  • channels(root): ""
  • nixpkgs: /etc/nixos/nixpkgs

@dtzWill
Copy link
Member

dtzWill commented Sep 25, 2018

Same, Linux here as well though. Can any Darwin user give this a try?

I don't know OSX versions but I do recall some (presumably older-ish?) had some issue with shebang handling, but it'd probably be best to wait for someone who knows more before jumping to any conclusions :).

@lheckemann
Copy link
Member

I had a similar problem the other day when I got a script for the wrong architecture — it turns out that when calling the interpreter specified in the shebang results in "Exec format error", (at least on linux) the kernel will try to run it with /bin/sh instead. @Calvin-L can you run /nix/store/xhir85mv5mfwdkbisnx3bl9h6agjmix4-perl-5.28.0/bin/perl?

@Calvin-L
Copy link
Contributor Author

@lheckemann I can, in fact!

$ /nix/store/xhir85mv5mfwdkbisnx3bl9h6agjmix4-perl-5.28.0/bin/perl --version

This is perl 5, version 28, subversion 0 (v5.28.0) built for darwin-2level
[...]

@Amar1729
Copy link
Contributor

Seems like it's a problem with shebang handling on Darwin.

$ nix-info -m
 - system: `"x86_64-darwin"`
 - host os: `Darwin 17.7.0, macOS 10.13.6`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.1.3`
 - channels(paula1): `"nixpkgs-19.03pre155263.20c4986c4dd"`
 - nixpkgs: `/Users/paula1/.nix-defexpr/channels/nixpkgs`

This is the nix shebang for ack (spaces replaced with newlines for readability):

#!/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/bin/perl
-I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl
-I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl
-I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl
-I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl
-I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl
-I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl
-I/nix/store/93i93v14dsmvvb1p06ny9sdwirhz4gca-perl5.28.0-ack-2.24/lib/perl5/site_perl

Manually calling /nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/bin/perl works fine. Deleting the shebang from the ack script and calling it manually like this works:
/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/bin/perl -I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl bin/ack --help

So I just removed the duplicate paths from the ack shebang and it works fine:

#!/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/bin/perl
-I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl
-I/nix/store/93i93v14dsmvvb1p06ny9sdwirhz4gca-perl5.28.0-ack-2.24/lib/perl5/site_perl
-I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl

Not sure why this problem exists though. Maybe duplicate include directories in shebangs should be fixed in the buildPerlPackage function?

@Amar1729
Copy link
Contributor

Interestingly, on mac just calling it from cli explicitly works:
/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/bin/perl -I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl -I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl -I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl -I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl -I/nix/store/c5a3d01x5n14f97hr2ni45z39cbqm6hk-perl-5.28.0/lib/perl5/site_perl -I/nix/store/3fkxk27px7ajvf6akrfna3kmsnf34hv7-perl5.28.0-File-Next-1.16/lib/perl5/site_perl -I/nix/store/93i93v14dsmvvb1p06ny9sdwirhz4gca-perl5.28.0-ack-2.24/lib/perl5/site_perl /nix/store/93i93v14dsmvvb1p06ny9sdwirhz4gca-perl5.28.0-ack-2.24/bin/ack --help

@Calvin-L
Copy link
Contributor Author

That shebang line is awful long. Could it be that MacOS has some maximum length for the shebang line? That would explain why shortening the line makes it work. If Bash has a longer maximum command length, then it also explains why invoking perl directly from Bash works.

@Calvin-L
Copy link
Contributor Author

This issue might be a duplicate of #35353, which is looking into buildPerlModule creating shebang lines that are too long for Darwin systems.

@Amar1729
Copy link
Contributor

This stackoverflow solution is an interesting workaround - could maybe considered as wrapper logic for buildPerlModule on darwin

#!/bin/bash
script="$1" 
shebang=$(head -1 "$script")
interp=( ${shebang#\#!} )        # use an array in case a argument is there too
# now run it
exec "${interp[@]}" "$script"

@cyounkins
Copy link
Contributor

I can confirm modifying the shebang to remove the duplicate includes fixes ack. I agree it appears to be the line length. Good find, this was puzzling!

@dropwhile
Copy link

dropwhile commented Jun 3, 2019

@Calvin-L On macos, I was able to install ack with nix-env -i -A nixpkgs.ack.
nix-env -i ack also did not work for me.

Got the same error though due to shebang line length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin
Projects
None yet
Development

No branches or pull requests

8 participants