Classes | |
struct | Doc |
Public Member Functions | |
const std::shared_ptr< const StaticEnv > | getStaticEnv (const Expr &expr) const |
bool | canDebug () |
void | runDebugRepl (const Error *error) |
void | runDebugRepl (const Error *error, const Env &env, const Expr &expr) |
template<class T, typename... Args> | |
EvalErrorBuilder< T > & | error (const Args &... args) |
EvalState (const LookupPath &_lookupPath, ref< Store > store, const fetchers::Settings &fetchSettings, const EvalSettings &settings, std::shared_ptr< Store > buildStore=nullptr) | |
LookupPath | getLookupPath () |
SourcePath | rootPath (CanonPath path) |
SourcePath | rootPath (PathView path) |
void | allowPath (const Path &path) |
void | allowPath (const StorePath &storePath) |
void | allowClosure (const StorePath &storePath) |
void | allowAndSetStorePathString (const StorePath &storePath, Value &v) |
void | checkURI (const std::string &uri) |
Path | toRealPath (const Path &path, const NixStringContext &context) |
Expr * | parseExprFromFile (const SourcePath &path) |
Expr * | parseExprFromFile (const SourcePath &path, std::shared_ptr< StaticEnv > &staticEnv) |
Expr * | parseExprFromString (std::string s, const SourcePath &basePath, std::shared_ptr< StaticEnv > &staticEnv) |
Expr * | parseExprFromString (std::string s, const SourcePath &basePath) |
Expr * | parseStdin () |
void | evalFile (const SourcePath &path, Value &v, bool mustBeTrivial=false) |
void | resetFileCache () |
SourcePath | findFile (const std::string_view path) |
SourcePath | findFile (const LookupPath &lookupPath, const std::string_view path, const PosIdx pos=noPos) |
std::optional< SourcePath > | resolveLookupPathPath (const LookupPath::Path &elem, bool initAccessControl=false) |
void | eval (Expr *e, Value &v) |
bool | evalBool (Env &env, Expr *e) |
bool | evalBool (Env &env, Expr *e, const PosIdx pos, std::string_view errorCtx) |
void | evalAttrs (Env &env, Expr *e, Value &v, const PosIdx pos, std::string_view errorCtx) |
void | forceValue (Value &v, const PosIdx pos) |
void | tryFixupBlackHolePos (Value &v, PosIdx pos) |
void | forceValueDeep (Value &v) |
NixInt | forceInt (Value &v, const PosIdx pos, std::string_view errorCtx) |
NixFloat | forceFloat (Value &v, const PosIdx pos, std::string_view errorCtx) |
bool | forceBool (Value &v, const PosIdx pos, std::string_view errorCtx) |
void | forceAttrs (Value &v, const PosIdx pos, std::string_view errorCtx) |
template<typename Callable> | |
void | forceAttrs (Value &v, Callable getPos, std::string_view errorCtx) |
void | forceList (Value &v, const PosIdx pos, std::string_view errorCtx) |
void | forceFunction (Value &v, const PosIdx pos, std::string_view errorCtx) |
std::string_view | forceString (Value &v, const PosIdx pos, std::string_view errorCtx) |
std::string_view | forceString (Value &v, NixStringContext &context, const PosIdx pos, std::string_view errorCtx) |
std::string_view | forceStringNoCtx (Value &v, const PosIdx pos, std::string_view errorCtx) |
template<typename... Args> | |
void | addErrorTrace (Error &e, const Args &... formatArgs) const |
template<typename... Args> | |
void | addErrorTrace (Error &e, const PosIdx pos, const Args &... formatArgs) const |
bool | isDerivation (Value &v) |
std::optional< std::string > | tryAttrsToString (const PosIdx pos, Value &v, NixStringContext &context, bool coerceMore=false, bool copyToStore=true) |
BackedStringView | coerceToString (const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx, bool coerceMore=false, bool copyToStore=true, bool canonicalizePath=true) |
StorePath | copyPathToStore (NixStringContext &context, const SourcePath &path) |
SourcePath | coerceToPath (const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx) |
StorePath | coerceToStorePath (const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx) |
std::pair< SingleDerivedPath, std::string_view > | coerceToSingleDerivedPathUnchecked (const PosIdx pos, Value &v, std::string_view errorCtx) |
SingleDerivedPath | coerceToSingleDerivedPath (const PosIdx pos, Value &v, std::string_view errorCtx) |
Value & | getBuiltin (const std::string &name) |
Value & | getBuiltins () |
std::optional< Doc > | getDoc (Value &v) |
CallDepth | addCallDepth (const PosIdx pos) |
bool | eqValues (Value &v1, Value &v2, const PosIdx pos, std::string_view errorCtx) |
void | assertEqValues (Value &v1, Value &v2, const PosIdx pos, std::string_view errorCtx) |
bool | isFunctor (Value &fun) |
void | callFunction (Value &fun, std::span< Value * > args, Value &vRes, const PosIdx pos) |
void | callFunction (Value &fun, Value &arg, Value &vRes, const PosIdx pos) |
void | autoCallFunction (const Bindings &args, Value &fun, Value &res) |
Value * | allocValue () |
Env & | allocEnv (size_t size) |
Bindings * | allocBindings (size_t capacity) |
BindingsBuilder | buildBindings (size_t capacity) |
ListBuilder | buildList (size_t size) |
Value * | getBool (bool b) |
void | mkThunk_ (Value &v, Expr *expr) |
void | mkPos (Value &v, PosIdx pos) |
void | mkStorePathString (const StorePath &storePath, Value &v) |
void | mkOutputString (Value &value, const SingleDerivedPath::Built &b, std::optional< StorePath > optStaticOutputPath, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings) |
void | mkSingleDerivedPathString (const SingleDerivedPath &p, Value &v) |
void | concatLists (Value &v, size_t nrLists, Value *const *lists, const PosIdx pos, std::string_view errorCtx) |
void | maybePrintStats () |
void | printStatistics () |
bool | fullGC () |
StringMap | realiseContext (const NixStringContext &context, StorePathSet *maybePaths=nullptr, bool isIFD=true) |
std::string | realiseString (Value &str, StorePathSet *storePathsOutMaybe, bool isIFD=true, const PosIdx pos=noPos) |
bool | callPathFilter (Value *filterFun, const SourcePath &path, PosIdx pos) |
DocComment | getDocCommentForPos (PosIdx pos) |
Public Attributes | |
const fetchers::Settings & | fetchSettings |
const EvalSettings & | settings |
SymbolTable | symbols |
PosTable | positions |
const Symbol | sWith |
const Symbol | sOutPath |
const Symbol | sDrvPath |
const Symbol | sType |
const Symbol | sMeta |
const Symbol | sName |
const Symbol | sValue |
const Symbol | sSystem |
const Symbol | sOverrides |
const Symbol | sOutputs |
const Symbol | sOutputName |
const Symbol | sIgnoreNulls |
const Symbol | sFile |
const Symbol | sLine |
const Symbol | sColumn |
const Symbol | sFunctor |
const Symbol | sToString |
const Symbol | sRight |
const Symbol | sWrong |
const Symbol | sStructuredAttrs |
const Symbol | sAllowedReferences |
const Symbol | sAllowedRequisites |
const Symbol | sDisallowedReferences |
const Symbol | sDisallowedRequisites |
const Symbol | sMaxSize |
const Symbol | sMaxClosureSize |
const Symbol | sBuilder |
const Symbol | sArgs |
const Symbol | sContentAddressed |
const Symbol | sImpure |
const Symbol | sOutputHash |
const Symbol | sOutputHashAlgo |
const Symbol | sOutputHashMode |
const Symbol | sRecurseForDerivations |
const Symbol | sDescription |
const Symbol | sSelf |
const Symbol | sEpsilon |
const Symbol | sStartSet |
const Symbol | sOperator |
const Symbol | sKey |
const Symbol | sPath |
const Symbol | sPrefix |
const Symbol | sOutputSpecified |
const Expr::AstSymbols | exprSymbols |
RepairFlag | repair |
Bindings | emptyBindings |
Value | vEmptyList |
Value | vNull |
Value | vTrue |
Value | vFalse |
Value | vStringRegular |
Value | vStringDirectory |
Value | vStringSymlink |
Value | vStringUnknown |
const ref< SourceAccessor > | rootFS |
const ref< MemorySourceAccessor > | corepkgsFS |
const ref< MemorySourceAccessor > | internalFS |
const SourcePath | derivationInternal |
const SourcePath | callFlakeInternal |
const ref< Store > | store |
const ref< Store > | buildStore |
RootValue | vImportedDrvToDerivation = nullptr |
ReplExitStatus(* | debugRepl )(ref< EvalState > es, const ValMap &extraEnv) |
bool | debugStop |
bool | inDebugger = false |
int | trylevel |
std::list< DebugTrace > | debugTraces |
std::map< const Expr *, const std::shared_ptr< const StaticEnv > > | exprEnvs |
std::map< const Hash, ref< eval_cache::EvalCache > > | evalCaches |
Env & | baseEnv |
std::shared_ptr< StaticEnv > | staticBaseEnv |
std::unordered_map< std::string, Value *, std::hash< std::string >, std::equal_to< std::string >, traceable_allocator< std::pair< const std::string, Value * > > > | internalPrimOps |
std::vector< std::pair< std::string, Constant > > | constantInfos |
Friends | |
struct | ExprVar |
struct | ExprAttrs |
struct | ExprLet |
struct | ExprOpUpdate |
struct | ExprOpConcatLists |
struct | ExprString |
struct | ExprInt |
struct | ExprFloat |
struct | ExprPath |
struct | ExprSelect |
struct | Value |
class | ListBuilder |
void | prim_getAttr (EvalState &state, const PosIdx pos, Value **args, Value &v) |
void | prim_match (EvalState &state, const PosIdx pos, Value **args, Value &v) |
void | prim_split (EvalState &state, const PosIdx pos, Value **args, Value &v) |
Check that the call depth is within limits, and increment it, until the returned object is destroyed.
|
inline |
Allocation primitives.
Allow access to a store path and return it as a string.
void nix::EvalState::allowClosure | ( | const StorePath & | storePath | ) |
Allow access to the closure of a store path.
void nix::EvalState::allowPath | ( | const Path & | path | ) |
Allow access to a path.
void nix::EvalState::allowPath | ( | const StorePath & | storePath | ) |
Allow access to a store path. Note that this gets remapped to the real store path if store
is a chroot store.
void nix::EvalState::assertEqValues | ( | Value & | v1, |
Value & | v2, | ||
const PosIdx | pos, | ||
std::string_view | errorCtx ) |
Like eqValues
, but throws an AssertionError
if not equal.
WARNING: Callers should call eqValues
first and report if assertEqValues
behaves incorrectly. (e.g. if it doesn't throw if eqValues returns false or vice versa)
Automatically call a function for which each argument has a default value or has a binding in the args
map.
bool nix::EvalState::canDebug | ( | ) |
Whether a debug repl can be started. If false
, runDebugRepl(error)
will return without starting a repl.
SourcePath nix::EvalState::coerceToPath | ( | const PosIdx | pos, |
Value & | v, | ||
NixStringContext & | context, | ||
std::string_view | errorCtx ) |
Path coercion.
Converts strings, paths and derivations to a path. The result is guaranteed to be a canonicalised, absolute path. Nothing is copied to the store.
SingleDerivedPath nix::EvalState::coerceToSingleDerivedPath | ( | const PosIdx | pos, |
Value & | v, | ||
std::string_view | errorCtx ) |
Coerce to SingleDerivedPath
.
Must be a string which is either a literal store path or a "placeholder (see DownstreamPlaceholder
).
Even more importantly, the string context must be exactly one element, which is either a NixStringContextElem::Opaque
or NixStringContextElem::Built
. (NixStringContextEleme::DrvDeep
is not permitted).
The string is parsed based on the context — the context is the source of truth, and ultimately tells us what we want, and then we ensure the string corresponds to it.
std::pair< SingleDerivedPath, std::string_view > nix::EvalState::coerceToSingleDerivedPathUnchecked | ( | const PosIdx | pos, |
Value & | v, | ||
std::string_view | errorCtx ) |
Part of coerceToSingleDerivedPath()
without any store IO which is exposed for unit testing only.
StorePath nix::EvalState::coerceToStorePath | ( | const PosIdx | pos, |
Value & | v, | ||
NixStringContext & | context, | ||
std::string_view | errorCtx ) |
Like coerceToPath, but the result must be a store path.
BackedStringView nix::EvalState::coerceToString | ( | const PosIdx | pos, |
Value & | v, | ||
NixStringContext & | context, | ||
std::string_view | errorCtx, | ||
bool | coerceMore = false, | ||
bool | copyToStore = true, | ||
bool | canonicalizePath = true ) |
String coercion.
Converts strings, paths and derivations to a string. If coerceMore
is set, also converts nulls, integers, booleans and lists to a string. If copyToStore
is set, referenced paths are copied to the Nix store as a side effect.
bool nix::EvalState::eqValues | ( | Value & | v1, |
Value & | v2, | ||
const PosIdx | pos, | ||
std::string_view | errorCtx ) |
Do a deep equality test between two values. That is, list elements and attributes are compared recursively.
Evaluate an expression to normal form
[out] | v | The resulting is stored here. |
Evaluation the expression, then verify that it has the expected type.
void nix::EvalState::evalFile | ( | const SourcePath & | path, |
Value & | v, | ||
bool | mustBeTrivial = false ) |
Evaluate an expression read from the given file to normal form. Optionally enforce that the top-level expression is trivial (i.e. doesn't require arbitrary computation).
SourcePath nix::EvalState::findFile | ( | const std::string_view | path | ) |
Look up a file in the search path.
v | either lambda or primop |
Force v
, and then verify that it has the expected type.
If v
is a thunk, enter it and overwrite v
with the result of the evaluation of the thunk. If v
is a delayed function application, call the function and overwrite v
with the result. Otherwise, this is a no-op.
void nix::EvalState::forceValueDeep | ( | Value & | v | ) |
Force a value, then recursively force list elements and attributes.
bool nix::EvalState::fullGC | ( | ) |
Perform a full memory garbage collection - not incremental.
Value & nix::EvalState::getBuiltin | ( | const std::string & | name | ) |
Retrieve a specific builtin, equivalent to evaluating builtins.${name}
.
name | The attribute name of the builtin to retrieve. |
EvalError | if the builtin does not exist. |
Value & nix::EvalState::getBuiltins | ( | ) |
Retrieve the builtins
attrset, equivalent to evaluating the reference builtins
. Always returns an attribute set value.
std::optional< EvalState::Doc > nix::EvalState::getDoc | ( | Value & | v | ) |
Retrieve the documentation for a value. This will evaluate the value if it is a thunk, and it will partially apply __functor if applicable.
v | The value to get the documentation for. |
bool nix::EvalState::isDerivation | ( | Value & | v | ) |
v
denotes a derivation (i.e. a set with attribute type = "derivation"
). void nix::EvalState::maybePrintStats | ( | ) |
Print statistics, if enabled.
Performs a full memory GC before printing the statistics, so that the GC statistics are more accurate.
void nix::EvalState::mkOutputString | ( | Value & | value, |
const SingleDerivedPath::Built & | b, | ||
std::optional< StorePath > | optStaticOutputPath, | ||
const ExperimentalFeatureSettings & | xpSettings = experimentalFeatureSettings ) |
Create a string representing a SingleDerivedPath::Built
.
The string is the printed store path with a context containing a single NixStringContextElem::Built
element of the drv path and output name.
value | Value we are settings |
b | the drv whose output we are making a string for, and the output |
optStaticOutputPath | Optional output path for that string. Must be passed if and only if output store object is input-addressed or fixed output. Will be printed to form string if passed, otherwise a placeholder will be used (see DownstreamPlaceholder ). |
xpSettings | Stop-gap to avoid globals during unit tests. |
void nix::EvalState::mkSingleDerivedPathString | ( | const SingleDerivedPath & | p, |
Value & | v ) |
Create a string representing a SingleDerivedPath
.
A combination of mkStorePathString
and mkOutputString
.
Create a string representing a store path.
The string is the printed store path with a context containing a single NixStringContextElem::Opaque
element of that store path.
Expr * nix::EvalState::parseExprFromFile | ( | const SourcePath & | path | ) |
Parse a Nix expression from the specified file.
Expr * nix::EvalState::parseExprFromString | ( | std::string | s, |
const SourcePath & | basePath, | ||
std::shared_ptr< StaticEnv > & | staticEnv ) |
Parse a Nix expression from the specified string.
void nix::EvalState::printStatistics | ( | ) |
Print statistics, unconditionally, cheaply, without performing a GC first.
|
nodiscard |
Realise the given context
[in] | context | the context to realise |
[out] | maybePaths | if not nullptr, all built or referenced store paths will be added to this set |
std::string nix::EvalState::realiseString | ( | Value & | str, |
StorePathSet * | storePathsOutMaybe, | ||
bool | isIFD = true, | ||
const PosIdx | pos = noPos ) |
Realise the given string with context, and return the string with outputs instead of downstream output placeholders.
[in] | str | the string to realise |
[out] | paths | all referenced store paths will be added to this set |
EvalError | if the value is not a string, path or derivation (see coerceToString ) |
std::optional< SourcePath > nix::EvalState::resolveLookupPathPath | ( | const LookupPath::Path & | elem, |
bool | initAccessControl = false ) |
Try to resolve a search path value (not the optional key part).
If the specified search path element is a URI, download it.
If it is not found, return std::nullopt
.
SourcePath nix::EvalState::rootPath | ( | CanonPath | path | ) |
Return a SourcePath
that refers to path
in the root filesystem.
SourcePath nix::EvalState::rootPath | ( | PathView | path | ) |
Variant which accepts relative paths too.
void nix::EvalState::runDebugRepl | ( | const Error * | error | ) |
Use front of debugTraces
; see runDebugRepl(error,env,expr)
Run a debug repl with the given error, environment and expression.
error | The error to debug, may be nullptr. |
env | The environment to debug, matching the expression. |
expr | The expression to debug, matching the environment. |
When using a diverted store and 'path' is in the Nix store, map 'path' to the diverted location (e.g. /nix/store/foo is mapped to /home/alice/my-nix/nix/store/foo). However, this is only done if the context is not empty, since otherwise we're probably trying to read from the actual /nix/store. This is intended to distinguish between import-from-derivation and sources stored in the actual /nix/store.
Env& nix::EvalState::baseEnv |
The base environment, containing the builtin functions and values.
std::vector<std::pair<std::string, Constant> > nix::EvalState::constantInfos |
Name and documentation about every constant.
Constants from primops are hard to crawl, and their docs will go here too.
const ref<MemorySourceAccessor> nix::EvalState::corepkgsFS |
The in-memory filesystem for <nix/...> paths.
std::map<const Hash, ref<eval_cache::EvalCache> > nix::EvalState::evalCaches |
A cache for evaluation caches, so as to reuse the same root value if possible
const ref<MemorySourceAccessor> nix::EvalState::internalFS |
In-memory filesystem for internal, non-user-callable Nix expressions like call-flake.nix.
std::unordered_map<std::string, Value *, std::hash<std::string>, std::equal_to<std::string>, traceable_allocator<std::pair<const std::string, Value *> > > nix::EvalState::internalPrimOps |
Internal primops not exposed to the user.
RepairFlag nix::EvalState::repair |
If set, force copying files to the Nix store even if they already exist there.
const ref<SourceAccessor> nix::EvalState::rootFS |
The accessor for the root filesystem.
std::shared_ptr<StaticEnv> nix::EvalState::staticBaseEnv |
The same, but used during parsing to resolve variables.
Value nix::EvalState::vEmptyList |
Empty list constant.
Value nix::EvalState::vFalse |
true
constant.
This is not a singleton. Pointer equality is not sufficient.
Value nix::EvalState::vNull |
null
constant.
This is not a singleton. Pointer equality is not sufficient.
Value nix::EvalState::vStringDirectory |
"directory"
Value nix::EvalState::vStringRegular |
"regular"
Value nix::EvalState::vStringSymlink |
"symlink"
Value nix::EvalState::vStringUnknown |
"unknown"
Value nix::EvalState::vTrue |
true
constant.
This is not a singleton. Pointer equality is not sufficient.