nixd
Loading...
Searching...
No Matches
Value.h
Go to the documentation of this file.
1#include <nix/eval.hh>
2
3namespace nixt {
4
5std::optional<nix::Value> getField(nix::EvalState &State, nix::Value &V,
6 std::string_view Field);
7std::optional<std::string_view>
8getFieldString(nix::EvalState &State, nix::Value &V, std::string_view Field);
9
10/// \brief Check if value \p V is an attrset, has the field, and equals to \p
11/// Pred
12bool checkField(nix::EvalState &State, nix::Value &V, std::string_view Field,
13 std::string_view Pred);
14
15/// \brief Check if value is an attrset, and it's "_type" equals to \p Pred
16bool checkType(nix::EvalState &State, nix::Value &V, std::string_view Pred);
17
18bool isOption(nix::EvalState &State, nix::Value &V);
19
20bool isDerivation(nix::EvalState &State, nix::Value &V);
21
22std::string attrPathStr(nix::EvalState &State, nix::Value &V,
23 const std::string &AttrPath);
24
25/// \brief Transform a vector of string into a vector of nix symbols.
26std::vector<nix::Symbol> toSymbols(nix::SymbolTable &STable,
27 const std::vector<std::string> &Names);
28
29/// \copydoc toSymbols
30std::vector<nix::Symbol> toSymbols(nix::SymbolTable &STable,
31 const std::vector<std::string_view> &Names);
32
33/// \brief Select attribute \p Attr
34nix::Value &selectAttr(nix::EvalState &State, nix::Value &V, nix::Symbol Attr);
35
36nix::Value &selectOption(nix::EvalState &State, nix::Value &V,
37 nix::Symbol Attr);
38
39/// \brief Given an attrpath in nix::Value \p V, select it
40nix::Value &selectAttrPath(nix::EvalState &State, nix::Value &V,
41 std::vector<nix::Symbol>::const_iterator Begin,
42 std::vector<nix::Symbol>::const_iterator End);
43
44/// \brief Select the option declaration list, \p V, dive into "submodules".
45nix::Value selectOptions(nix::EvalState &State, nix::Value &V,
46 std::vector<nix::Symbol>::const_iterator Begin,
47 std::vector<nix::Symbol>::const_iterator End);
48
49inline nix::Value selectOptions(nix::EvalState &State, nix::Value &V,
50 const std::vector<nix::Symbol> &AttrPath) {
51 return selectOptions(State, V, AttrPath.begin(), AttrPath.end());
52}
53
54/// \copydoc selectAttrPath
55inline nix::Value &selectSymbols(nix::EvalState &State, nix::Value &V,
56 const std::vector<nix::Symbol> &AttrPath) {
57 return selectAttrPath(State, V, AttrPath.begin(), AttrPath.end());
58}
59
60/// \copydoc selectAttrPath
61inline nix::Value &selectStrings(nix::EvalState &State, nix::Value &V,
62 const std::vector<std::string> &AttrPath) {
63 return selectSymbols(State, V, toSymbols(State.symbols, AttrPath));
64}
65
66/// \copydoc selectAttrPath
67inline nix::Value &
68selectStringViews(nix::EvalState &State, nix::Value &V,
69 const std::vector<std::string_view> &AttrPath) {
70 return selectSymbols(State, V, toSymbols(State.symbols, AttrPath));
71}
72
73} // namespace nixt
Access EvalCache in nix::EvalState.
Definition ArrayRef.h:7
nix::Value & selectSymbols(nix::EvalState &State, nix::Value &V, const std::vector< nix::Symbol > &AttrPath)
Given an attrpath in nix::Value V, select it.
Definition Value.h:55
std::optional< std::string_view > getFieldString(nix::EvalState &State, nix::Value &V, std::string_view Field)
Definition Value.cpp:23
nix::Value & selectAttrPath(nix::EvalState &State, nix::Value &V, std::vector< nix::Symbol >::const_iterator Begin, std::vector< nix::Symbol >::const_iterator End)
Given an attrpath in nix::Value V, select it.
Definition Value.cpp:102
bool isOption(nix::EvalState &State, nix::Value &V)
Definition Value.cpp:46
bool checkField(nix::EvalState &State, nix::Value &V, std::string_view Field, std::string_view Pred)
Check if value V is an attrset, has the field, and equals to Pred.
Definition Value.cpp:36
bool checkType(nix::EvalState &State, nix::Value &V, std::string_view Pred)
Check if value is an attrset, and it's "_type" equals to Pred.
Definition Value.cpp:41
std::string attrPathStr(nix::EvalState &State, nix::Value &V, const std::string &AttrPath)
Definition Value.cpp:54
nix::Value & selectOption(nix::EvalState &State, nix::Value &V, nix::Symbol Attr)
nix::Value & selectStrings(nix::EvalState &State, nix::Value &V, const std::vector< std::string > &AttrPath)
Given an attrpath in nix::Value V, select it.
Definition Value.h:61
bool isDerivation(nix::EvalState &State, nix::Value &V)
Definition Value.cpp:50
nix::Value selectOptions(nix::EvalState &State, nix::Value &V, std::vector< nix::Symbol >::const_iterator Begin, std::vector< nix::Symbol >::const_iterator End)
Select the option declaration list, V, dive into "submodules".
Definition Value.cpp:158
std::vector< nix::Symbol > toSymbols(nix::SymbolTable &STable, const std::vector< std::string > &Names)
Transform a vector of string into a vector of nix symbols.
Definition Value.cpp:63
nix::Value & selectAttr(nix::EvalState &State, nix::Value &V, nix::Symbol Attr)
Select attribute Attr.
Definition Value.cpp:84
std::optional< nix::Value > getField(nix::EvalState &State, nix::Value &V, std::string_view Field)
Definition Value.cpp:10
nix::Value & selectStringViews(nix::EvalState &State, nix::Value &V, const std::vector< std::string_view > &AttrPath)
Given an attrpath in nix::Value V, select it.
Definition Value.h:68