diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-01-31 12:54:52 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-01-31 13:00:50 +0100 |
commit | a6e2b6b36044d7708cf50b464009e50c8d120730 (patch) | |
tree | 886052a271e0b5f001715251da2814c8fcb456a8 /src | |
parent | ebfbfe95158fd074fa057930e1e0fb858059e358 (diff) |
nix flake deps -> nix flake list-inputs
Also add a --json flag.
Diffstat (limited to 'src')
-rw-r--r-- | src/nix/flake.cc | 64 |
1 files changed, 32 insertions, 32 deletions
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<nix::Store> store) override - { - auto evalState = getEvalState(); - - std::queue<LockedFlake> 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<nix::Store> 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<nix::Store> 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<void(const LockedInputs & inputs, size_t depth)> 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<CmdFlakeList>(); }}, {"update", []() { return make_ref<CmdFlakeUpdate>(); }}, {"info", []() { return make_ref<CmdFlakeInfo>(); }}, + {"list-inputs", []() { return make_ref<CmdFlakeListInputs>(); }}, {"check", []() { return make_ref<CmdFlakeCheck>(); }}, {"add", []() { return make_ref<CmdFlakeAdd>(); }}, {"remove", []() { return make_ref<CmdFlakeRemove>(); }}, |