aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-26 15:14:33 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-26 15:14:33 -0400
commit8c7910083976e255300efa797030448f5a1cb864 (patch)
treeafbd7a37d0724feb408a2d025364ed3938b5673a /src/libexpr/primops.cc
parentaa115e22df1c80e8878237a9e704d7d70783a243 (diff)
parent3a4623afbbc1bff85bde33167d36e8c5a4a3df0d (diff)
Merge branch 'master' into no-manifests
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index f20c2f287..5c011c43e 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -65,7 +65,31 @@ static void prim_import(EvalState & state, Value * * args, Value & v)
}
}
- state.evalFile(path, v);
+ if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) {
+ Derivation drv = parseDerivation(readFile(path));
+ Value & w = *state.allocValue();
+ state.mkAttrs(w, 1 + drv.outputs.size());
+ mkString(*state.allocAttr(w, state.sDrvPath), path, singleton<PathSet>("=" + path));
+ state.mkList(*state.allocAttr(w, state.symbols.create("outputs")), drv.outputs.size());
+ unsigned int outputs_index = 0;
+
+ Value * outputsVal = w.attrs->find(state.symbols.create("outputs"))->value;
+ foreach (DerivationOutputs::iterator, i, drv.outputs) {
+ mkString(*state.allocAttr(w, state.symbols.create(i->first)),
+ i->second.path, singleton<PathSet>("!" + i->first + "!" + path));
+ mkString(*(outputsVal->list.elems[outputs_index++] = state.allocValue()),
+ i->first);
+ }
+ w.attrs->sort();
+ Value fun;
+ state.mkThunk_(fun,
+ state.parseExprFromFile(state.findFile("nix/imported-drv-to-derivation.nix")));
+ state.forceFunction(fun);
+ mkApp(v, fun, w);
+ state.forceAttrs(v);
+ } else {
+ state.evalFile(path, v);
+ }
}