diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-02-14T17·07+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-02-14T17·07+0000 |
commit | e446d342b77e0babb200afd6b6275df2c70cfaee (patch) | |
tree | 86ea0157026866ca09d58e63aaf6496fd3a35346 /src | |
parent | 0cb016c209a6cbfc57a93a3f353a556924d31b50 (diff) |
* Added an installation source `--from-expression' (or `-E') to
install derivations from a Nix expression specified on the command line. This is particularly useful for disambiguation if there are multiple derivations with the same name. For instance, in Nixpkgs, to install the Firefox wrapper rather than the plain Firefox component: $ nix-env -f .../i686-linux.nix -i -E 'x: x.firefoxWrapper' The Nix expressions should be functions to which the default Nix expression (in this case, `i686-linux.nix') is passed, hence `x: ...'. This might also be a nice way to deal with high-level (user-level) variability, e.g., $ nix-env -f ./server.nix -i -E 'x: x {port = 8080; ssl = false;}'
Diffstat (limited to 'src')
-rw-r--r-- | src/nix-env/main.cc | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index a9125001226f..a250413ab1ad 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -91,7 +91,7 @@ static bool parseDerivation(EvalState & state, Expr e, UserEnvElem & elem) } -static bool parseDerivations(EvalState & state, Expr e, UserEnvElems & elems) +static void parseDerivations(EvalState & state, Expr e, UserEnvElems & elems) { ATermList es; UserEnvElem elem; @@ -122,17 +122,14 @@ static bool parseDerivations(EvalState & state, Expr e, UserEnvElems & elems) parseDerivations(state, *i, elems); } } - - return true; } static void loadDerivations(EvalState & state, Path nixExprPath, string systemFilter, UserEnvElems & elems) { - Expr e = parseExprFromFile(state, absPath(nixExprPath)); - if (!parseDerivations(state, e, elems)) - throw Error("set of derivations expected"); + parseDerivations(state, + parseExprFromFile(state, absPath(nixExprPath)), elems); /* Filter out all derivations not applicable to the current system. */ @@ -185,8 +182,7 @@ static void queryInstalled(EvalState & state, UserEnvElems & elems, AddPos addPos; e = bottomupRewrite(addPos, e); - if (!parseDerivations(state, e, elems)) - throw badTerm(format("set of derivations expected in `%1%'") % path, e); + parseDerivations(state, e, elems); } @@ -315,7 +311,25 @@ static void queryInstSources(EvalState & state, break; } + /* Get the available user environment elements from the Nix + expressions specified on the command line; these should be + functions that take the default Nix expression file as + argument, e.g., if the file is `./foo.nix', then the + argument `x: x.bar' is equivalent to `(x: x.bar) + (import ./foo.nix)' = `(import ./foo.nix).bar'. */ case srcNixExprs: + + Expr e1 = parseExprFromFile(state, + absPath(instSource.nixExprPath)); + + for (Strings::const_iterator i = args.begin(); + i != args.end(); ++i) + { + Expr e2 = parseExprFromString(state, *i, absPath(".")); + Expr call = makeCall(e2, e1); + parseDerivations(state, call, elems); + } + break; case srcStorePaths: |