![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
Classes | |
| struct | Doc |
Public Types | |
| enum class | CopyLazyPaths : bool { PreserveLazy = false , Copy = true } |
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) | |
| Value * | allocValue () |
| LookupPath | getLookupPath () |
| SourcePath | rootPath (CanonPath path) |
| SourcePath | rootPath (std::string_view path) |
| SourcePath | storePath (const StorePath &path) |
| void | allowPathLegacy (const std::string &path) |
| void | allowPath (const StorePath &storePath) |
| void | allowClosure (const StorePath &storePath) |
| void | allowAndSetStorePathString (const StorePath &storePath, Value &v) |
| void | checkURI (const std::string &uri) |
| StorePath | mountInput (fetchers::Input &input, const fetchers::Input &originalInput, ref< SourceAccessor > accessor) |
| Expr * | parseExprFromFile (const SourcePath &path) |
| Expr * | parseExprFromFile (const SourcePath &path, const std::shared_ptr< StaticEnv > &staticEnv) |
| Expr * | parseExprFromString (std::string s, const SourcePath &basePath, const std::shared_ptr< StaticEnv > &staticEnv) |
| Expr * | parseExprFromString (std::string s, const SourcePath &basePath) |
| ExprAttrs * | parseReplBindings (std::string s, const SourcePath &basePath, const std::shared_ptr< StaticEnv > &staticEnv) |
| ExprAttrs * | parseReplBindings (std::string s, std::string errorSource, const SourcePath &basePath, const std::shared_ptr< StaticEnv > &staticEnv) |
| 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::shared_ptr< LookupPathResolvedState > | 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, std::string_view errorCtx) |
| void | evalAttrs (Env &env, Expr *e, Value &v, std::string_view errorCtx) |
| void | forceValue (Value &v, const 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, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings) |
| std::string_view | forceStringNoCtx (Value &v, const PosIdx pos, std::string_view errorCtx) |
| const Attr * | getAttr (Symbol attrSym, const Bindings *attrSet, 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) |
| template<typename Cb> | |
| auto | peelToStringOutPath (const PosIdx pos, Value &v, bool checkToStringReturn, Cb &&cb) -> std::invoke_result_t< Cb, Value *, bool > |
| void | ensureLazyPathCopied (const StorePath &path) |
| void | ensureLazyPathsCopied (const NixStringContext &context) |
| 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, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings) |
| 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 (const Value &fun) const |
| void | callFunction (Value &fun, std::span< Value *const > 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) |
| 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, std::span< Value *const > lists, const PosIdx pos, std::string_view errorCtx) |
| Concatenate values with an n-ary version of the ++ operator. | |
| void | maybePrintStats () |
| void | printStatistics () |
| bool | fullGC () |
| StringMap | realiseContext (const NixStringContext &context, StorePathSet *maybePaths=nullptr, bool isIFD=true) |
| SourcePath | realisePath (const PosIdx pos, Value &v, std::optional< SymlinkResolution > resolveSymlinks=SymlinkResolution::Full, CopyLazyPaths copyLazyPaths=CopyLazyPaths::PreserveLazy) |
| 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 |
| EvalMemory | mem |
| RepairFlag | repair |
| const ref< MountedSourceAccessor > | storeFS |
| const ref< SourceAccessor > | rootFS |
| const ref< MemorySourceAccessor > | corepkgsFS |
| const ref< MemorySourceAccessor > | internalFS |
| const SourcePath | derivationInternal |
| const SourcePath | importedDrvToDerivation |
| const ref< Store > | store |
| const ref< Store > | buildStore |
| const ref< fetchers::InputCache > | inputCache |
| ReplExitStatus(*) | debugRepl (ref< EvalState > es, const ValMap &extraEnv) |
| bool | debugStop |
| bool | inDebugger = false |
| int | trylevel |
| std::list< DebugTrace > | debugTraces |
| boost::unordered_flat_map< const Expr *, const std::shared_ptr< const StaticEnv > > | exprEnvs |
| std::map< const Hash, ref< eval_cache::EvalCache > > | evalCaches |
| Env & | baseEnv |
| const std::shared_ptr< StaticEnv > | staticBaseEnv |
| boost::unordered_flat_map< std::string, Value *, StringViewHash, std::equal_to<>, traceable_allocator< std::pair< const std::string, Value * > > > | internalPrimOps |
| std::vector< std::pair< std::string, Constant > > | constantInfos |
Static Public Attributes | |
| static constexpr StaticEvalSymbols | s = StaticEvalSymbols::create() |
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, CallSite callSite, Value *const *args, Value &v) |
| void | prim_match (EvalState &state, CallSite callSite, Value *const *args, Value &v) |
| void | prim_split (EvalState &state, CallSite callSite, Value *const *args, Value &v) |
| nix::EvalState::EvalState | ( | const LookupPath & | lookupPath, |
| ref< Store > | store, | ||
| const fetchers::Settings & | fetchSettings, | ||
| const EvalSettings & | settings, | ||
| std::shared_ptr< Store > | buildStore = nullptr ) |
| lookupPath | Only used during construction. |
| store | The store to use for instantiation |
| fetchSettings | Must outlive the lifetime of this EvalState! |
| settings | Must outlive the lifetime of this EvalState! |
| buildStore | The store to use for builds ("import from derivation", C API nix_string_realise) |
Check that the call depth is within limits, and increment it, until the returned object is destroyed.
|
inline |
A wrapper around EvalMemory::allocValue() to avoid code churn when it was introduced.
| void nix::EvalState::allowAndSetStorePathString | ( | const StorePath & | storePath, |
| Value & | v ) |
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 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::allowPathLegacy | ( | const std::string & | path | ) |
Allow access to a path.
Only for restrict eval: pure eval just whitelist store paths, never arbitrary paths.
| 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)
| void nix::EvalState::autoCallFunction | ( | const Bindings & | args, |
| Value & | fun, | ||
| Value & | res ) |
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, | ||
| const ExperimentalFeatureSettings & | xpSettings = experimentalFeatureSettings ) |
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.
| void nix::EvalState::ensureLazyPathCopied | ( | const StorePath & | path | ) |
For efficiency reasons, some store paths (as seen by the evaluator) in the storeFS at their content-addressed locations don't get copied to the store eagerly. This saves on needless I/O and possibly IPC if all the evaluator does is just evaluate nix expressions from those locations. This function copies such store objects to the store if they aren't already valid.
| void nix::EvalState::ensureLazyPathsCopied | ( | const NixStringContext & | context | ) |
Ensure that all NixStringContextElem::Opaque context elements get fetched to the store.
| 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.
| void nix::EvalState::eval | ( | Expr * | e, |
| Value & | v ) |
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.
| void nix::EvalState::forceFunction | ( | Value & | v, |
| const PosIdx | pos, | ||
| std::string_view | errorCtx ) |
| v | either lambda or primop |
| NixInt nix::EvalState::forceInt | ( | Value & | v, |
| const PosIdx | pos, | ||
| std::string_view | errorCtx ) |
Force v, and then verify that it has the expected type.
|
inline |
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.
| const Attr * nix::EvalState::getAttr | ( | Symbol | attrSym, |
| const Bindings * | attrSet, | ||
| std::string_view | errorCtx ) |
Get attribute from an attribute set and throw an error if it doesn't exist.
| Value * nix::EvalState::getBool | ( | bool | b | ) |
Return a boolean Value * without allocating.
| 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 | ) |
| 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.
| void nix::EvalState::mkStorePathString | ( | const StorePath & | storePath, |
| Value & | v ) |
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.
| StorePath nix::EvalState::mountInput | ( | fetchers::Input & | input, |
| const fetchers::Input & | originalInput, | ||
| ref< SourceAccessor > | accessor ) |
Mount an input on the Nix store.
| 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, | ||
| const std::shared_ptr< StaticEnv > & | staticEnv ) |
Parse a Nix expression from the specified string.
| ExprAttrs * nix::EvalState::parseReplBindings | ( | std::string | s, |
| const SourcePath & | basePath, | ||
| const std::shared_ptr< StaticEnv > & | staticEnv ) |
Parse REPL bindings from the specified string. Returns ExprAttrs with bindings to add to scope.
| std::invoke_result_t< Cb, Value *, bool > nix::EvalState::peelToStringOutPath | ( | const PosIdx | pos, |
| Value & | v, | ||
| bool | checkToStringReturn, | ||
| Cb && | cb ) -> std::invoke_result_t< Cb, Value *, bool > |
Force v and peel through __toString and outPath attributes repeatedly until reaching a terminal value: either a non-attrset, or an attrset that has neither attribute. Invoke cb(peeled, cameThroughToString) on that terminal value.
cb runs while the peel's call stack is still live, so errors it raises carry a trace reflecting which __toString and outPath attributes were traversed to reach peeled. Relying on the stack to preserve that context avoids the cost and complexity of tracking provenance in the hot path at runtime.
__toString takes precedence over a sibling outPath at each step, matching string-interpolation coercion in the language.
peeled is always a valid, forced Value; in the terminal-attrset case it is that attrset.
cameThroughToString is true iff the peel invoked at least one __toString.
With checkToStringReturn, if any __toString was traversed the terminal value must be a string, path, or external value; otherwise a TypeError is thrown before cb runs. Pure outPath peels are exempt.
| 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 |
| SourcePath nix::EvalState::realisePath | ( | const PosIdx | pos, |
| Value & | v, | ||
| std::optional< SymlinkResolution > | resolveSymlinks = SymlinkResolution::Full, | ||
| CopyLazyPaths | copyLazyPaths = CopyLazyPaths::PreserveLazy ) |
Coerce v to a path and realise it, i.e. build anything in the value's string context using realiseContext().
| copyLazyPaths | When encountering a lazy path (i.e. a string with Opaque context that's also "mounted" on the storeFS), fetch the store path to the store. |
| 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] | storePathsOutMaybe | all referenced store paths will be added to this set if it's not nullptr |
| EvalError | if the value is not a string, path or derivation (see coerceToString) |
| std::shared_ptr< EvalState::LookupPathResolvedState > 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 nullptr.
| SourcePath nix::EvalState::rootPath | ( | CanonPath | path | ) |
Return a SourcePath that refers to path in the root filesystem.
| SourcePath nix::EvalState::rootPath | ( | std::string_view | 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. |
| SourcePath nix::EvalState::storePath | ( | const StorePath & | path | ) |
Return a SourcePath that refers to path in the store.
For now, this has to also be within the root filesystem for backwards compat, but for Windows and maybe also pure eval, we'll probably want to do something different.
| 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 derivation.nix.
| boost::unordered_flat_map< std::string, Value *, StringViewHash, std::equal_to<>, 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.
| const std::shared_ptr<StaticEnv> nix::EvalState::staticBaseEnv |
The same, but used during parsing to resolve variables.
| const ref<MountedSourceAccessor> nix::EvalState::storeFS |
The accessor corresponding to store.