Skip to content

Commit

Permalink
nixd/nix: use _type to determine whether the attrset is an option (#92
Browse files Browse the repository at this point in the history
)
  • Loading branch information
inclyc committed Jun 8, 2023
2 parents 4c85058 + c460e09 commit 8c3351e
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/nixd/src/nix/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ bool isOption(EvalState &State, Value &V) {
State.forceValue(V, noPos);
if (V.type() != ValueType::nAttrs)
return false;
bool HasDesc = false;
bool HasType = false;
for (auto Attr : *V.attrs) {
auto Name = State.symbols[Attr.name];
if (std::string_view(Name) == "description")
HasDesc = true;
if (std::string_view(Name) == "type")
HasType = true;
}
return HasType && HasDesc;

// https://github.com/NixOS/nixpkgs/blob/58ca986543b591a8269cbce3328293ca8d64480f/lib/options.nix#L89
auto S = attrPathStr(State, V, "_type");
return S && S.value() == "option";
};

std::optional<std::string> attrPathStr(nix::EvalState &State, nix::Value &V,
Expand Down

0 comments on commit 8c3351e

Please sign in to comment.