From d746503e5c6fafd0fb6b2a4e6527c12cfc626637 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Jul 2020 20:23:39 +0200 Subject: [PATCH] Add --inputs-from to use flake inputs as registry entries 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. --- src/libfetchers/registry.cc | 2 ++ src/nix/installables.cc | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index 914a0e1e8..d4134ce29 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -204,6 +204,8 @@ std::pair 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}; } diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 3683ab945..adfd14a75 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -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(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()