aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-02-12 21:55:43 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-02-12 21:55:43 +0100
commitbeab05851bfa895fe538f15f8bbb2da3a20db638 (patch)
tree0528f50f617213f6047829a1be9b5cdf61477b94 /src/nix
parent272b58220d17bc862f646dbc2cb38eea126001c0 (diff)
nix: Add --flake flag
This allows using an arbitrary "provides" attribute from the specified flake. For example: nix build --flake nixpkgs packages.hello (Maybe provides.packages should be used for consistency...)
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.hh3
-rw-r--r--src/nix/installables.cc26
2 files changed, 23 insertions, 6 deletions
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 04183c7ed..a08347945 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -53,7 +53,8 @@ struct Installable
struct SourceExprCommand : virtual Args, StoreCommand, MixEvalArgs
{
- Path file;
+ std::optional<Path> file;
+ std::optional<std::string> flakeUri;
SourceExprCommand();
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index b4584f168..0453c72c2 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -7,6 +7,7 @@
#include "get-drvs.hh"
#include "store-api.hh"
#include "shared.hh"
+#include "primops/flake.hh"
#include <regex>
@@ -18,8 +19,15 @@ SourceExprCommand::SourceExprCommand()
.shortName('f')
.longName("file")
.label("file")
- .description("evaluate FILE rather than the default")
+ .description("evaluate FILE rather than use the default installation source")
.dest(&file);
+
+ mkFlag()
+ .shortName('F')
+ .longName("flake")
+ .label("flake")
+ .description("evaluate FLAKE rather than use the default installation source")
+ .dest(&flakeUri);
}
Value * SourceExprCommand::getSourceExpr(EvalState & state)
@@ -28,9 +36,17 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
vSourceExpr = state.allocValue();
- if (file != "")
- state.evalFile(lookupFileArg(state, file), *vSourceExpr);
- else {
+ if (file && flakeUri)
+ throw Error("cannot use both --file and --flake");
+
+ if (file)
+ state.evalFile(lookupFileArg(state, *file), *vSourceExpr);
+ else if (flakeUri) {
+ // FIXME: handle flakeUri being a relative path
+ auto vTemp = state.allocValue();
+ auto vFlake = *makeFlakeValue(state, "impure:" + *flakeUri, *vTemp);
+ *vSourceExpr = *((*vFlake.attrs->get(state.symbols.create("provides")))->value);
+ } else {
// FIXME: remove "impure" hack, call some non-user-accessible
// variant of getFlake instead.
auto fun = state.parseExprFromString(
@@ -38,7 +54,7 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
" (getFlake (\"impure:\" + flakeInfo.uri)).${flakeName}.provides.packages or {})", "/");
auto vFun = state.allocValue();
state.eval(fun, *vFun);
- auto vRegistry = state.makeFlakeRegistryValue();
+ auto vRegistry = makeFlakeRegistryValue(state);
mkApp(*vSourceExpr, *vFun, *vRegistry);
}