Skip to content

Commit

Permalink
Allow a "file" libfetcher type for plain files
Browse files Browse the repository at this point in the history
Resolves NixOS#3785

Might help NixOS#3920
  • Loading branch information
bqv committed Oct 15, 2020
1 parent 11882d7 commit f4f7b0b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,12 @@ struct TarballInputScheme : InputScheme

std::optional<Input> inputFromAttrs(const Attrs & attrs) override
{
if (maybeGetStrAttr(attrs, "type") != "tarball") return {};
auto type = maybeGetStrAttr(attrs, "type");
if (type != "tarball" && type != "file") return {};

for (auto & [name, value] : attrs)
if (name != "type" && name != "url" && /* name != "hash" && */ name != "narHash")
throw Error("unsupported tarball input attribute '%s'", name);
throw Error("unsupported %s input attribute '%s'", *type, name);

Input input;
input.attrs = attrs;
Expand Down Expand Up @@ -226,8 +227,14 @@ struct TarballInputScheme : InputScheme

std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) override
{
auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), "source", false).first;
return {std::move(tree), input};
std::optional<Tree> tree;
if (getStrAttr(input.attrs, "type") == "tarball")
tree = downloadTarball(store, getStrAttr(input.attrs, "url"), "source", false).first;
else {
auto file = downloadFile(store, getStrAttr(input.attrs, "url"), "source", false);
tree = Tree(store->toRealPath(file.storePath), std::move(file.storePath));
}
return {std::move(*tree), input};
}
};

Expand Down

0 comments on commit f4f7b0b

Please sign in to comment.