Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
nix::EvalState Class Reference
Inheritance diagram for nix::EvalState:

Classes

struct  Doc
 

Public Member Functions

const std::shared_ptr< const StaticEnvgetStaticEnv (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)
 
ExprparseExprFromFile (const SourcePath &path)
 
ExprparseExprFromFile (const SourcePath &path, std::shared_ptr< StaticEnv > &staticEnv)
 
ExprparseExprFromString (std::string s, const SourcePath &basePath, std::shared_ptr< StaticEnv > &staticEnv)
 
ExprparseExprFromString (std::string s, const SourcePath &basePath)
 
ExprparseStdin ()
 
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< SourcePathresolveLookupPathPath (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)
 
ValuegetBuiltin (const std::string &name)
 
ValuegetBuiltins ()
 
std::optional< DocgetDoc (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)
 
ValueallocValue ()
 
EnvallocEnv (size_t size)
 
BindingsallocBindings (size_t capacity)
 
BindingsBuilder buildBindings (size_t capacity)
 
ListBuilder buildList (size_t size)
 
ValuegetBool (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::SettingsfetchSettings
 
const EvalSettingssettings
 
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< SourceAccessorrootFS
 
const ref< MemorySourceAccessorcorepkgsFS
 
const ref< MemorySourceAccessorinternalFS
 
const SourcePath derivationInternal
 
const SourcePath callFlakeInternal
 
const ref< Storestore
 
const ref< StorebuildStore
 
RootValue vImportedDrvToDerivation = nullptr
 
ReplExitStatus(* debugRepl )(ref< EvalState > es, const ValMap &extraEnv)
 
bool debugStop
 
bool inDebugger = false
 
int trylevel
 
std::list< DebugTracedebugTraces
 
std::map< const Expr *, const std::shared_ptr< const StaticEnv > > exprEnvs
 
std::map< const Hash, ref< eval_cache::EvalCache > > evalCaches
 
EnvbaseEnv
 
std::shared_ptr< StaticEnvstaticBaseEnv
 
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)
 

Member Function Documentation

◆ addCallDepth()

CallDepth nix::EvalState::addCallDepth ( const PosIdx pos)
inline

Check that the call depth is within limits, and increment it, until the returned object is destroyed.

◆ allocValue()

Value * nix::EvalState::allocValue ( )
inline

Allocation primitives.

◆ allowAndSetStorePathString()

void nix::EvalState::allowAndSetStorePathString ( const StorePath & storePath,
Value & v )

Allow access to a store path and return it as a string.

◆ allowClosure()

void nix::EvalState::allowClosure ( const StorePath & storePath)

Allow access to the closure of a store path.

◆ allowPath() [1/2]

void nix::EvalState::allowPath ( const Path & path)

Allow access to a path.

◆ allowPath() [2/2]

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.

◆ assertEqValues()

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)

◆ autoCallFunction()

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.

◆ canDebug()

bool nix::EvalState::canDebug ( )

Whether a debug repl can be started. If false, runDebugRepl(error) will return without starting a repl.

◆ coerceToPath()

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.

◆ coerceToSingleDerivedPath()

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.

◆ coerceToSingleDerivedPathUnchecked()

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.

◆ coerceToStorePath()

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.

◆ coerceToString()

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.

◆ eqValues()

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.

◆ eval()

void nix::EvalState::eval ( Expr * e,
Value & v )

Evaluate an expression to normal form

Parameters
[out]vThe resulting is stored here.

◆ evalBool()

bool nix::EvalState::evalBool ( Env & env,
Expr * e )
inline

Evaluation the expression, then verify that it has the expected type.

◆ evalFile()

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).

◆ findFile()

SourcePath nix::EvalState::findFile ( const std::string_view path)

Look up a file in the search path.

◆ forceFunction()

void nix::EvalState::forceFunction ( Value & v,
const PosIdx pos,
std::string_view errorCtx )
Parameters
veither lambda or primop

◆ forceInt()

NixInt nix::EvalState::forceInt ( Value & v,
const PosIdx pos,
std::string_view errorCtx )

Force v, and then verify that it has the expected type.

◆ forceValue()

void nix::EvalState::forceValue ( Value & v,
const PosIdx pos )
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.

◆ forceValueDeep()

void nix::EvalState::forceValueDeep ( Value & v)

Force a value, then recursively force list elements and attributes.

◆ fullGC()

bool nix::EvalState::fullGC ( )

Perform a full memory garbage collection - not incremental.

Returns
true if Nix was built with GC and a GC was performed, false if not. The return value is currently not thread safe - just the return value.

◆ getBool()

Value * nix::EvalState::getBool ( bool b)

Return a boolean Value * without allocating.

◆ getBuiltin()

Value & nix::EvalState::getBuiltin ( const std::string & name)

Retrieve a specific builtin, equivalent to evaluating builtins.${name}.

Parameters
nameThe attribute name of the builtin to retrieve.
Exceptions
EvalErrorif the builtin does not exist.

◆ getBuiltins()

Value & nix::EvalState::getBuiltins ( )

Retrieve the builtins attrset, equivalent to evaluating the reference builtins. Always returns an attribute set value.

◆ getDoc()

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.

Parameters
vThe value to get the documentation for.

◆ isDerivation()

bool nix::EvalState::isDerivation ( Value & v)
Returns
true iff the value v denotes a derivation (i.e. a set with attribute type = "derivation").

◆ maybePrintStats()

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.

◆ mkOutputString()

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.

Parameters
valueValue we are settings
bthe drv whose output we are making a string for, and the output
optStaticOutputPathOptional 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).
xpSettingsStop-gap to avoid globals during unit tests.

◆ mkSingleDerivedPathString()

void nix::EvalState::mkSingleDerivedPathString ( const SingleDerivedPath & p,
Value & v )

Create a string representing a SingleDerivedPath.

A combination of mkStorePathString and mkOutputString.

◆ mkStorePathString()

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.

◆ parseExprFromFile()

Expr * nix::EvalState::parseExprFromFile ( const SourcePath & path)

Parse a Nix expression from the specified file.

◆ parseExprFromString()

Expr * nix::EvalState::parseExprFromString ( std::string s,
const SourcePath & basePath,
std::shared_ptr< StaticEnv > & staticEnv )

Parse a Nix expression from the specified string.

◆ printStatistics()

void nix::EvalState::printStatistics ( )

Print statistics, unconditionally, cheaply, without performing a GC first.

◆ realiseContext()

StringMap nix::EvalState::realiseContext ( const NixStringContext & context,
StorePathSet * maybePaths = nullptr,
bool isIFD = true )
nodiscard

Realise the given context

Parameters
[in]contextthe context to realise
[out]maybePathsif not nullptr, all built or referenced store paths will be added to this set
Returns
a mapping from the placeholders used to construct the associated value to their final store path.

◆ realiseString()

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.

Parameters
[in]strthe string to realise
[out]pathsall referenced store paths will be added to this set
Returns
the realised string
Exceptions
EvalErrorif the value is not a string, path or derivation (see coerceToString)

◆ resolveLookupPathPath()

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.

◆ rootPath() [1/2]

SourcePath nix::EvalState::rootPath ( CanonPath path)

Return a SourcePath that refers to path in the root filesystem.

◆ rootPath() [2/2]

SourcePath nix::EvalState::rootPath ( PathView path)

Variant which accepts relative paths too.

◆ runDebugRepl() [1/2]

void nix::EvalState::runDebugRepl ( const Error * error)

Use front of debugTraces; see runDebugRepl(error,env,expr)

◆ runDebugRepl() [2/2]

void nix::EvalState::runDebugRepl ( const Error * error,
const Env & env,
const Expr & expr )

Run a debug repl with the given error, environment and expression.

Parameters
errorThe error to debug, may be nullptr.
envThe environment to debug, matching the expression.
exprThe expression to debug, matching the environment.

◆ toRealPath()

Path nix::EvalState::toRealPath ( const Path & path,
const NixStringContext & context )

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.

Member Data Documentation

◆ baseEnv

Env& nix::EvalState::baseEnv

The base environment, containing the builtin functions and values.

◆ buildStore

const ref<Store> nix::EvalState::buildStore

Store used to build stuff.

◆ constantInfos

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.

◆ corepkgsFS

const ref<MemorySourceAccessor> nix::EvalState::corepkgsFS

The in-memory filesystem for <nix/...> paths.

◆ debugRepl

ReplExitStatus(* nix::EvalState::debugRepl) (ref< EvalState > es, const ValMap &extraEnv)

Debugger

◆ evalCaches

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

◆ internalFS

const ref<MemorySourceAccessor> nix::EvalState::internalFS

In-memory filesystem for internal, non-user-callable Nix expressions like call-flake.nix.

◆ internalPrimOps

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.

◆ repair

RepairFlag nix::EvalState::repair

If set, force copying files to the Nix store even if they already exist there.

◆ rootFS

const ref<SourceAccessor> nix::EvalState::rootFS

The accessor for the root filesystem.

◆ staticBaseEnv

std::shared_ptr<StaticEnv> nix::EvalState::staticBaseEnv

The same, but used during parsing to resolve variables.

◆ store

const ref<Store> nix::EvalState::store

Store used to materialise .drv files.

◆ vEmptyList

Value nix::EvalState::vEmptyList

Empty list constant.

◆ vFalse

Value nix::EvalState::vFalse

true constant.

This is not a singleton. Pointer equality is not sufficient.

◆ vNull

Value nix::EvalState::vNull

null constant.

This is not a singleton. Pointer equality is not sufficient.

◆ vStringDirectory

Value nix::EvalState::vStringDirectory

"directory"

◆ vStringRegular

Value nix::EvalState::vStringRegular

"regular"

◆ vStringSymlink

Value nix::EvalState::vStringSymlink

"symlink"

◆ vStringUnknown

Value nix::EvalState::vStringUnknown

"unknown"

◆ vTrue

Value nix::EvalState::vTrue

true constant.

This is not a singleton. Pointer equality is not sufficient.


The documentation for this class was generated from the following files: