forked from lix-project/lix
03f1d1ecb5
* Made the dependencies on bzip2 and the shell explicit.
56 lines
1.2 KiB
Text
56 lines
1.2 KiB
Text
#! @perl@ -w
|
|
|
|
use strict;
|
|
use IPC::Open2;
|
|
|
|
my $url = shift @ARGV;
|
|
defined $url or die;
|
|
|
|
print "fetching $url...\n";
|
|
|
|
my $out = "@storedir@/nix-prefetch-url-$$";
|
|
|
|
system "@curl@ --fail --location --max-redirs 20 \"$url\" > \"$out\"";
|
|
$? == 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 = "@storedir@/nix-prefetch-url-$hash";
|
|
rename $out, $out2;
|
|
|
|
# Create a Nix expression.
|
|
my $nixexpr =
|
|
"(import @datadir@/nix/corepkgs/fetchurl) " .
|
|
"{url = $url; md5 = \"$hash\"; system = \"@system@\";}";
|
|
|
|
#print STDERR "expr: $nixexpr\n";
|
|
|
|
# Instantiate a Nix expression.
|
|
#print STDERR "instantiating Nix expression...\n";
|
|
my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-instantiate -")
|
|
or die "cannot run nix-instantiate";
|
|
|
|
print WRITE $nixexpr;
|
|
close WRITE;
|
|
|
|
my $drvpath = <READ>;
|
|
chomp $drvpath;
|
|
|
|
waitpid $pid, 0;
|
|
$? == 0 or die "nix-instantiate failed";
|
|
|
|
# Run Nix.
|
|
#print STDERR "realising store expression $drvpath...\n";
|
|
system "@bindir@/nix-store --realise $drvpath > /dev/null";
|
|
$? == 0 or die "realisation failed";
|
|
|
|
my $path = `@bindir@/nix-store -qn $drvpath`;
|
|
$? == 0 or die "query failed";
|
|
|
|
print "path is $path";
|
|
|
|
unlink $out2;
|