diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-09-03T13·45+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-09-03T13·45+0200 |
commit | 07a08bddf001271b4b7eff2a119c395f40119966 (patch) | |
tree | 304d714281d8b3021495903ef004763a8dc280bc /src | |
parent | c57ed84e286047a9f3c103cf689ae04381c23dad (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/eval.cc | 6 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 6 | ||||
-rw-r--r-- | src/nix-env/nix-env.cc | 9 |
3 files changed, 18 insertions, 3 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 50f36ce4e90b..af2bf92e3fe9 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -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 of stack space, which is a real killer in the recursive evaluator. So here are some helper functions for throwing diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 29c8341dfb9a..b08bec8d9eb9 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -203,6 +203,12 @@ private: void addPrimOp(const string & name, unsigned int arity, PrimOpFun primOp); +public: + + void getBuiltin(const string & name, Value & v); + +private: + inline Value * lookupVar(Env * env, const VarRef & var, bool noEval); friend class ExprVar; diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index e4cc66e76194..9f51e919b0e9 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -131,9 +131,12 @@ static void getAllExprs(EvalState & state, continue; } attrs.insert(attrName); - // FIXME: make loading lazy. - Value & v2(*state.allocAttr(v, state.symbols.create(attrName))); - state.evalFile(path2, v2); + /* Load the expression on demand. */ + Value & vFun(*state.allocValue()); + 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)) /* `path2' is a directory (with no default.nix in it); |