Allow nix-shell to be used as a #! interpreter
Allow nix-shell to be used as a #! interpreter

This allows scripts to fetch their own dependencies via nix-shell. For
instance, here is a Haskell script that, when executed, pulls in GHC
and the HTTP package:

  #! /usr/bin/env nix-shell
  #! nix-shell -i runghc -p haskellPackages.ghc haskellPackages.HTTP

  import Network.HTTP

  main = do
    resp <- Network.HTTP.simpleHTTP (getRequest "http://nixos.org/")
    body <- getResponseBody resp
    print (take 100 body)

Or a Perl script that pulls in Perl and some CPAN packages:

  #! /usr/bin/env nix-shell
  #! nix-shell -i perl -p perl perlPackages.HTMLTokeParserSimple perlPackages.LWP

  use HTML::TokeParser::Simple;

  my $p = HTML::TokeParser::Simple->new(url => 'http://nixos.org/');

  while (my $token = $p->get_tag("a")) {
      my $href = $token->get_attr("href");
      print "$href\n" if $href;
  }

Note that the options to nix-shell must be given on a separate line
that starts with the magic string ‘#! nix-shell’. This is because
‘env’ does not allow passing arguments to an interpreter directly.

bjornfor/nix,bennofs/nix,ttuegel/nix,bjornfor/nix,peti/nix,vcunat/nix,NixOS/nix,wmertens/nix,gebner/nix,ehmry/nix,acowley/nix,dtzWill/nix,vcunat/nix,gridaphobe/nix,rycee/nix,garbas/nix,rowhit/nix,NixOS/nix,NixOS/nix,puffnfresh/nix,rowhit/nix,peti/nix,tchajed/nix,offlinehacker/nix,dtzWill/nix,layus/nix,shlevy/nix,aucampia/nix,acowley/nix,vizanto/nix,dezgeg/nix,pikajude/nix,joelmo/nix,dezgeg/nix,rycee/nix,gridaphobe/nix,rowhit/nix,ehmry/nix,offlinehacker/nix,shlevy/nix,zimbatm/nix,pikajude/nix,offlinehacker/nix,garbas/nix,layus/nix,garbas/nix,gebner/nix,vcunat/nix,joelmo/nix,garbas/nix,dezgeg/nix,joelmo/nix,tchajed/nix,bennofs/nix,dtzWill/nix,peti/nix,bjornfor/nix,shlevy/nix,offlinehacker/nix,layus/nix,NixOS/nix,ehmry/nix,rycee/nix,peti/nix,puffnfresh/nix,gebner/nix,tchajed/nix,dtzWill/nix,dtzWill/nix,zimbatm/nix,aucampia/nix,zimbatm/nix,ehmry/nix,ttuegel/nix,dezgeg/nix,bjornfor/nix,puffnfresh/nix,shlevy/nix,pikajude/nix,wmertens/nix,layus/nix,NixOS/nix,vizanto/nix,aucampia/nix,acowley/nix,ehmry/nix,ysangkok/nix,ttuegel/nix,rycee/nix,vizanto/nix,shlevy/nix,aucampia/nix,bennofs/nix,joelmo/nix,rycee/nix,zimbatm/nix,gridaphobe/nix,wmertens/nix,peti/nix,gebner/nix,puffnfresh/nix,ttuegel/nix,bennofs/nix,garbas/nix,vcunat/nix,rowhit/nix,acowley/nix,ehmry/nix,vizanto/nix,wmertens/nix,ysangkok/nix,tchajed/nix,dezgeg/nix,layus/nix,gridaphobe/nix,ysangkok/nix