mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
Cleanup
This commit is contained in:
parent
8414685c0f
commit
185c3c8240
7 changed files with 62 additions and 34 deletions
|
@ -68,7 +68,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
|
||||||
expectType(state, tAttrs, *value, pos);
|
expectType(state, tAttrs, *value, pos);
|
||||||
|
|
||||||
FlakeInput input {
|
FlakeInput input {
|
||||||
.ref = parseFlakeRef(inputName)
|
.ref = FlakeRef::fromAttrs({{"type", "indirect"}, {"id", inputName}})
|
||||||
};
|
};
|
||||||
|
|
||||||
auto sInputs = state.symbols.create("inputs");
|
auto sInputs = state.symbols.create("inputs");
|
||||||
|
|
|
@ -370,32 +370,39 @@ struct GitInputScheme : InputScheme
|
||||||
url.scheme != "git+ssh" &&
|
url.scheme != "git+ssh" &&
|
||||||
url.scheme != "git+file") return nullptr;
|
url.scheme != "git+file") return nullptr;
|
||||||
|
|
||||||
auto input = std::make_unique<GitInput>(url);
|
auto url2(url);
|
||||||
|
// FIXME: strip git+
|
||||||
|
url2.query.clear();
|
||||||
|
|
||||||
input->url.query.clear();
|
Input::Attrs attrs;
|
||||||
|
attrs.emplace("type", "git");
|
||||||
|
|
||||||
for (auto &[name, value] : url.query) {
|
for (auto &[name, value] : url.query) {
|
||||||
if (name == "rev") {
|
if (name == "rev" || name == "ref")
|
||||||
if (!std::regex_match(value, revRegex))
|
attrs.emplace(name, value);
|
||||||
throw BadURL("Git URL '%s' contains an invalid commit hash", url.url);
|
else
|
||||||
input->rev = Hash(value, htSHA1);
|
url2.query.emplace(name, value);
|
||||||
}
|
|
||||||
else if (name == "ref") {
|
|
||||||
if (!std::regex_match(value, refRegex))
|
|
||||||
throw BadURL("Git URL '%s' contains an invalid branch/tag name", url.url);
|
|
||||||
input->ref = value;
|
|
||||||
}
|
|
||||||
else input->url.query.insert_or_assign(name, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
attrs.emplace("url", url2.to_string());
|
||||||
|
|
||||||
|
return inputFromAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
||||||
{
|
{
|
||||||
if (maybeGetStrAttr(attrs, "type") != "git") return {};
|
if (maybeGetStrAttr(attrs, "type") != "git") return {};
|
||||||
|
|
||||||
|
for (auto & [name, value] : attrs)
|
||||||
|
if (name != "type" && name != "url" && name != "ref" && name != "rev")
|
||||||
|
throw Error("unsupported Git input attribute '%s'", name);
|
||||||
|
|
||||||
auto input = std::make_unique<GitInput>(parseURL(getStrAttr(attrs, "url")));
|
auto input = std::make_unique<GitInput>(parseURL(getStrAttr(attrs, "url")));
|
||||||
input->ref = maybeGetStrAttr(attrs, "ref");
|
if (auto ref = maybeGetStrAttr(attrs, "ref")) {
|
||||||
|
if (!std::regex_match(*ref, refRegex))
|
||||||
|
throw BadURL("invalid Git branch/tag name '%s'", *ref);
|
||||||
|
input->ref = *ref;
|
||||||
|
}
|
||||||
if (auto rev = maybeGetStrAttr(attrs, "rev"))
|
if (auto rev = maybeGetStrAttr(attrs, "rev"))
|
||||||
input->rev = Hash(*rev, htSHA1);
|
input->rev = Hash(*rev, htSHA1);
|
||||||
return input;
|
return input;
|
||||||
|
|
|
@ -166,8 +166,6 @@ struct GitHubInputScheme : InputScheme
|
||||||
|
|
||||||
for (auto &[name, value] : url.query) {
|
for (auto &[name, value] : url.query) {
|
||||||
if (name == "rev") {
|
if (name == "rev") {
|
||||||
if (!std::regex_match(value, revRegex))
|
|
||||||
throw BadURL("GitHub URL '%s' contains an invalid commit hash", url.url);
|
|
||||||
if (input->rev)
|
if (input->rev)
|
||||||
throw BadURL("GitHub URL '%s' contains multiple commit hashes", url.url);
|
throw BadURL("GitHub URL '%s' contains multiple commit hashes", url.url);
|
||||||
input->rev = Hash(value, htSHA1);
|
input->rev = Hash(value, htSHA1);
|
||||||
|
@ -193,6 +191,11 @@ struct GitHubInputScheme : InputScheme
|
||||||
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
||||||
{
|
{
|
||||||
if (maybeGetStrAttr(attrs, "type") != "github") return {};
|
if (maybeGetStrAttr(attrs, "type") != "github") return {};
|
||||||
|
|
||||||
|
for (auto & [name, value] : attrs)
|
||||||
|
if (name != "type" && name != "owner" && name != "repo" && name != "ref" && name != "rev")
|
||||||
|
throw Error("unsupported GitHub input attribute '%s'", name);
|
||||||
|
|
||||||
auto input = std::make_unique<GitHubInput>();
|
auto input = std::make_unique<GitHubInput>();
|
||||||
input->owner = getStrAttr(attrs, "owner");
|
input->owner = getStrAttr(attrs, "owner");
|
||||||
input->repo = getStrAttr(attrs, "repo");
|
input->repo = getStrAttr(attrs, "repo");
|
||||||
|
|
|
@ -123,6 +123,11 @@ struct IndirectInputScheme : InputScheme
|
||||||
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
||||||
{
|
{
|
||||||
if (maybeGetStrAttr(attrs, "type") != "indirect") return {};
|
if (maybeGetStrAttr(attrs, "type") != "indirect") return {};
|
||||||
|
|
||||||
|
for (auto & [name, value] : attrs)
|
||||||
|
if (name != "type" && name != "id" && name != "ref" && name != "rev")
|
||||||
|
throw Error("unsupported indirect input attribute '%s'", name);
|
||||||
|
|
||||||
auto input = std::make_unique<IndirectInput>();
|
auto input = std::make_unique<IndirectInput>();
|
||||||
input->id = getStrAttr(attrs, "id");
|
input->id = getStrAttr(attrs, "id");
|
||||||
input->ref = maybeGetStrAttr(attrs, "ref");
|
input->ref = maybeGetStrAttr(attrs, "ref");
|
||||||
|
|
|
@ -264,32 +264,39 @@ struct MercurialInputScheme : InputScheme
|
||||||
url.scheme != "hg+ssh" &&
|
url.scheme != "hg+ssh" &&
|
||||||
url.scheme != "hg+file") return nullptr;
|
url.scheme != "hg+file") return nullptr;
|
||||||
|
|
||||||
auto input = std::make_unique<MercurialInput>(url);
|
auto url2(url);
|
||||||
|
// FIXME: strip hg+
|
||||||
|
url2.query.clear();
|
||||||
|
|
||||||
input->url.query.clear();
|
Input::Attrs attrs;
|
||||||
|
attrs.emplace("type", "hg");
|
||||||
|
|
||||||
for (auto &[name, value] : url.query) {
|
for (auto &[name, value] : url.query) {
|
||||||
if (name == "rev") {
|
if (name == "rev" || name == "ref")
|
||||||
if (!std::regex_match(value, revRegex))
|
attrs.emplace(name, value);
|
||||||
throw BadURL("Mercurial URL '%s' contains an invalid commit hash", url.url);
|
else
|
||||||
input->rev = Hash(value, htSHA1);
|
url2.query.emplace(name, value);
|
||||||
}
|
|
||||||
else if (name == "ref") {
|
|
||||||
if (!std::regex_match(value, refRegex))
|
|
||||||
throw BadURL("Mercurial URL '%s' contains an invalid branch/tag name", url.url);
|
|
||||||
input->ref = value;
|
|
||||||
}
|
|
||||||
else input->url.query.insert_or_assign(name, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
attrs.emplace("url", url2.to_string());
|
||||||
|
|
||||||
|
return inputFromAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
||||||
{
|
{
|
||||||
if (maybeGetStrAttr(attrs, "type") != "hg") return {};
|
if (maybeGetStrAttr(attrs, "type") != "hg") return {};
|
||||||
|
|
||||||
|
for (auto & [name, value] : attrs)
|
||||||
|
if (name != "type" && name != "url" && name != "ref" && name != "rev")
|
||||||
|
throw Error("unsupported Mercurial input attribute '%s'", name);
|
||||||
|
|
||||||
auto input = std::make_unique<MercurialInput>(parseURL(getStrAttr(attrs, "url")));
|
auto input = std::make_unique<MercurialInput>(parseURL(getStrAttr(attrs, "url")));
|
||||||
input->ref = maybeGetStrAttr(attrs, "ref");
|
if (auto ref = maybeGetStrAttr(attrs, "ref")) {
|
||||||
|
if (!std::regex_match(*ref, refRegex))
|
||||||
|
throw BadURL("invalid Mercurial branch/tag name '%s'", *ref);
|
||||||
|
input->ref = *ref;
|
||||||
|
}
|
||||||
if (auto rev = maybeGetStrAttr(attrs, "rev"))
|
if (auto rev = maybeGetStrAttr(attrs, "rev"))
|
||||||
input->rev = Hash(*rev, htSHA1);
|
input->rev = Hash(*rev, htSHA1);
|
||||||
return input;
|
return input;
|
||||||
|
|
|
@ -110,6 +110,11 @@ struct TarballInputScheme : InputScheme
|
||||||
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
|
||||||
{
|
{
|
||||||
if (maybeGetStrAttr(attrs, "type") != "tarball") return {};
|
if (maybeGetStrAttr(attrs, "type") != "tarball") return {};
|
||||||
|
|
||||||
|
for (auto & [name, value] : attrs)
|
||||||
|
if (name != "type" && name != "url" && name != "hash" && name != "narHash")
|
||||||
|
throw Error("unsupported tarball input attribute '%s'", name);
|
||||||
|
|
||||||
auto input = std::make_unique<TarballInput>(parseURL(getStrAttr(attrs, "url")));
|
auto input = std::make_unique<TarballInput>(parseURL(getStrAttr(attrs, "url")));
|
||||||
if (auto hash = maybeGetStrAttr(attrs, "hash"))
|
if (auto hash = maybeGetStrAttr(attrs, "hash"))
|
||||||
// FIXME: require SRI hash.
|
// FIXME: require SRI hash.
|
||||||
|
|
|
@ -450,7 +450,8 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
||||||
if (hasPrefix(s, "nixpkgs.")) {
|
if (hasPrefix(s, "nixpkgs.")) {
|
||||||
bool static warned;
|
bool static warned;
|
||||||
warnOnce(warned, "the syntax 'nixpkgs.<attr>' is deprecated; use 'nixpkgs:<attr>' instead");
|
warnOnce(warned, "the syntax 'nixpkgs.<attr>' is deprecated; use 'nixpkgs:<attr>' instead");
|
||||||
result.push_back(std::make_shared<InstallableFlake>(*this, parseFlakeRef("flake:nixpkgs"),
|
result.push_back(std::make_shared<InstallableFlake>(*this,
|
||||||
|
FlakeRef::fromAttrs({{"type", "indirect"}, {"id", "nixpkgs"}}),
|
||||||
Strings{"legacyPackages." + settings.thisSystem.get() + "." + std::string(s, 8)}, Strings{}));
|
Strings{"legacyPackages." + settings.thisSystem.get() + "." + std::string(s, 8)}, Strings{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue