about summary refs log tree commit diff
path: root/src/nix/installables.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-08-23T15·11+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-08-23T15·11+0200
commitd74236d1f2c3bca4fcc8cb1574fb962e813f69d3 (patch)
tree0ec4d387e04e9a79835efebd85753aeb5a00d251 /src/nix/installables.cc
parent22d6e31fc6a9de2ee424984e629ccd2e394ba512 (diff)
nix build: Use Nix search path
That is, unless --file is specified, the Nix search path is
synthesized into an attribute set. Thus you can say

  $ nix build nixpkgs.hello

assuming $NIX_PATH contains an entry of the form "nixpkgs=...". This
is more verbose than

  $ nix build hello

but is less ambiguous.
Diffstat (limited to 'src/nix/installables.cc')
-rw-r--r--src/nix/installables.cc42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 6257c7679af9..8341bbc5a3a4 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -9,6 +9,41 @@
 
 namespace nix {
 
+Value * MixInstallables::buildSourceExpr(EvalState & state)
+{
+    Value * vRoot = state.allocValue();
+
+    if (file != "") {
+        Expr * e = state.parseExprFromFile(resolveExprPath(lookupFileArg(state, file)));
+        state.eval(e, *vRoot);
+    }
+
+    else {
+
+        /* Construct the installation source from $NIX_PATH. */
+
+        auto searchPath = state.getSearchPath();
+
+        state.mkAttrs(*vRoot, searchPath.size());
+
+        std::unordered_set<std::string> seen;
+
+        for (auto & i : searchPath) {
+            if (i.first == "") continue;
+            if (seen.count(i.first)) continue;
+            seen.insert(i.first);
+            if (!pathExists(i.second)) continue;
+            mkApp(*state.allocAttr(*vRoot, state.symbols.create(i.first)),
+                state.getBuiltin("import"),
+                mkString(*state.allocValue(), i.second));
+        }
+
+        vRoot->attrs->sort();
+    }
+
+    return vRoot;
+}
+
 UserEnvElems MixInstallables::evalInstallables(ref<Store> store)
 {
     UserEnvElems res;
@@ -46,15 +81,12 @@ UserEnvElems MixInstallables::evalInstallables(ref<Store> store)
 
             EvalState state({}, store);
 
-            Expr * e = state.parseExprFromFile(resolveExprPath(lookupFileArg(state, file)));
-
-            Value vRoot;
-            state.eval(e, vRoot);
+            auto vRoot = buildSourceExpr(state);
 
             std::map<string, string> autoArgs_;
             Bindings & autoArgs(*evalAutoArgs(state, autoArgs_));
 
-            Value & v(*findAlongAttrPath(state, installable, autoArgs, vRoot));
+            Value & v(*findAlongAttrPath(state, installable, autoArgs, *vRoot));
             state.forceValue(v);
 
             DrvInfos drvs;