1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

Make <nix/unpack-channel.nix> a builtin builder

This was the last function using a shell script, so this allows us to
get rid of tar, coreutils, bash etc.
This commit is contained in:
Eelco Dolstra 2019-03-27 23:40:35 +01:00
parent e60f6bd4ce
commit 045708db43
9 changed files with 55 additions and 84 deletions

View file

@ -3128,6 +3128,8 @@ void DerivationGoal::runChild()
builtinFetchurl(drv2, netrcData);
else if (drv->builder == "builtin:buildenv")
builtinBuildenv(drv2);
else if (drv->builder == "builtin:unpack-channel")
builtinUnpackChannel(drv2);
else
throw Error(format("unsupported builtin function '%1%'") % string(drv->builder, 8));
_exit(0);

View file

@ -7,5 +7,6 @@ namespace nix {
// TODO: make pluggable.
void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData);
void builtinBuildenv(const BasicDerivation & drv);
void builtinUnpackChannel(const BasicDerivation & drv);
}

View file

@ -0,0 +1,39 @@
#include "rust.hh"
#include "builtins.hh"
#include "compression.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);
auto source = sinkToSource([&](Sink & sink) {
auto decompressor =
hasSuffix(src, ".bz2") ? makeDecompressionSink("bzip2", sink) :
hasSuffix(src, ".xz") ? makeDecompressionSink("xz", sink) :
makeDecompressionSink("none", sink);
readFile(src, *decompressor);
decompressor->finish();
});
unpack_tarfile(*source, 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");
}
}

View file

@ -6,7 +6,7 @@ libstore_DIR := $(d)
libstore_SOURCES := $(wildcard $(d)/*.cc $(d)/builtins/*.cc)
libstore_LIBS = libutil
libstore_LIBS = libutil libnixrust
libstore_LDFLAGS = $(SQLITE3_LIBS) -lbz2 $(LIBCURL_LIBS) $(SODIUM_LIBS) -pthread
ifneq ($(OS), FreeBSD)

View file

@ -1,9 +1,4 @@
#include "command.hh"
#include "store-api.hh"
#include "common-args.hh"
#include "compression.hh"
using namespace nix;
#include "serialise.hh"
namespace rust {
@ -47,37 +42,3 @@ struct Source
extern "C" {
bool unpack_tarfile(rust::Source source, rust::StringSlice dest_dir);
}
struct CmdTest : StoreCommand
{
CmdTest()
{
}
std::string name() override
{
return "test";
}
std::string description() override
{
return "bla bla";
}
void run(ref<Store> store) override
{
auto source = sinkToSource([&](Sink & sink) {
auto decompressor = makeDecompressionSink("bzip2", sink);
readFile("./nix-2.2.tar.bz2", *decompressor);
decompressor->finish();
});
std::string destDir = "./dest";
deletePath(destDir);
unpack_tarfile(*source, destDir);
}
};
static RegisterCommand r(make_ref<CmdTest>());

View file

@ -15,9 +15,9 @@ nix_SOURCES := \
$(wildcard src/nix-prefetch-url/*.cc) \
$(wildcard src/nix-store/*.cc) \
nix_LIBS = libexpr libmain libstore libutil libnixrust
nix_LIBS = libexpr libmain libstore libutil
nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -lboost_context -lboost_thread -lboost_system -Lnix-rust/target/release
nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -lboost_context -lboost_thread -lboost_system
$(foreach name, \
nix-build nix-channel nix-collect-garbage nix-copy-closure nix-daemon nix-env nix-hash nix-instantiate nix-prefetch-url nix-shell nix-store, \