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