2003-08-15 13:13:41 +03:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IPC::Open2;
|
|
|
|
|
|
|
|
my $url = shift @ARGV;
|
|
|
|
defined $url or die;
|
|
|
|
|
|
|
|
print "fetching $url...\n";
|
|
|
|
|
|
|
|
my $out = "@prefix@/store/nix-prefetch-url-$$";
|
|
|
|
|
2003-10-02 18:48:47 +03:00
|
|
|
system "@wget@ --passive-ftp '$url' -O '$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";
|
|
|
|
|
|
|
|
my $out2 = "@prefix@/store/nix-prefetch-url-$hash";
|
|
|
|
rename $out, $out2;
|
|
|
|
|
2003-11-22 20:45:56 +02:00
|
|
|
# Create a Nix expression.
|
|
|
|
my $nixexpr =
|
|
|
|
"(import @datadir@/nix/corepkgs/fetchurl) " .
|
2003-12-01 16:36:50 +02:00
|
|
|
"{url = $url; md5 = \"$hash\"; system = \"@system@\"}";
|
2003-11-22 20:45:56 +02:00
|
|
|
|
|
|
|
print "expr: $nixexpr\n";
|
2003-08-15 13:13:41 +03:00
|
|
|
|
|
|
|
# Instantiate a Nix expression.
|
2003-11-22 20:45:56 +02:00
|
|
|
print STDERR "instantiating Nix expression...\n";
|
|
|
|
my $pid = open2(\*READ, \*WRITE, "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.
|
2003-11-22 20:45:56 +02:00
|
|
|
print STDERR "realising store expression $drvpath...\n";
|
|
|
|
system "nix-store --realise $drvpath > /dev/null";
|
|
|
|
$? == 0 or die "realisation failed";
|
2003-08-15 13:13:41 +03:00
|
|
|
|
|
|
|
unlink $out2;
|