Skip to content

Commit

Permalink
nix-store: implement --query --unsubstitutable
Browse files Browse the repository at this point in the history
Resolves NixOS#3946 by providing an efficient means of querying cache status
of the passed paths.

For every path passed, it will be returned on standard output only if it
is not available in any of the configured substituters.
  • Loading branch information
nrdxp committed Jan 11, 2023
1 parent 6dd8b3b commit 6d692d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
16 changes: 15 additions & 1 deletion doc/manual/src/command-ref/nix-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ error: cannot delete path `/nix/store/zq0h41l75vlb4z45kzgjjmsjxvcv1qk7-mesa-6.4'
{`--outputs` | `--requisites` | `-R` | `--references` |
`--referrers` | `--referrers-closure` | `--deriver` | `-d` |
`--graph` | `--tree` | `--binding` *name* | `-b` *name* | `--hash` |
`--size` | `--roots`}
`--size` | `--roots` | `--unsubstitutable` | `-U`}
[`--use-output`] [`-u`] [`--force-realise`] [`-f`]
*paths…*

Expand Down Expand Up @@ -405,6 +405,10 @@ symlink.
Prints the garbage collector roots that point, directly or
indirectly, at the store paths *paths*.

- `--unsubstitutable`; `-U`\
Outputs a list of the store paths *paths* which are not available in
any configured substituters.

## Examples

Print the closure (runtime dependencies) of the `svn` program in the
Expand Down Expand Up @@ -443,6 +447,16 @@ $ nix-store -q --tree $(nix-store -qd $(which svn))
...
```

Show unsubstitutable build & runtime dependencies:

```console
$ drv=$(nix-store -qd $(which svn))
$ nix-store -qU $(nix-store -qR --include-outputs $drv)
/nix/store/5mbglq5ldqld8sj57273aljwkfvj22mc-subversion-1.1.4
/nix/store/9lz9yc6zgmc0vlqmn2ipcpkjlmbi51vv-glibc-2.3.4
...
```

Show all paths that depend on the same OpenSSL library as `svn`:

```console
Expand Down
22 changes: 20 additions & 2 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
enum QueryType
{ qDefault, qOutputs, qRequisites, qReferences, qReferrers
, qReferrersClosure, qDeriver, qBinding, qHash, qSize
, qTree, qGraph, qGraphML, qResolve, qRoots };
, qTree, qGraph, qGraphML, qResolve, qRoots, qUnsubstitutable };
QueryType query = qDefault;
bool useOutput = false;
bool includeOutputs = false;
Expand All @@ -300,6 +300,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
}
else if (i == "--hash") query = qHash;
else if (i == "--size") query = qSize;
else if (i == "--unsubstitutable" || i == "-U") query = qUnsubstitutable;
else if (i == "--tree") query = qTree;
else if (i == "--graph") query = qGraph;
else if (i == "--graphml") query = qGraphML;
Expand Down Expand Up @@ -364,6 +365,24 @@ static void opQuery(Strings opFlags, Strings opArgs)
}
break;

case qUnsubstitutable: {
if (opArgs.empty()) throw UsageError("no paths passed");

StorePathSet inputPaths = {};
for (auto & str : opArgs) {
inputPaths.emplace(store->followLinksToStorePath(str));
}

auto substitutablePaths = store->querySubstitutablePaths(inputPaths);

for ( auto & path : inputPaths) {
if (substitutablePaths.find(path) == substitutablePaths.end())
std::cout << '\n' << store->printStorePath(path);
}
std::cout << std::endl;
break;
}

case qBinding:
for (auto & i : opArgs) {
auto path = useDeriver(store->followLinksToStorePath(i));
Expand Down Expand Up @@ -680,7 +699,6 @@ static void opExport(Strings opFlags, Strings opArgs)
sink.flush();
}


static void opImport(Strings opFlags, Strings opArgs)
{
for (auto & i : opFlags)
Expand Down

0 comments on commit 6d692d5

Please sign in to comment.