diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-01-08T13·32+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-01-08T13·32+0100 |
commit | a957893b261a4438101c205e38fe8ce62b83a121 (patch) | |
tree | de3e3fd274ca4fa201f4fdf746929d55bfdc79f2 /src | |
parent | 7ba0e9cb481f00baca02f31393ad49681fc48a5d (diff) |
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.
Diffstat (limited to 'src')
0 files changed, 0 insertions, 0 deletions