diff --git a/src/nix/flake.cc b/src/nix/flake.cc index dafd1ae7e..5450f1fb5 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -110,37 +110,6 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake) return j; } -#if 0 -// FIXME: merge info CmdFlakeInfo? -struct CmdFlakeDeps : FlakeCommand -{ - std::string description() override - { - return "list informaton about dependencies"; - } - - void run(nix::ref store) override - { - auto evalState = getEvalState(); - - std::queue todo; - todo.push(lockFlake()); - - stopProgressBar(); - - while (!todo.empty()) { - auto lockedFlake = std::move(todo.front()); - todo.pop(); - - for (auto & info : lockedFlake.flakeDeps) { - printFlakeInfo(*store, info.second.flake); - todo.push(info.second); - } - } - } -}; -#endif - struct CmdFlakeUpdate : FlakeCommand { std::string description() override @@ -150,7 +119,6 @@ struct CmdFlakeUpdate : FlakeCommand void run(nix::ref store) override { - auto evalState = getEvalState(); lockFlake(); } }; @@ -214,6 +182,37 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON } }; +struct CmdFlakeListInputs : FlakeCommand, MixJSON +{ + std::string description() override + { + return "list flake inputs"; + } + + void run(nix::ref store) override + { + auto flake = lockFlake(); + + if (json) + std::cout << ((LockedInputs &) flake.lockFile).toJson() << "\n"; + else { + std::cout << fmt("%s\n", flake.flake.resolvedRef); + + std::function recurse; + + recurse = [&](const LockedInputs & inputs, size_t depth) + { + for (auto & input : inputs.inputs) { + std::cout << fmt("%s%s: %s\n", std::string(depth * 2, ' '), input.first, input.second.ref); + recurse(input.second, depth + 1); + } + }; + + recurse(flake.lockFile, 1); + } + } +}; + struct CmdFlakeCheck : FlakeCommand { bool build = true; @@ -685,6 +684,7 @@ struct CmdFlake : virtual MultiCommand, virtual Command {"list", []() { return make_ref(); }}, {"update", []() { return make_ref(); }}, {"info", []() { return make_ref(); }}, + {"list-inputs", []() { return make_ref(); }}, {"check", []() { return make_ref(); }}, {"add", []() { return make_ref(); }}, {"remove", []() { return make_ref(); }}, diff --git a/tests/flakes.sh b/tests/flakes.sh index 6d2ee80f1..4642a7c2e 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -114,7 +114,7 @@ cat > $registry <