about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-10-30T10·27+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-10-30T10·27+0100
commitdae5dc7ade60aa6a9a05e41133da7faebe6bdc1b (patch)
tree73dd25edb51c70422e4cb58df6ec885d6c461557 /src
parent5c28943e8fd19d7eb55865d45d6dc61336aa04e9 (diff)
<nix/fetchurl.nix>: Support downloading and unpacking NARs
This removes the need to have multiple downloads in the stdenv
bootstrap process (like a separate busybox binary for Linux, or
curl/mkdir/sh/bzip2 for Darwin). Now all those files can be combined
into a single NAR.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/builtins.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/libstore/builtins.cc b/src/libstore/builtins.cc
index 2a4396308399..fefad63bd1bb 100644
--- a/src/libstore/builtins.cc
+++ b/src/libstore/builtins.cc
@@ -1,5 +1,7 @@
 #include "builtins.hh"
 #include "download.hh"
+#include "store-api.hh"
+#include "archive.hh"
 
 namespace nix {
 
@@ -20,12 +22,21 @@ void builtinFetchurl(const BasicDerivation & drv)
 
     auto out = drv.env.find("out");
     if (out == drv.env.end()) throw Error("attribute ‘url’ missing");
-    writeFile(out->second, data.data);
+
+    Path storePath = out->second;
+    assertStorePath(storePath);
+
+    auto unpack = drv.env.find("unpack");
+    if (unpack != drv.env.end() && unpack->second == "1") {
+        StringSource source(data.data);
+        restorePath(storePath, source);
+    } else
+        writeFile(storePath, data.data);
 
     auto executable = drv.env.find("executable");
     if (executable != drv.env.end() && executable->second == "1") {
-        if (chmod(out->second.c_str(), 0755) == -1)
-            throw SysError(format("making ‘%1%’ executable") % out->second);
+        if (chmod(storePath.c_str(), 0755) == -1)
+            throw SysError(format("making ‘%1%’ executable") % storePath);
     }
 }