diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-03-11 17:03:38 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-03-11 17:03:38 +0100 |
commit | 35f66517350402792aded1b677a47526e23e78ef (patch) | |
tree | 512766433dac03f2bdc9f01b1a5915e2a15da2ab /src/libexpr | |
parent | 97d1c7f93207296fe8fadc63cf8819501886cf77 (diff) | |
parent | 9950cdec3514949942a79c58764b1ea9bf9d5d57 (diff) |
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/eval.hh | 4 | ||||
-rw-r--r-- | src/libexpr/imported-drv-to-derivation.nix | 21 | ||||
-rw-r--r-- | src/libexpr/local.mk | 2 | ||||
-rw-r--r-- | src/libexpr/parser.y | 6 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 15 |
5 files changed, 39 insertions, 9 deletions
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index cc212258d..f6c96bd68 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -146,8 +146,8 @@ public: Expr * parseExprFromFile(const Path & path, StaticEnv & staticEnv); /* Parse a Nix expression from the specified string. */ - Expr * parseExprFromString(const string & s, const Path & basePath, StaticEnv & staticEnv); - Expr * parseExprFromString(const string & s, const Path & basePath); + Expr * parseExprFromString(std::string_view s, const Path & basePath, StaticEnv & staticEnv); + Expr * parseExprFromString(std::string_view s, const Path & basePath); Expr * parseStdin(); diff --git a/src/libexpr/imported-drv-to-derivation.nix b/src/libexpr/imported-drv-to-derivation.nix new file mode 100644 index 000000000..eab8b050e --- /dev/null +++ b/src/libexpr/imported-drv-to-derivation.nix @@ -0,0 +1,21 @@ +attrs @ { drvPath, outputs, name, ... }: + +let + + commonAttrs = (builtins.listToAttrs outputsList) // + { all = map (x: x.value) outputsList; + inherit drvPath name; + type = "derivation"; + }; + + outputToAttrListElement = outputName: + { name = outputName; + value = commonAttrs // { + outPath = builtins.getAttr outputName attrs; + inherit outputName; + }; + }; + + outputsList = map outputToAttrListElement outputs; + +in (builtins.head outputsList).value diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk index 6acb0150c..d1982927c 100644 --- a/src/libexpr/local.mk +++ b/src/libexpr/local.mk @@ -39,3 +39,5 @@ $(eval $(call install-file-in, $(d)/nix-expr.pc, $(prefix)/lib/pkgconfig, 0644)) $(foreach i, $(wildcard src/libexpr/flake/*.hh), \ $(eval $(call install-file-in, $(i), $(includedir)/nix/flake, 0644))) + +$(d)/primops.cc: $(d)/imported-drv-to-derivation.nix.gen.hh diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index afa1fd439..9c769e803 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -611,13 +611,13 @@ Expr * EvalState::parseExprFromFile(const Path & path, StaticEnv & staticEnv) } -Expr * EvalState::parseExprFromString(const string & s, const Path & basePath, StaticEnv & staticEnv) +Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath, StaticEnv & staticEnv) { - return parse(s.c_str(), "(string)", basePath, staticEnv); + return parse(s.data(), "(string)", basePath, staticEnv); } -Expr * EvalState::parseExprFromString(const string & s, const Path & basePath) +Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath) { return parseExprFromString(s, basePath, staticBaseEnv); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 083caf04a..b0f8b4414 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -122,10 +122,17 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args mkString(*(outputsVal->listElems()[outputs_index++]), o.first); } w.attrs->sort(); - Value fun; - state.evalFile(settings.nixDataDir + "/nix/corepkgs/imported-drv-to-derivation.nix", fun); - state.forceFunction(fun, pos); - mkApp(v, fun, w); + + static Value * fun = nullptr; + if (!fun) { + fun = state.allocValue(); + state.eval(state.parseExprFromString( + #include "imported-drv-to-derivation.nix.gen.hh" + , "/"), *fun); + } + + state.forceFunction(*fun, pos); + mkApp(v, *fun, w); state.forceAttrs(v, pos); } else { state.forceAttrs(*args[0]); |