aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/builtins
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-12-04 00:31:09 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-12-04 00:31:09 +0100
commitc3c23a52ee1c5844343bc5ed075791ec7fec6413 (patch)
treebaf65223d87d2a5a5030f88208ceebab790624da /src/libstore/builtins
parente721f99817bb7154d8098c902e25f84521a90b7f (diff)
parentc1d18050b4cfed9eba68d4d21b397c6cce035e37 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libstore/builtins')
-rw-r--r--src/libstore/builtins/unpack-channel.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libstore/builtins/unpack-channel.cc b/src/libstore/builtins/unpack-channel.cc
new file mode 100644
index 000000000..d18e3ddaf
--- /dev/null
+++ b/src/libstore/builtins/unpack-channel.cc
@@ -0,0 +1,29 @@
+#include "builtins.hh"
+#include "tarfile.hh"
+
+namespace nix {
+
+void builtinUnpackChannel(const BasicDerivation & drv)
+{
+ auto getAttr = [&](const string & name) {
+ auto i = drv.env.find(name);
+ if (i == drv.env.end()) throw Error("attribute '%s' missing", name);
+ return i->second;
+ };
+
+ Path out = getAttr("out");
+ auto channelName = getAttr("channelName");
+ auto src = getAttr("src");
+
+ createDirs(out);
+
+ unpackTarfile(src, out);
+
+ auto entries = readDirectory(out);
+ if (entries.size() != 1)
+ throw Error("channel tarball '%s' contains more than one file", src);
+ if (rename((out + "/" + entries[0].name).c_str(), (out + "/" + channelName).c_str()) == -1)
+ throw SysError("renaming channel directory");
+}
+
+}