1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-21 11:30:30 -04:00
nix/src/libexpr/common-opts.cc
Eelco Dolstra 1ecc97b6bd * Add a Nix expression search path feature. Paths between angle
brackets, e.g.

    import <nixpkgs/pkgs/lib>

  are resolved by looking them up relative to the elements listed in
  the search path.  This allows us to get rid of hacks like

    import "${builtins.getEnv "NIXPKGS_ALL"}/pkgs/lib"

  The search path can be specified through the ‘-I’ command-line flag
  and through the colon-separated ‘NIX_PATH’ environment variable,
  e.g.,

    $ nix-build -I /etc/nixos ...

  If a file is not found in the search path, an error message is
  lazily thrown.
2011-08-06 16:05:24 +00:00

48 lines
1.1 KiB
C++

#include "common-opts.hh"
#include "../libmain/shared.hh"
#include "util.hh"
namespace nix {
bool parseOptionArg(const string & arg, Strings::iterator & i,
const Strings::iterator & argsEnd, EvalState & state,
Bindings & autoArgs)
{
if (arg != "--arg" && arg != "--argstr") return false;
UsageError error(format("`%1%' requires two arguments") % arg);
if (i == argsEnd) throw error;
string name = *i++;
if (i == argsEnd) throw error;
string value = *i++;
/* !!! check for duplicates! */
Value * v = state.allocValue();
autoArgs.push_back(Attr(state.symbols.create(name), v));
if (arg == "--arg")
state.mkThunk_(*v, state.parseExprFromString(value, absPath(".")));
else
mkString(*v, value);
autoArgs.sort(); // !!! inefficient
return true;
}
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
const Strings::iterator & argsEnd, EvalState & state)
{
if (arg != "-I") return false;
if (i == argsEnd) throw UsageError(format("`%1%' requires an argument") % arg);;
state.addToSearchPath(*i++);
return true;
}
}