Allow Flake inputs to accept boolean and integer attributes

I believe that this makes it possible to do things like
Git inputs with submodules, but it also likely applies
to other input types from libfetchers.
This commit is contained in:
Danila Fedorin 2021-01-08 01:53:57 +00:00
parent 920e6a6920
commit 93f1678ec6

View file

@ -120,11 +120,16 @@ static FlakeInput parseFlakeInput(EvalState & state,
expectType(state, nString, *attr.value, *attr.pos); expectType(state, nString, *attr.value, *attr.pos);
input.follows = parseInputPath(attr.value->string.s); input.follows = parseInputPath(attr.value->string.s);
} else { } else {
if (attr.value->type() == nString) if (attr.value->type() == nString) {
attrs.emplace(attr.name, attr.value->string.s); attrs.emplace(attr.name, attr.value->string.s);
else } else if (attr.value->type() == nBool) {
throw TypeError("flake input attribute '%s' is %s while a string is expected", attrs.emplace(attr.name, Explicit<bool>{ attr.value->boolean });
} else if (attr.value->type() == nInt) {
attrs.emplace(attr.name, attr.value->integer);
} else {
throw TypeError("flake input attribute '%s' is %s while a string, boolean, or integer is expected",
attr.name, showType(*attr.value)); attr.name, showType(*attr.value));
}
} }
} catch (Error & e) { } catch (Error & e) {
e.addTrace(*attr.pos, hintfmt("in flake attribute '%s'", attr.name)); e.addTrace(*attr.pos, hintfmt("in flake attribute '%s'", attr.name));