From 8745fade0387b2900a98b95798d9f12be7ef97ca Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 17 Apr 2012 17:14:14 +0200 Subject: [PATCH] =?UTF-8?q?Added=20utility=20command=20=E2=80=98nix-instan?= =?UTF-8?q?tiate=20--find-file=E2=80=99=20to=20look=20up=20a=20file=20in?= =?UTF-8?q?=20Nix's=20search=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/manual/nix-instantiate.xml | 14 ++++++++++++++ src/nix-instantiate/nix-instantiate.cc | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/doc/manual/nix-instantiate.xml b/doc/manual/nix-instantiate.xml index a659ee730..7e6120852 100644 --- a/doc/manual/nix-instantiate.xml +++ b/doc/manual/nix-instantiate.xml @@ -36,6 +36,7 @@ + @@ -100,6 +101,19 @@ policies. + + + Look up the given files in Nix’s search path (as + specified by the NIX_PATH environment variable). + If found, print the corresponding absolute paths on standard + output. For instance, if NIX_PATH is + nixpkgs=/home/alice/nixpkgs, then + nix-instantiate --find-file nixpkgs/default.nix + will print + /home/alice/nixpkgs/default.nix. + + + When used with and diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index 8f3a290f3..adc8ca623 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) {