nix flake deps -> nix flake list-inputs

Also add a --json flag.
This commit is contained in:
Eelco Dolstra 2020-01-31 12:54:52 +01:00
parent ebfbfe9515
commit a6e2b6b360
2 changed files with 40 additions and 36 deletions

View file

@ -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>(); }},

View file

@ -114,7 +114,7 @@ cat > $registry <<EOF
EOF
# Test 'nix flake list'.
(( $(nix flake list | wc -l) == 6 ))
[[ $(nix flake list | wc -l) == 6 ]]
# Test 'nix flake info'.
nix flake info flake1 | grep -q 'URL: .*flake1.*'
@ -361,11 +361,11 @@ nix build -o $TEST_ROOT/result flake4/removeXyzzy#sth
# Testing the nix CLI
nix flake add flake1 flake3
(( $(nix flake list | wc -l) == 7 ))
[[ $(nix flake list | wc -l) == 7 ]]
nix flake pin flake1
(( $(nix flake list | wc -l) == 7 ))
[[ $(nix flake list | wc -l) == 7 ]]
nix flake remove flake1
(( $(nix flake list | wc -l) == 6 ))
[[ $(nix flake list | wc -l) == 6 ]]
# Test 'nix flake init'.
(cd $flake7Dir && nix flake init)
@ -617,3 +617,7 @@ nix flake update $flake3Dir
nix flake update $flake3Dir --update-input flake2/flake1
[[ $(jq .inputs.flake2.inputs.flake1.url $flake3Dir/flake.lock) =~ flake1.*rev=$hash2 ]]
# Test 'nix flake list-inputs'.
[[ $(nix flake list-inputs $flake3Dir | wc -l) == 5 ]]
nix flake list-inputs $flake3Dir --json | jq .