Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/nix/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ void NixRepl::loadFile(const Path & path)

void NixRepl::loadFlake(const std::string & flakeRefS)
{
auto flakeRef = parseFlakeRef(flakeRefS, absPath("."), true);
auto [flakeRef, fragment] = parseFlakeRefWithFragment(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;
auto v = state->allocValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the reason for the change? Having v as a plain stack-allocated Value is nice since it has a lexical lifetime.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think I copied that from somewhere else while try to debug a stack overflow. I'll change it back 👍


flake::callFlake(*state,
flake::lockFlake(*state, flakeRef,
Expand All @@ -624,8 +624,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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won’t work properly if fragment has more than one level (foo.bar). You probably need to split it first with parseAttrPath and recursively get the right value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give that a shot. While we are at it, is there a function or method somewhere used to traverse the multiple outputs to find a match?


if (f == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == 0) {
if (!f) {

warn("no attribute %s, nothing loaded", fragment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warn("no attribute %s, nothing loaded", fragment);
warn("attribute '%s' does not exist, nothing loaded", fragment);

return;
};

fragment != "" ? addAttrsToScope(*f->value) : addAttrsToScope(*v);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fragment != "" ? addAttrsToScope(*f->value) : addAttrsToScope(*v);
addAttrsToScope(fragment != "" ? *f->value : *v);


}


Expand Down Expand Up @@ -654,7 +663,10 @@ void NixRepl::reloadFiles()
if (!first) notice("");
first = false;
notice("Loading '%1%'...", i);
loadFile(i);

settings.isExperimentalFeatureEnabled(Xp::Flakes)
? loadFlake(i)
: loadFile(i);
Comment on lines +667 to +669
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
settings.isExperimentalFeatureEnabled(Xp::Flakes)
? loadFlake(i)
: loadFile(i);
if (settings.isExperimentalFeatureEnabled(Xp::Flakes))
loadFlake(i);
else
loadFile(i);

since it's not really idiomatic in C++ (IMHO) to have the conditional operator at statement level.

}
}

Expand Down