2004-03-15 15:23:53 +00:00
|
|
|
#! @perl@ -w
|
2003-08-15 10:13:41 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IPC::Open2;
|
|
|
|
|
|
|
|
my $url = shift @ARGV;
|
|
|
|
defined $url or die;
|
|
|
|
|
|
|
|
print "fetching $url...\n";
|
|
|
|
|
2004-02-20 11:32:30 +00:00
|
|
|
my $out = "@storedir@/nix-prefetch-url-$$";
|
2003-08-15 10:13:41 +00:00
|
|
|
|
2003-10-02 15:48:47 +00:00
|
|
|
system "@wget@ --passive-ftp '$url' -O '$out'";
|
2003-08-15 10:13:41 +00:00
|
|
|
$? == 0 or die "unable to fetch $url";
|
|
|
|
|
|
|
|
my $hash=`@bindir@/nix-hash --flat $out`;
|
|
|
|
$? == 0 or die "unable to hash $out";
|
|
|
|
chomp $hash;
|
|
|
|
|
|
|
|
print "file has hash $hash\n";
|
|
|
|
|
2004-02-20 11:32:30 +00:00
|
|
|
my $out2 = "@storedir@/nix-prefetch-url-$hash";
|
2003-08-15 10:13:41 +00:00
|
|
|
rename $out, $out2;
|
|
|
|
|
2003-11-22 18:45:56 +00:00
|
|
|
# Create a Nix expression.
|
|
|
|
my $nixexpr =
|
|
|
|
"(import @datadir@/nix/corepkgs/fetchurl) " .
|
2004-02-10 16:14:47 +00:00
|
|
|
"{url = $url; md5 = \"$hash\"; system = \"@system@\";}";
|
2003-11-22 18:45:56 +00:00
|
|
|
|
|
|
|
print "expr: $nixexpr\n";
|
2003-08-15 10:13:41 +00:00
|
|
|
|
|
|
|
# Instantiate a Nix expression.
|
2003-11-22 18:45:56 +00:00
|
|
|
print STDERR "instantiating Nix expression...\n";
|
|
|
|
my $pid = open2(\*READ, \*WRITE, "nix-instantiate -") or die "cannot run nix-instantiate";
|
2003-08-15 10:13:41 +00:00
|
|
|
|
2003-11-22 18:45:56 +00:00
|
|
|
print WRITE $nixexpr;
|
2003-08-15 10:13:41 +00:00
|
|
|
close WRITE;
|
|
|
|
|
2003-11-22 18:45:56 +00:00
|
|
|
my $drvpath = <READ>;
|
|
|
|
chomp $drvpath;
|
2003-08-15 10:13:41 +00:00
|
|
|
|
|
|
|
waitpid $pid, 0;
|
2003-11-22 18:45:56 +00:00
|
|
|
$? == 0 or die "nix-instantiate failed";
|
2003-08-15 10:13:41 +00:00
|
|
|
|
|
|
|
# Run Nix.
|
2003-11-22 18:45:56 +00:00
|
|
|
print STDERR "realising store expression $drvpath...\n";
|
|
|
|
system "nix-store --realise $drvpath > /dev/null";
|
|
|
|
$? == 0 or die "realisation failed";
|
2003-08-15 10:13:41 +00:00
|
|
|
|
|
|
|
unlink $out2;
|