aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimothy DeHerrera <tim.deh@pm.me>2021-12-22 15:36:08 -0700
committerTom Bereknyei <tomberek@gmail.com>2022-05-18 21:20:59 -0400
commit06d57ce7597fc1b49ce1cdc721edc64eaafe38fb (patch)
tree90126f3d894edfc445fefd0f70f5f83cdb0d7d8a /src
parent78dc64ec1e34236d90c8869feebe30f596205cb2 (diff)
nix repl: load flakes from cli args
If experimental feature "flakes" is enabled, args passed to `nix repl` will now be considered flake refs and imported using the existing `:load-flake` machinery. In addition, `:load-flake` now supports loading flake fragments.
Diffstat (limited to 'src')
-rw-r--r--src/nix/repl.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 2967632ed..d20eb0929 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -646,11 +646,11 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
if (flakeRefS.empty())
throw Error("cannot use ':load-flake' without a path specified. (Use '.' for the current working directory.)");
- auto flakeRef = parseFlakeRef(flakeRefS, absPath("."), true);
+ auto [flakeRef, fragment] = parseFlakeRefWithFragment(flakeRefS, absPath("."), true);
if (evalSettings.pureEval && !flakeRef.input.isLocked())
throw Error("cannot use ':load-flake' on locked flake reference '%s' (use --impure to override)", flakeRefS);
- Value v;
+ auto v = state->allocValue();
flake::callFlake(*state,
flake::lockFlake(*state, flakeRef,
@@ -659,8 +659,17 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
.useRegistries = !evalSettings.pureEval,
.allowMutable = !evalSettings.pureEval,
}),
- v);
- addAttrsToScope(v);
+ *v);
+
+ auto f = v->attrs->get(state->symbols.create(fragment));
+
+ if (f == 0) {
+ warn("no attribute %s, nothing loaded", fragment);
+ return;
+ };
+
+ fragment != "" ? addAttrsToScope(*f->value) : addAttrsToScope(*v);
+
}
@@ -689,7 +698,10 @@ void NixRepl::reloadFiles()
if (!first) notice("");
first = false;
notice("Loading '%1%'...", i);
- loadFile(i);
+
+ settings.isExperimentalFeatureEnabled(Xp::Flakes)
+ ? loadFlake(i)
+ : loadFile(i);
}
}