Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path-info: implement --filter-substitutable #7587

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 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,14 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
.description = "Show signatures.",
.handler = {&showSigs, true},
});

addFlag({
.longName = "filter-substitutable",
.description =
"Query path availability in the configured substituters, printing only those that are not available. "
"When used with `--json`, a `substitutable` boolean is added to the output.",
.handler = {&showSubStatus, true},
});
}

std::string description() override
Expand Down Expand Up @@ -86,14 +95,36 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
for (auto & storePath : storePaths)
pathLen = std::max(pathLen, store->printStorePath(storePath).size());

StorePathSet substitutablePaths;
if (showSubStatus)
substitutablePaths = store->querySubstitutablePaths(StorePathSet(storePaths.begin(), storePaths.end()));

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) {
for (auto & v : json) {
std::string const storePathS = v["path"];
v["substitutable"] = (bool) substitutablePaths.count(store->parseStorePath(storePathS));
}
}
std::cout << json.dump();
}

else {
StorePaths missingPaths;

if (showSubStatus) {
for (auto & path : storePaths) {
if (!substitutablePaths.count(path))
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 -r --filter-substitutable /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