Added utility command ‘nix-instantiate --find-file’ to look up a file in Nix's search path
This commit is contained in:
		
							parent
							
								
									8cf1719e3e
								
							
						
					
					
						commit
						8745fade03
					
				
					 2 changed files with 26 additions and 0 deletions
				
			
		|  | @ -36,6 +36,7 @@ | ||||||
|           <option>--eval-only</option> |           <option>--eval-only</option> | ||||||
|           <arg><option>--strict</option></arg> |           <arg><option>--strict</option></arg> | ||||||
|         </arg> |         </arg> | ||||||
|  |         <arg choice='plain'><option>--find-file</option></arg> | ||||||
|       </group> |       </group> | ||||||
|       <arg><option>--xml</option></arg> |       <arg><option>--xml</option></arg> | ||||||
|     </arg> |     </arg> | ||||||
|  | @ -100,6 +101,19 @@ policies.</para> | ||||||
|      |      | ||||||
|   </varlistentry> |   </varlistentry> | ||||||
| 
 | 
 | ||||||
|  |   <varlistentry><term><option>--find-file</option></term> | ||||||
|  |    | ||||||
|  |     <listitem><para>Look up the given files in Nix’s search path (as | ||||||
|  |     specified by the <envar>NIX_PATH</envar> environment variable). | ||||||
|  |     If found, print the corresponding absolute paths on standard | ||||||
|  |     output.  For instance, if <envar>NIX_PATH</envar> is | ||||||
|  |     <literal>nixpkgs=/home/alice/nixpkgs</literal>, then | ||||||
|  |     <literal>nix-instantiate --find-file nixpkgs/default.nix</literal> | ||||||
|  |     will print | ||||||
|  |     <literal>/home/alice/nixpkgs/default.nix</literal>.</para></listitem> | ||||||
|  |      | ||||||
|  |   </varlistentry> | ||||||
|  |        | ||||||
|   <varlistentry><term><option>--xml</option></term> |   <varlistentry><term><option>--xml</option></term> | ||||||
| 
 | 
 | ||||||
|     <listitem><para>When used with <option>--parse-only</option> and |     <listitem><para>When used with <option>--parse-only</option> and | ||||||
|  |  | ||||||
|  | @ -79,6 +79,7 @@ void run(Strings args) | ||||||
|     EvalState state; |     EvalState state; | ||||||
|     Strings files; |     Strings files; | ||||||
|     bool readStdin = false; |     bool readStdin = false; | ||||||
|  |     bool findFile = false; | ||||||
|     bool evalOnly = false; |     bool evalOnly = false; | ||||||
|     bool parseOnly = false; |     bool parseOnly = false; | ||||||
|     bool xmlOutput = false; |     bool xmlOutput = false; | ||||||
|  | @ -100,6 +101,8 @@ void run(Strings args) | ||||||
|             readOnlyMode = true; |             readOnlyMode = true; | ||||||
|             parseOnly = evalOnly = true; |             parseOnly = evalOnly = true; | ||||||
|         } |         } | ||||||
|  |         else if (arg == "--find-file") | ||||||
|  |             findFile = true; | ||||||
|         else if (arg == "--attr" || arg == "-A") { |         else if (arg == "--attr" || arg == "-A") { | ||||||
|             if (i == args.end()) |             if (i == args.end()) | ||||||
|                 throw UsageError("`--attr' requires an argument"); |                 throw UsageError("`--attr' requires an argument"); | ||||||
|  | @ -130,6 +133,15 @@ void run(Strings args) | ||||||
| 
 | 
 | ||||||
|     if (attrPaths.empty()) attrPaths.push_back(""); |     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(); |     store = openStore(); | ||||||
| 
 | 
 | ||||||
|     if (readStdin) { |     if (readStdin) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue