about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-04-17T15·14+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-04-17T15·14+0200
commit8745fade0387b2900a98b95798d9f12be7ef97ca (patch)
tree2037037a5d863c122cb03fee0e0608a66cc9a290 /src
parent8cf1719e3e02998c0d22ed9e505a4a98e3335627 (diff)
Added utility command ‘nix-instantiate --find-file’ to look up a file in Nix's search path
Diffstat (limited to 'src')
-rw-r--r--src/nix-instantiate/nix-instantiate.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index 8f3a290f3a6a..adc8ca623807 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -79,6 +79,7 @@ void run(Strings args)
     EvalState state;
     Strings files;
     bool readStdin = false;
+    bool findFile = false;
     bool evalOnly = false;
     bool parseOnly = false;
     bool xmlOutput = false;
@@ -100,6 +101,8 @@ void run(Strings args)
             readOnlyMode = true;
             parseOnly = evalOnly = true;
         }
+        else if (arg == "--find-file")
+            findFile = true;
         else if (arg == "--attr" || arg == "-A") {
             if (i == args.end())
                 throw UsageError("`--attr' requires an argument");
@@ -130,6 +133,15 @@ void run(Strings args)
 
     if (attrPaths.empty()) attrPaths.push_back("");
 
+    if (findFile) {
+        foreach (Strings::iterator, i, files) {
+            Path p = state.findFile(*i);
+            if (p == "") throw Error(format("unable to find `%1%'") % *i);
+            std::cout << p << std::endl;
+        }
+        return;
+    }
+
     store = openStore();
 
     if (readStdin) {