Skip to content

Commit

Permalink
path-info: implement --query-substitutes
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Jan 11, 2023
1 parent 6dd8b3b commit 12e0743
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
65 changes: 63 additions & 2 deletions src/nix/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
bool showClosureSize = false;
bool humanReadable = false;
bool showSigs = false;
bool showSubStatus = false;

CmdPathInfo()
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -87,13 +95,66 @@ 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) {

StorePathCAMap pathsMap;
for (auto & path : storePaths) {
pathsMap.emplace(path, std::nullopt);
}

SubstitutablePathInfos infos;
store->querySubstitutablePathInfos(pathsMap, infos);

StorePathSet substitutablePaths;
for (auto & info : infos) {
substitutablePaths.emplace(info.first);
}

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) {
StorePathCAMap pathsMap;
for (auto & path : storePaths) {
pathsMap.emplace(path, std::nullopt);
}

SubstitutablePathInfos infos;
store->querySubstitutablePathInfos(pathsMap, infos);

StorePathSet substitutablePaths;
for (auto & info : infos) {
substitutablePaths.emplace(info.first);
}

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);
Expand Down
9 changes: 9 additions & 0 deletions src/nix/path-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 12e0743

Please sign in to comment.