Skip to content

Commit

Permalink
Add --inputs-from to use flake inputs as registry entries
Browse files Browse the repository at this point in the history
This allows you to refer to an input from another flake. For example,

  $ nix run --inputs-from /path/to/hydra nixpkgs#hello

runs 'hello' from the 'nixpkgs' inputs of the 'hydra' flake.

Fixes #3769.
  • Loading branch information
edolstra committed Jul 1, 2020
1 parent 7d554f2 commit d746503
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libfetchers/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ std::pair<Input, Attrs> lookupInRegistries(
if (!input.isDirect())
throw Error("cannot find flake '%s' in the flake registries", input.to_string());

debug("looked up '%s' -> '%s'", _input.to_string(), input.to_string());

return {input, extraAttrs};
}

Expand Down
25 changes: 25 additions & 0 deletions src/nix/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ MixFlakeOptions::MixFlakeOptions()
parseFlakeRef(flakeRef, absPath(".")));
}}
});

addFlag({
.longName = "inputs-from",
.description = "use the inputs of the specified flake as registry entries",
.labels = {"flake-url"},
.handler = {[&](std::string flakeRef) {
auto evalState = getEvalState();
auto flake = flake::lockFlake(
*evalState,
parseFlakeRef(flakeRef, absPath(".")),
{ .writeLockFile = false });
for (auto & [inputName, input] : flake.lockFile.root->inputs) {
auto input2 = flake.lockFile.findInput({inputName}); // resolve 'follows' nodes
if (auto input3 = std::dynamic_pointer_cast<const flake::LockedNode>(input2)) {
overrideRegistry(
fetchers::Input::fromAttrs({{"type","indirect"}, {"id", inputName}}),
input3->lockedRef.input,
{});
}
}
}},
.completer = {[&](size_t, std::string_view prefix) {
completeFlakeRef(getEvalState()->store, prefix);
}}
});
}

SourceExprCommand::SourceExprCommand()
Expand Down

0 comments on commit d746503

Please sign in to comment.