about summary refs log tree commit diff
path: root/scripts/nix-prefetch-url.in
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-08-15T10·13+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-08-15T10·13+0000
commite374dbf89b0ba9a4f5835ef9ac30eda6df1dce6a (patch)
treeab3712823c18dcb08fd4506716b4a102b7cfdc8b /scripts/nix-prefetch-url.in
parent01e30360d46ce940d8b83f4ff7a71e8464c1422b (diff)
* A script `nix-prefetch-url' to fetch a URL, place it in the Nix
  store, and print its hash.

Diffstat (limited to 'scripts/nix-prefetch-url.in')
-rw-r--r--scripts/nix-prefetch-url.in48
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in
new file mode 100644
index 0000000000..f5539eb98d
--- /dev/null
+++ b/scripts/nix-prefetch-url.in
@@ -0,0 +1,48 @@
+#! /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-$$";
+
+system "@wget@ '$url' -O '$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 = "@prefix@/store/nix-prefetch-url-$hash";
+rename $out, $out2;
+
+# Create a Fix expression.
+my $fixexpr = 
+    "App(IncludeFix(\"fetchurl/fetchurl.fix\"), " .
+    "[(\"url\", \"$url\"), (\"md5\", \"$hash\")])";
+
+# Instantiate a Nix expression.
+print STDERR "running fix...\n";
+my $pid = open2(\*READ, \*WRITE, "fix -") or die "cannot run fix";
+
+print WRITE $fixexpr;
+close WRITE;
+
+my $id = <READ>;
+chomp $id;
+
+waitpid $pid, 0;
+$? == 0 or die "fix failed";
+
+# Run Nix.
+print STDERR "running nix...\n";
+system "nix --install $id > /dev/null";
+$? == 0 or die "`nix --install' failed";
+
+unlink $out2;