Skip to content

Commit

Permalink
path-info: implement --filter-substitutable
Browse files Browse the repository at this point in the history
Fixes NixOS#3946

Filters out any paths from the output which are already available in
the configured substituters. Useful in CI environments, to avoid builds
that are already cached.
  • Loading branch information
nrdxp committed Jan 31, 2023
1 parent eaa20f2 commit fb30259
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
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

0 comments on commit fb30259

Please sign in to comment.