about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.am3
-rw-r--r--scripts/nix-prefetch-url.in48
-rw-r--r--scripts/nix-pull.in7
3 files changed, 54 insertions, 4 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index d1ab6e4cdc68..4a1be7f8f0d4 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1,5 +1,5 @@
 bin_SCRIPTS = nix-switch nix-collect-garbage \
- nix-pull nix-push
+ nix-pull nix-push nix-prefetch-url
 
 noinst_SCRIPTS = nix-profile.sh
 
@@ -14,5 +14,6 @@ include ../substitute.mk
 
 EXTRA_DIST = nix-switch.in nix-collect-garbage.in \
  nix-pull.in nix-push.in nix-profile.sh.in \
+ nix-prefetch-url.in \
  prebuilts.conf
 
diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in
new file mode 100644
index 000000000000..f5539eb98dca
--- /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;
diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in
index d7b0523d6c95..a3d23ea167af 100644
--- a/scripts/nix-pull.in
+++ b/scripts/nix-pull.in
@@ -1,5 +1,6 @@
 #! /usr/bin/perl -w
 
+use strict;
 use IPC::Open2;
 
 my $tmpfile = "@localstatedir@/nix/pull.tmp";
@@ -85,7 +86,7 @@ $fullexpr .= "]";
 
 # Instantiate Nix expressions from the Fix expressions we created above.
 print STDERR "running fix...\n";
-$pid = open2(\*READ, \*WRITE, "fix -") or die "cannot run fix";
+my $pid = open2(\*READ, \*WRITE, "fix -") or die "cannot run fix";
 
 print WRITE $fullexpr;
 close WRITE;
@@ -93,9 +94,9 @@ my $i = 0;
 while (<READ>) {
     chomp;
     die unless /^([0-9a-z]{32})$/;
-    $nid = $1;
+    my $nid = $1;
     die unless ($i < scalar @ids);
-    $id = $ids[$i++];
+    my $id = $ids[$i++];
     push @subs, $id;
     push @subs, $nid;
 }