aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-07-20 20:06:56 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-07-20 20:06:56 +0200
commitc5fafca5a477debff123675b4c2167b8311f9ddf (patch)
tree57ed9f2c36dd5b00d0ea024de91a3e0c65df3873
parentdd7bcf3e1cf63a25cda4080fe70565353c358795 (diff)
parent765a3a20cb3be150498b73d1a2a5f7eb282ccc09 (diff)
Merge remote-tracking branch 'origin/repl-flake-support'
-rw-r--r--src/nix/repl.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 07bbd461f..b711f4163 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -68,6 +68,7 @@ struct NixRepl
StorePath getDerivationPath(Value & v);
bool processLine(string line);
void loadFile(const Path & path);
+ void loadFlake(const std::string & flakeRef);
void initEnv();
void reloadFiles();
void addAttrsToScope(Value & attrs);
@@ -415,6 +416,7 @@ bool NixRepl::processLine(string line)
<< " :e <expr> Open package or function in $EDITOR\n"
<< " :i <expr> Build derivation, then install result into current profile\n"
<< " :l <path> Load Nix expression and add it to scope\n"
+ << " :lf <ref> Load Nix flake and add it to scope\n"
<< " :p <expr> Evaluate and print expression recursively\n"
<< " :q Exit nix-repl\n"
<< " :r Reload all files\n"
@@ -435,6 +437,10 @@ bool NixRepl::processLine(string line)
loadFile(arg);
}
+ else if (command == ":lf" || command == ":load-flake") {
+ loadFlake(arg);
+ }
+
else if (command == ":r" || command == ":reload") {
state->resetFileCache();
reloadFiles();
@@ -576,6 +582,25 @@ void NixRepl::loadFile(const Path & path)
addAttrsToScope(v2);
}
+void NixRepl::loadFlake(const std::string & flakeRefS)
+{
+ auto flakeRef = parseFlakeRef(flakeRefS, absPath("."), true);
+ if (evalSettings.pureEval && !flakeRef.input.isImmutable())
+ throw Error("cannot use ':load-flake' on mutable flake reference '%s' (use --impure to override)", flakeRefS);
+
+ Value v;
+
+ flake::callFlake(*state,
+ flake::lockFlake(*state, flakeRef,
+ flake::LockFlags {
+ .updateLockFile = false,
+ .useRegistries = !evalSettings.pureEval,
+ .allowMutable = !evalSettings.pureEval,
+ }),
+ v);
+ addAttrsToScope(v);
+}
+
void NixRepl::initEnv()
{