2004-03-15 16:23:53 +01:00
|
|
|
#! @perl@ -w
|
2003-08-15 12:13:41 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IPC::Open2;
|
|
|
|
|
|
|
|
my $url = shift @ARGV;
|
|
|
|
defined $url or die;
|
|
|
|
|
|
|
|
print "fetching $url...\n";
|
|
|
|
|
2004-02-20 12:32:30 +01:00
|
|
|
my $out = "@storedir@/nix-prefetch-url-$$";
|
2003-08-15 12:13:41 +02:00
|
|
|
|
2004-04-06 10:18:51 +02:00
|
|
|
system "@curl@ --fail --location --max-redirs 20 \"$url\" > \"$out\"";
|
2003-08-15 12:13:41 +02: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 12:32:30 +01:00
|
|
|
my $out2 = "@storedir@/nix-prefetch-url-$hash";
|
2003-08-15 12:13:41 +02:00
|
|
|
rename $out, $out2;
|
|
|
|
|
2003-11-22 19:45:56 +01:00
|
|
|
# Create a Nix expression.
|
|
|
|
my $nixexpr =
|
|
|
|
"(import @datadir@/nix/corepkgs/fetchurl) " .
|
2004-02-10 17:14:47 +01:00
|
|
|
"{url = $url; md5 = \"$hash\"; system = \"@system@\";}";
|
2003-11-22 19:45:56 +01:00
|
|
|
|
2004-04-06 10:18:51 +02:00
|
|
|
#print STDERR "expr: $nixexpr\n";
|
2003-08-15 12:13:41 +02:00
|
|
|
|
|
|
|
# Instantiate a Nix expression.
|
2004-04-06 10:18:51 +02:00
|
|
|
#print STDERR "instantiating Nix expression...\n";
|
|
|
|
my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-instantiate -")
|
|
|
|
or die "cannot run nix-instantiate";
|
2003-08-15 12:13:41 +02:00
|
|
|
|
2003-11-22 19:45:56 +01:00
|
|
|
print WRITE $nixexpr;
|
2003-08-15 12:13:41 +02:00
|
|
|
close WRITE;
|
|
|
|
|
2003-11-22 19:45:56 +01:00
|
|
|
my $drvpath = <READ>;
|
|
|
|
chomp $drvpath;
|
2003-08-15 12:13:41 +02:00
|
|
|
|
|
|
|
waitpid $pid, 0;
|
2003-11-22 19:45:56 +01:00
|
|
|
$? == 0 or die "nix-instantiate failed";
|
2003-08-15 12:13:41 +02:00
|
|
|
|
|
|
|
# Run Nix.
|
2004-04-06 10:18:51 +02:00
|
|
|
#print STDERR "realising store expression $drvpath...\n";
|
|
|
|
system "@bindir@/nix-store --realise $drvpath > /dev/null";
|
2003-11-22 19:45:56 +01:00
|
|
|
$? == 0 or die "realisation failed";
|
2003-08-15 12:13:41 +02:00
|
|
|
|
2004-04-06 10:18:51 +02:00
|
|
|
my $path = `@bindir@/nix-store -qn $drvpath`;
|
|
|
|
$? == 0 or die "query failed";
|
|
|
|
|
|
|
|
print "path is $path";
|
|
|
|
|
2003-08-15 12:13:41 +02:00
|
|
|
unlink $out2;
|