nix-env: Load files in ~/.nix-defexpr on demand

So if you do "nix-env -qa -A nixos", then other channels won't be
parsed/evaluated at all.
This commit is contained in:
Eelco Dolstra 2013-09-03 15:45:32 +02:00
parent c57ed84e28
commit 07a08bddf0
3 changed files with 18 additions and 3 deletions

View File

@ -222,6 +222,12 @@ void EvalState::addPrimOp(const string & name,
} }
void EvalState::getBuiltin(const string & name, Value & v)
{
v = *baseEnv.values[0]->attrs->find(symbols.create(name))->value;
}
/* Every "format" object (even temporary) takes up a few hundred bytes /* Every "format" object (even temporary) takes up a few hundred bytes
of stack space, which is a real killer in the recursive of stack space, which is a real killer in the recursive
evaluator. So here are some helper functions for throwing evaluator. So here are some helper functions for throwing

View File

@ -203,6 +203,12 @@ private:
void addPrimOp(const string & name, void addPrimOp(const string & name,
unsigned int arity, PrimOpFun primOp); unsigned int arity, PrimOpFun primOp);
public:
void getBuiltin(const string & name, Value & v);
private:
inline Value * lookupVar(Env * env, const VarRef & var, bool noEval); inline Value * lookupVar(Env * env, const VarRef & var, bool noEval);
friend class ExprVar; friend class ExprVar;

View File

@ -131,9 +131,12 @@ static void getAllExprs(EvalState & state,
continue; continue;
} }
attrs.insert(attrName); attrs.insert(attrName);
// FIXME: make loading lazy. /* Load the expression on demand. */
Value & v2(*state.allocAttr(v, state.symbols.create(attrName))); Value & vFun(*state.allocValue());
state.evalFile(path2, v2); Value & vArg(*state.allocValue());
state.getBuiltin("import", vFun);
mkString(vArg, path2);
mkApp(*state.allocAttr(v, state.symbols.create(attrName)), vFun, vArg);
} }
else if (S_ISDIR(st.st_mode)) else if (S_ISDIR(st.st_mode))
/* `path2' is a directory (with no default.nix in it); /* `path2' is a directory (with no default.nix in it);