mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
nix-expr: Add primops to EvalSettings
This commit is contained in:
parent
9b0f455609
commit
3c4c0953e0
5 changed files with 30 additions and 3 deletions
|
@ -103,4 +103,13 @@ Path getNixDefExpr()
|
||||||
: getHome() + "/.nix-defexpr";
|
: getHome() + "/.nix-defexpr";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EvalSettings::addPrimOp(PrimOp && primOp)
|
||||||
|
{
|
||||||
|
extraPrimOps.emplace_back(std::move(primOp));
|
||||||
}
|
}
|
||||||
|
void EvalSettings::addPrimOp(const PrimOp & primOp)
|
||||||
|
{
|
||||||
|
extraPrimOps.emplace_back(PrimOp(primOp));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace nix
|
|
@ -7,6 +7,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class EvalState;
|
class EvalState;
|
||||||
|
struct PrimOp;
|
||||||
|
|
||||||
struct EvalSettings : Config
|
struct EvalSettings : Config
|
||||||
{
|
{
|
||||||
|
@ -50,6 +51,17 @@ struct EvalSettings : Config
|
||||||
|
|
||||||
LookupPathHooks lookupPathHooks;
|
LookupPathHooks lookupPathHooks;
|
||||||
|
|
||||||
|
std::vector<PrimOp> extraPrimOps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a primop to be added when an EvalState is created from these settings.
|
||||||
|
*/
|
||||||
|
void addPrimOp(PrimOp && primOp);
|
||||||
|
/**
|
||||||
|
* Register a primop to be added when an EvalState is created from these settings.
|
||||||
|
*/
|
||||||
|
void addPrimOp(const PrimOp & primOp);
|
||||||
|
|
||||||
Setting<bool> enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation", R"(
|
Setting<bool> enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation", R"(
|
||||||
Enable built-in functions that allow executing native code.
|
Enable built-in functions that allow executing native code.
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,7 @@ EvalState::EvalState(
|
||||||
#include "fetchurl.nix.gen.hh"
|
#include "fetchurl.nix.gen.hh"
|
||||||
);
|
);
|
||||||
|
|
||||||
createBaseEnv();
|
createBaseEnv(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -633,7 +633,7 @@ private:
|
||||||
|
|
||||||
unsigned int baseEnvDispl = 0;
|
unsigned int baseEnvDispl = 0;
|
||||||
|
|
||||||
void createBaseEnv();
|
void createBaseEnv(const EvalSettings & settings);
|
||||||
|
|
||||||
Value * addConstant(const std::string & name, Value & v, Constant info);
|
Value * addConstant(const std::string & name, Value & v, Constant info);
|
||||||
|
|
||||||
|
|
|
@ -4669,7 +4669,7 @@ RegisterPrimOp::RegisterPrimOp(PrimOp && primOp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalState::createBaseEnv()
|
void EvalState::createBaseEnv(const EvalSettings & evalSettings)
|
||||||
{
|
{
|
||||||
baseEnv.up = 0;
|
baseEnv.up = 0;
|
||||||
|
|
||||||
|
@ -4928,6 +4928,12 @@ void EvalState::createBaseEnv()
|
||||||
addPrimOp(std::move(primOpAdjusted));
|
addPrimOp(std::move(primOpAdjusted));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto & primOp : evalSettings.extraPrimOps) {
|
||||||
|
auto primOpAdjusted = primOp;
|
||||||
|
primOpAdjusted.arity = std::max(primOp.args.size(), primOp.arity);
|
||||||
|
addPrimOp(std::move(primOpAdjusted));
|
||||||
|
}
|
||||||
|
|
||||||
/* Add a wrapper around the derivation primop that computes the
|
/* Add a wrapper around the derivation primop that computes the
|
||||||
`drvPath' and `outPath' attributes lazily.
|
`drvPath' and `outPath' attributes lazily.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue