aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/eval.hh')
-rw-r--r--src/libexpr/eval.hh63
1 files changed, 33 insertions, 30 deletions
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 74a7162ff..bb3ac2b22 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -8,6 +8,7 @@
#include "symbol-table.hh"
#include "config.hh"
#include "experimental-features.hh"
+#include "input-accessor.hh"
#include <map>
#include <optional>
@@ -59,17 +60,11 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
void copyContext(const Value & v, NixStringContext & context);
-/**
- * Cache for calls to addToStore(); maps source paths to the store
- * paths.
- */
-typedef std::map<Path, StorePath> SrcToStore;
-
-
std::string printValue(const EvalState & state, const Value & v);
std::ostream & operator << (std::ostream & os, const ValueType t);
+// FIXME: maybe change this to an std::variant<SourcePath, URL>.
typedef std::pair<std::string, std::string> SearchPathElem;
typedef std::list<SearchPathElem> SearchPath;
@@ -137,8 +132,6 @@ public:
SymbolTable symbols;
PosTable positions;
- static inline std::string derivationNixPath = "//builtin/derivation.nix";
-
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
sFile, sLine, sColumn, sFunctor, sToString,
@@ -149,7 +142,6 @@ public:
sDescription, sSelf, sEpsilon, sStartSet, sOperator, sKey, sPath,
sPrefix,
sOutputSpecified;
- Symbol sDerivationNix;
/**
* If set, force copying files to the Nix store even if they
@@ -165,6 +157,8 @@ public:
Bindings emptyBindings;
+ const SourcePath derivationInternal;
+
/**
* Store used to materialise .drv files.
*/
@@ -234,15 +228,18 @@ public:
}
private:
- SrcToStore srcToStore;
+
+ /* Cache for calls to addToStore(); maps source paths to the store
+ paths. */
+ std::map<SourcePath, StorePath> srcToStore;
/**
* A cache from path names to parse trees.
*/
#if HAVE_BOEHMGC
- typedef std::map<Path, Expr *, std::less<Path>, traceable_allocator<std::pair<const Path, Expr *>>> FileParseCache;
+ typedef std::map<SourcePath, Expr *, std::less<SourcePath>, traceable_allocator<std::pair<const SourcePath, Expr *>>> FileParseCache;
#else
- typedef std::map<Path, Expr *> FileParseCache;
+ typedef std::map<SourcePath, Expr *> FileParseCache;
#endif
FileParseCache fileParseCache;
@@ -250,9 +247,9 @@ private:
* A cache from path names to values.
*/
#if HAVE_BOEHMGC
- typedef std::map<Path, Value, std::less<Path>, traceable_allocator<std::pair<const Path, Value>>> FileEvalCache;
+ typedef std::map<SourcePath, Value, std::less<SourcePath>, traceable_allocator<std::pair<const SourcePath, Value>>> FileEvalCache;
#else
- typedef std::map<Path, Value> FileEvalCache;
+ typedef std::map<SourcePath, Value> FileEvalCache;
#endif
FileEvalCache fileEvalCache;
@@ -263,7 +260,7 @@ private:
/**
* Cache used by checkSourcePath().
*/
- std::unordered_map<Path, Path> resolvedPaths;
+ std::unordered_map<Path, SourcePath> resolvedPaths;
/**
* Cache used by prim_match().
@@ -295,6 +292,12 @@ public:
SearchPath getSearchPath() { return searchPath; }
/**
+ * Return a `SourcePath` that refers to `path` in the root
+ * filesystem.
+ */
+ SourcePath rootPath(CanonPath path);
+
+ /**
* Allow access to a path.
*/
void allowPath(const Path & path);
@@ -314,7 +317,7 @@ public:
* Check whether access to a path is allowed and throw an error if
* not. Otherwise return the canonicalised path.
*/
- Path checkSourcePath(const Path & path);
+ SourcePath checkSourcePath(const SourcePath & path);
void checkURI(const std::string & uri);
@@ -332,14 +335,14 @@ public:
/**
* Parse a Nix expression from the specified file.
*/
- Expr * parseExprFromFile(const Path & path);
- Expr * parseExprFromFile(const Path & path, std::shared_ptr<StaticEnv> & staticEnv);
+ Expr * parseExprFromFile(const SourcePath & path);
+ Expr * parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv);
/**
* Parse a Nix expression from the specified string.
*/
- Expr * parseExprFromString(std::string s, const Path & basePath, std::shared_ptr<StaticEnv> & staticEnv);
- Expr * parseExprFromString(std::string s, const Path & basePath);
+ Expr * parseExprFromString(std::string s, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv);
+ Expr * parseExprFromString(std::string s, const SourcePath & basePath);
Expr * parseStdin();
@@ -348,14 +351,14 @@ public:
* form. Optionally enforce that the top-level expression is
* trivial (i.e. doesn't require arbitrary computation).
*/
- void evalFile(const Path & path, Value & v, bool mustBeTrivial = false);
+ void evalFile(const SourcePath & path, Value & v, bool mustBeTrivial = false);
/**
* Like `evalFile`, but with an already parsed expression.
*/
void cacheFile(
- const Path & path,
- const Path & resolvedPath,
+ const SourcePath & path,
+ const SourcePath & resolvedPath,
Expr * e,
Value & v,
bool mustBeTrivial = false);
@@ -365,8 +368,8 @@ public:
/**
* Look up a file in the search path.
*/
- Path findFile(const std::string_view path);
- Path findFile(SearchPath & searchPath, const std::string_view path, const PosIdx pos = noPos);
+ SourcePath findFile(const std::string_view path);
+ SourcePath findFile(SearchPath & searchPath, const std::string_view path, const PosIdx pos = noPos);
/**
* If the specified search path element is a URI, download it.
@@ -454,7 +457,7 @@ public:
bool coerceMore = false, bool copyToStore = true,
bool canonicalizePath = true);
- StorePath copyPathToStore(NixStringContext & context, const Path & path);
+ StorePath copyPathToStore(NixStringContext & context, const SourcePath & path);
/**
* Path coercion.
@@ -463,7 +466,7 @@ public:
* path. The result is guaranteed to be a canonicalised, absolute
* path. Nothing is copied to the store.
*/
- Path coerceToPath(const PosIdx pos, Value & v, NixStringContext & context, std::string_view errorCtx);
+ SourcePath coerceToPath(const PosIdx pos, Value & v, NixStringContext & context, std::string_view errorCtx);
/**
* Like coerceToPath, but the result must be a store path.
@@ -525,7 +528,7 @@ private:
char * text,
size_t length,
Pos::Origin origin,
- Path basePath,
+ const SourcePath & basePath,
std::shared_ptr<StaticEnv> & staticEnv);
public:
@@ -656,7 +659,7 @@ std::string showType(const Value & v);
/**
* If `path` refers to a directory, then append "/default.nix".
*/
-Path resolveExprPath(Path path);
+SourcePath resolveExprPath(const SourcePath & path);
struct InvalidPathError : EvalError
{