* Allow '<nixexpr>' syntax to be used in nix-instantiate, nix-build

and nix-env, e.g.,

  $ nix-env -f '<nixpkgs>' -i patchelf

  or

  $ nix-build '<nixos/tests>' -A login.test
This commit is contained in:
Eelco Dolstra 2011-12-01 16:41:43 +00:00
parent 23c38a04cc
commit b12b21825c
5 changed files with 16 additions and 4 deletions

View file

@ -44,4 +44,15 @@ bool parseSearchPathArg(const string & arg, Strings::iterator & i,
}
Path lookupFileArg(EvalState & state, string s)
{
if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
Path p = state.findFile(s.substr(1, s.size() - 2));
if (p == "") throw Error(format("file `%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)") % p);
return p;
} else
return absPath(s);
}
}

View file

@ -14,6 +14,8 @@ bool parseOptionArg(const string & arg, Strings::iterator & i,
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
const Strings::iterator & argsEnd, EvalState & state);
Path lookupFileArg(EvalState & state, string s);
}

View file

@ -1270,7 +1270,7 @@ void run(Strings args)
else if (arg == "--profile" || arg == "-p")
globals.profile = absPath(needArg(i, args, arg));
else if (arg == "--file" || arg == "-f")
globals.instSource.nixExprPath = absPath(needArg(i, args, arg));
globals.instSource.nixExprPath = lookupFileArg(globals.state, needArg(i, args, arg));
else if (arg == "--switch-profile" || arg == "-S")
op = opSwitchProfile;
else if (arg == "--switch-generation" || arg == "-G")

View file

@ -138,8 +138,7 @@ void run(Strings args)
}
foreach (Strings::iterator, i, files) {
Path path = absPath(*i);
Expr * e = state.parseExprFromFile(path);
Expr * e = state.parseExprFromFile(lookupFileArg(state, *i));
processExpr(state, attrPaths, parseOnly, strict, autoArgs,
evalOnly, xmlOutput, xmlOutputSourceLocation, e);
}

View file

@ -36,7 +36,7 @@ nix-env -p $profiles/test -q '*' | grep -q foo-2.0pre1
test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
# Upgrade "foo": should install foo-2.0.
nix-env -p $profiles/test -f ./user-envs.nix -u foo
NIX_PATH=nixpkgs=./user-envs.nix nix-env -p $profiles/test -f '<nixpkgs>' -u foo
# Query installed: should contain foo-2.0 now.
test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1