From dca60104d2f0d935530a882f0e793b5c85d68d0f Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Wed, 11 Jan 2023 13:53:42 -0700 Subject: [PATCH] path-info: inplement --query-substitutes Fixes #3946 --- src/nix/path-info.cc | 43 +++++++++++++++++++++++++++++++++++++++++-- src/nix/path-info.md | 9 +++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 613c5b1918dc..0dd191a8ac45 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -16,6 +16,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON bool showClosureSize = false; bool humanReadable = false; bool showSigs = false; + bool showSubStatus = false; CmdPathInfo() { @@ -45,6 +46,13 @@ struct CmdPathInfo : StorePathsCommand, MixJSON .description = "Show signatures.", .handler = {&showSigs, true}, }); + + addFlag({ + .longName = "--query-substitutes", + .shortName = 'U', + .description = "Query path availability in the configured substituters, printing only those that are not; with `--json` adds a `substitutable` boolean to the output.", + .handler = {&showSubStatus, true}, + }); } std::string description() override @@ -87,13 +95,44 @@ struct CmdPathInfo : StorePathsCommand, MixJSON pathLen = std::max(pathLen, store->printStorePath(storePath).size()); if (json) { - std::cout << store->pathInfoToJSON( + auto json = store->pathInfoToJSON( // FIXME: preserve order? StorePathSet(storePaths.begin(), storePaths.end()), - true, showClosureSize, SRI, AllowInvalid).dump(); + true, showClosureSize, SRI, AllowInvalid); + + if (showSubStatus) { + StorePathSet inputPaths = StorePathSet(storePaths.begin(), storePaths.end()); + auto substitutablePaths = store->querySubstitutablePaths(inputPaths); + + auto jsonNew = nlohmann::json::array(); + + for (auto v : json) { + std::string const storePathS = v["path"]; + substitutablePaths.find(store->followLinksToStorePath(storePathS)) == + substitutablePaths.end() + ? v["substitutable"] = false + : v["substitutable"] = true; + jsonNew.emplace_back(std::move(v)); + } + std::cout << jsonNew.dump(); + } + else std::cout << json.dump(); } else { + StorePaths missingPaths; + + if (showSubStatus) { + StorePathSet inputPaths = StorePathSet(storePaths.begin(), storePaths.end()); + auto substitutablePaths = store->querySubstitutablePaths(inputPaths); + + for (auto & path : storePaths) { + if (substitutablePaths.find(path) == substitutablePaths.end()) + missingPaths.emplace_back(std::move(path)); + } + + storePaths = missingPaths; + } for (auto & storePath : storePaths) { auto info = store->queryPathInfo(storePath); diff --git a/src/nix/path-info.md b/src/nix/path-info.md index b30898ac0f03..eb29700fd238 100644 --- a/src/nix/path-info.md +++ b/src/nix/path-info.md @@ -39,6 +39,15 @@ R""( ``` +* Print all dependant paths which do not exist in any configured binary cache: + + ```console + # nix path-info -rU /nix/store/blzxgyvrk32ki6xga10phr4sby2xf25q-geeqie-1.5.1 + /nix/store/blzxgyvrk32ki6xga10phr4sby2xf25q-geeqie-1.5.1 + /nix/store/w2vgpk3rdl6smqz7ixxywqapgagsarjf-fbida-2.14 + ... + ``` + * Print the 10 most recently added paths (using --json and the jq(1) command):