From 76467e1e7ecfa1fe2dee39e674f4ab17c3af2269 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Wed, 28 Dec 2022 20:53:43 -0700 Subject: [PATCH] nix-store: implement --query --unsubstitutable Resolves #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. --- doc/manual/src/command-ref/nix-store.md | 16 +++++++++++++++- src/nix-store/nix-store.cc | 22 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/doc/manual/src/command-ref/nix-store.md b/doc/manual/src/command-ref/nix-store.md index 6d0e02ca5ae..a560128b351 100644 --- a/doc/manual/src/command-ref/nix-store.md +++ b/doc/manual/src/command-ref/nix-store.md @@ -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…* @@ -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 @@ -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 diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 3bbefedbe07..174bc5abe80 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -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; @@ -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; @@ -364,6 +365,24 @@ static void opQuery(Strings opFlags, Strings opArgs) } break; + case qUnsubstitutable: { + if (opArgs.empty()) throw UsageError("no paths passed"); + + StorePathSet storePaths; + for (auto const & str : opArgs) { + storePaths.emplace(store->followLinksToStorePath(str)); + } + + auto substitutablePaths = store->querySubstitutablePaths(storePaths); + + for ( auto & path : storePaths) { + 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)); @@ -680,7 +699,6 @@ static void opExport(Strings opFlags, Strings opArgs) sink.flush(); } - static void opImport(Strings opFlags, Strings opArgs) { for (auto & i : opFlags)