From 073e134de6260de7d90b135b7e173157741d4853 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 8 Mar 2022 17:45:19 +0000 Subject: [PATCH 1/4] Rename `requireGcStore` to `GcStore::require` I should have done this to begin with. This will be nicer once more Store sub-interfaces exist too, to illustrate the pattern. --- src/libstore/daemon.cc | 6 +++--- src/libstore/gc-store.cc | 2 +- src/libstore/gc-store.hh | 4 ++-- src/nix-collect-garbage/nix-collect-garbage.cc | 2 +- src/nix-store/nix-store.cc | 6 +++--- src/nix/store-delete.cc | 2 +- src/nix/store-gc.cc | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index e6760664c..ffc605410 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -645,7 +645,7 @@ static void performOp(TunnelLogger * logger, ref store, Path path = absPath(readString(from)); logger->startWork(); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); gcStore.addIndirectRoot(path); logger->stopWork(); @@ -663,7 +663,7 @@ static void performOp(TunnelLogger * logger, ref store, case wopFindRoots: { logger->startWork(); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); Roots roots = gcStore.findRoots(!trusted); logger->stopWork(); @@ -695,7 +695,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); if (options.ignoreLiveness) throw Error("you are not allowed to ignore liveness"); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); gcStore.collectGarbage(options, results); logger->stopWork(); diff --git a/src/libstore/gc-store.cc b/src/libstore/gc-store.cc index 3dbdec53b..4516cc744 100644 --- a/src/libstore/gc-store.cc +++ b/src/libstore/gc-store.cc @@ -2,7 +2,7 @@ namespace nix { -GcStore & requireGcStore(Store & store) +GcStore & GcStore::require(Store & store) { auto * gcStore = dynamic_cast(&store); if (!gcStore) diff --git a/src/libstore/gc-store.hh b/src/libstore/gc-store.hh index 829f70dc4..462cc097b 100644 --- a/src/libstore/gc-store.hh +++ b/src/libstore/gc-store.hh @@ -77,8 +77,8 @@ struct GcStore : public virtual Store /* Perform a garbage collection. */ virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0; + + static GcStore & require(Store & store); }; -GcStore & requireGcStore(Store & store); - } diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc index 4b28ea6a4..b61f0e640 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/nix-collect-garbage/nix-collect-garbage.cc @@ -81,7 +81,7 @@ static int main_nix_collect_garbage(int argc, char * * argv) // Run the actual garbage collector. if (!dryRun) { auto store = openStore(); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); options.action = GCOptions::gcDeleteDead; GCResults results; PrintFreed freed(true, results); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 8ebaf9387..33493500c 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -429,7 +429,7 @@ static void opQuery(Strings opFlags, Strings opArgs) store->computeFSClosure( args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); Roots roots = gcStore.findRoots(false); for (auto & [target, links] : roots) if (referrers.find(target) != referrers.end()) @@ -590,7 +590,7 @@ static void opGC(Strings opFlags, Strings opArgs) if (!opArgs.empty()) throw UsageError("no arguments expected"); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); if (printRoots) { Roots roots = gcStore.findRoots(false); @@ -629,7 +629,7 @@ static void opDelete(Strings opFlags, Strings opArgs) for (auto & i : opArgs) options.pathsToDelete.insert(store->followLinksToStorePath(i)); - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); GCResults results; PrintFreed freed(true, results); diff --git a/src/nix/store-delete.cc b/src/nix/store-delete.cc index aa7a8b12f..0de7efaba 100644 --- a/src/nix/store-delete.cc +++ b/src/nix/store-delete.cc @@ -33,7 +33,7 @@ struct CmdStoreDelete : StorePathsCommand void run(ref store, std::vector && storePaths) override { - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); for (auto & path : storePaths) options.pathsToDelete.insert(path); diff --git a/src/nix/store-gc.cc b/src/nix/store-gc.cc index 21718dc0c..515f4ffdb 100644 --- a/src/nix/store-gc.cc +++ b/src/nix/store-gc.cc @@ -34,7 +34,7 @@ struct CmdStoreGC : StoreCommand, MixDryRun void run(ref store) override { - auto & gcStore = requireGcStore(*store); + auto & gcStore = GcStore::require(*store); options.action = dryRun ? GCOptions::gcReturnDead : GCOptions::gcDeleteDead; GCResults results; From 89effe9d4abde2ea8970736f79e0a6a499777692 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 8 Mar 2022 18:28:29 +0000 Subject: [PATCH 2/4] `GcStore::resolve` should print the URI --- src/libstore/gc-store.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstore/gc-store.cc b/src/libstore/gc-store.cc index 4516cc744..dc2b82166 100644 --- a/src/libstore/gc-store.cc +++ b/src/libstore/gc-store.cc @@ -6,7 +6,7 @@ GcStore & GcStore::require(Store & store) { auto * gcStore = dynamic_cast(&store); if (!gcStore) - throw UsageError("Garbage collection not supported by this store"); + throw UsageError("Garbage collection not supported by store '%s'", store.getUri()); return *gcStore; } From 678d1c2aa0f499466c723d3461277dc197515f57 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 8 Mar 2022 18:20:39 +0000 Subject: [PATCH 3/4] Factor out a `LogStore` interface Continue progress on #5729. Just as I hoped, this uncovered an issue: the daemon protocol is missing a way to query build logs. This doesn't effect `unix://`, but does effect `ssh://`. A FIXME is left for this, so we come back to it later. --- src/libstore/binary-cache-store.hh | 5 ++++- src/libstore/build/local-derivation-goal.cc | 6 ++++++ src/libstore/daemon.cc | 4 +++- src/libstore/local-fs-store.hh | 6 +++++- src/libstore/log-store.cc | 13 +++++++++++++ src/libstore/log-store.hh | 19 +++++++++++++++++++ src/libstore/remote-store.hh | 6 +++++- src/libstore/ssh-store.cc | 4 ++++ src/libstore/store-api.hh | 8 -------- src/nix-store/nix-store.cc | 9 ++++++--- src/nix/log.cc | 14 +++++++++++--- src/nix/repl.cc | 12 ++++++++++-- src/nix/store-copy-log.cc | 8 ++++++-- 13 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 src/libstore/log-store.cc create mode 100644 src/libstore/log-store.hh diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index 9603a8caa..ca538b3cb 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -2,6 +2,7 @@ #include "crypto.hh" #include "store-api.hh" +#include "log-store.hh" #include "pool.hh" @@ -28,7 +29,9 @@ struct BinaryCacheStoreConfig : virtual StoreConfig "other than -1 which we reserve to indicate Nix defaults should be used"}; }; -class BinaryCacheStore : public virtual BinaryCacheStoreConfig, public virtual Store +class BinaryCacheStore : public virtual BinaryCacheStoreConfig, + public virtual Store, + public virtual LogStore { private: diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index a372728f5..4e763e570 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -1340,6 +1340,12 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo next->queryMissing(allowed, willBuild, willSubstitute, unknown, downloadSize, narSize); } + + virtual std::optional getBuildLog(const StorePath & path) override + { return std::nullopt; } + + virtual void addBuildLog(const StorePath & path, std::string_view log) override + { unsupported("addBuildLog"); } }; diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index ffc605410..1e24a1c79 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -4,6 +4,7 @@ #include "build-result.hh" #include "store-api.hh" #include "gc-store.hh" +#include "log-store.hh" #include "path-with-outputs.hh" #include "finally.hh" #include "archive.hh" @@ -953,11 +954,12 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); if (!trusted) throw Error("you are not privileged to add logs"); + auto & logStore = LogStore::require(*store); { FramedSource source(from); StringSink sink; source.drainInto(sink); - store->addBuildLog(path, sink.s); + logStore.addBuildLog(path, sink.s); } logger->stopWork(); to << 1; diff --git a/src/libstore/local-fs-store.hh b/src/libstore/local-fs-store.hh index fbd49dc2c..e6fb3201a 100644 --- a/src/libstore/local-fs-store.hh +++ b/src/libstore/local-fs-store.hh @@ -2,6 +2,7 @@ #include "store-api.hh" #include "gc-store.hh" +#include "log-store.hh" namespace nix { @@ -24,7 +25,10 @@ struct LocalFSStoreConfig : virtual StoreConfig "physical path to the Nix store"}; }; -class LocalFSStore : public virtual LocalFSStoreConfig, public virtual Store, virtual GcStore +class LocalFSStore : public virtual LocalFSStoreConfig, + public virtual Store, + public virtual GcStore, + public virtual LogStore { public: diff --git a/src/libstore/log-store.cc b/src/libstore/log-store.cc new file mode 100644 index 000000000..56aec91f2 --- /dev/null +++ b/src/libstore/log-store.cc @@ -0,0 +1,13 @@ +#include "log-store.hh" + +namespace nix { + +LogStore & LogStore::require(Store & store) +{ + auto * gcStore = dynamic_cast(&store); + if (!gcStore) + throw UsageError("Build log storage and retrieval not supported by store '%s'", store.getUri()); + return *gcStore; +} + +} diff --git a/src/libstore/log-store.hh b/src/libstore/log-store.hh new file mode 100644 index 000000000..ad17cbe6e --- /dev/null +++ b/src/libstore/log-store.hh @@ -0,0 +1,19 @@ +#pragma once + +#include "store-api.hh" + + +namespace nix { + +struct LogStore : public virtual Store +{ + /* Return the build log of the specified store path, if available, + or null otherwise. */ + virtual std::optional getBuildLog(const StorePath & path) = 0; + + virtual void addBuildLog(const StorePath & path, std::string_view log) = 0; + + static LogStore & require(Store & store); +}; + +} diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 9f6f50593..8493be6fc 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -5,6 +5,7 @@ #include "store-api.hh" #include "gc-store.hh" +#include "log-store.hh" namespace nix { @@ -30,7 +31,10 @@ struct RemoteStoreConfig : virtual StoreConfig /* FIXME: RemoteStore is a misnomer - should be something like DaemonStore. */ -class RemoteStore : public virtual RemoteStoreConfig, public virtual Store, public virtual GcStore +class RemoteStore : public virtual RemoteStoreConfig, + public virtual Store, + public virtual GcStore, + public virtual LogStore { public: diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index bb03daef4..62daa838c 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -52,6 +52,10 @@ public: bool sameMachine() override { return false; } + // FIXME extend daemon protocol, move implementation to RemoteStore + std::optional getBuildLog(const StorePath & path) override + { unsupported("getBuildLog"); } + private: struct Connection : RemoteStore::Connection diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index e99a3f2cb..635a82a2a 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -605,14 +605,6 @@ public: */ StorePathSet exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths); - /* Return the build log of the specified store path, if available, - or null otherwise. */ - virtual std::optional getBuildLog(const StorePath & path) - { return std::nullopt; } - - virtual void addBuildLog(const StorePath & path, std::string_view log) - { unsupported("addBuildLog"); } - /* Hack to allow long-running processes like hydra-queue-runner to occasionally flush their path info cache. */ void clearPathInfoCache() diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 33493500c..b3f28bcc2 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -4,6 +4,7 @@ #include "globals.hh" #include "build-result.hh" #include "gc-store.hh" +#include "log-store.hh" #include "local-store.hh" #include "monitor-fd.hh" #include "serve-protocol.hh" @@ -474,13 +475,15 @@ static void opReadLog(Strings opFlags, Strings opArgs) { if (!opFlags.empty()) throw UsageError("unknown flag"); + auto & logStore = LogStore::require(*store); + RunPager pager; for (auto & i : opArgs) { - auto path = store->followLinksToStorePath(i); - auto log = store->getBuildLog(path); + auto path = logStore.followLinksToStorePath(i); + auto log = logStore.getBuildLog(path); if (!log) - throw Error("build log of derivation '%s' is not available", store->printStorePath(path)); + throw Error("build log of derivation '%s' is not available", logStore.printStorePath(path)); std::cout << *log; } } diff --git a/src/nix/log.cc b/src/nix/log.cc index fd3c1d787..72d02ef11 100644 --- a/src/nix/log.cc +++ b/src/nix/log.cc @@ -2,6 +2,7 @@ #include "common-args.hh" #include "shared.hh" #include "store-api.hh" +#include "log-store.hh" #include "progress-bar.hh" using namespace nix; @@ -34,17 +35,24 @@ struct CmdLog : InstallableCommand RunPager pager; for (auto & sub : subs) { + auto * logSubP = dynamic_cast(&*sub); + if (!logSubP) { + printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri()); + continue; + } + auto & logSub = *logSubP; + auto log = std::visit(overloaded { [&](const DerivedPath::Opaque & bo) { - return sub->getBuildLog(bo.path); + return logSub.getBuildLog(bo.path); }, [&](const DerivedPath::Built & bfd) { - return sub->getBuildLog(bfd.drvPath); + return logSub.getBuildLog(bfd.drvPath); }, }, b.raw()); if (!log) continue; stopProgressBar(); - printInfo("got build log for '%s' from '%s'", installable->what(), sub->getUri()); + printInfo("got build log for '%s' from '%s'", installable->what(), logSub.getUri()); std::cout << *log; return; } diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 3a51a13e6..916353d8c 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -25,6 +25,7 @@ extern "C" { #include "eval-inline.hh" #include "attr-path.hh" #include "store-api.hh" +#include "log-store.hh" #include "common-eval-args.hh" #include "get-drvs.hh" #include "derivations.hh" @@ -526,9 +527,16 @@ bool NixRepl::processLine(std::string line) bool foundLog = false; RunPager pager; for (auto & sub : subs) { - auto log = sub->getBuildLog(drvPath); + auto * logSubP = dynamic_cast(&*sub); + if (!logSubP) { + printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri()); + continue; + } + auto & logSub = *logSubP; + + auto log = logSub.getBuildLog(drvPath); if (log) { - printInfo("got build log for '%s' from '%s'", drvPathRaw, sub->getUri()); + printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.getUri()); logger->writeToStdout(*log); foundLog = true; break; diff --git a/src/nix/store-copy-log.cc b/src/nix/store-copy-log.cc index 079cd6b3e..22b3980c0 100644 --- a/src/nix/store-copy-log.cc +++ b/src/nix/store-copy-log.cc @@ -1,6 +1,7 @@ #include "command.hh" #include "shared.hh" #include "store-api.hh" +#include "log-store.hh" #include "sync.hh" #include "thread-pool.hh" @@ -26,7 +27,10 @@ struct CmdCopyLog : virtual CopyCommand, virtual InstallablesCommand void run(ref srcStore) override { + auto & srcLogStore = LogStore::require(*srcStore); + auto dstStore = getDstStore(); + auto & dstLogStore = LogStore::require(*dstStore); StorePathSet drvPaths; @@ -35,8 +39,8 @@ struct CmdCopyLog : virtual CopyCommand, virtual InstallablesCommand drvPaths.insert(drvPath); for (auto & drvPath : drvPaths) { - if (auto log = srcStore->getBuildLog(drvPath)) - dstStore->addBuildLog(drvPath, *log); + if (auto log = srcLogStore.getBuildLog(drvPath)) + dstLogStore.addBuildLog(drvPath, *log); else throw Error("build log for '%s' is not available", srcStore->printStorePath(drvPath)); } From a03b1fd7f60788304f358d5f4dc063c7c9e650a9 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 9 Mar 2022 15:27:48 +0000 Subject: [PATCH 4/4] Deduplicate the Store downcasting with a template --- src/libstore/daemon.cc | 9 +++++---- src/libstore/gc-store.cc | 13 ------------- src/libstore/gc-store.hh | 4 ++-- src/libstore/log-store.cc | 13 ------------- src/libstore/log-store.hh | 2 ++ src/libstore/store-cast.hh | 16 ++++++++++++++++ src/nix-collect-garbage/nix-collect-garbage.cc | 3 ++- src/nix-store/nix-store.cc | 9 +++++---- src/nix/store-copy-log.cc | 5 +++-- src/nix/store-delete.cc | 3 ++- src/nix/store-gc.cc | 3 ++- 11 files changed, 39 insertions(+), 41 deletions(-) delete mode 100644 src/libstore/gc-store.cc delete mode 100644 src/libstore/log-store.cc create mode 100644 src/libstore/store-cast.hh diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 1e24a1c79..9f21ecf36 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -3,6 +3,7 @@ #include "worker-protocol.hh" #include "build-result.hh" #include "store-api.hh" +#include "store-cast.hh" #include "gc-store.hh" #include "log-store.hh" #include "path-with-outputs.hh" @@ -646,7 +647,7 @@ static void performOp(TunnelLogger * logger, ref store, Path path = absPath(readString(from)); logger->startWork(); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); gcStore.addIndirectRoot(path); logger->stopWork(); @@ -664,7 +665,7 @@ static void performOp(TunnelLogger * logger, ref store, case wopFindRoots: { logger->startWork(); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); Roots roots = gcStore.findRoots(!trusted); logger->stopWork(); @@ -696,7 +697,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); if (options.ignoreLiveness) throw Error("you are not allowed to ignore liveness"); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); gcStore.collectGarbage(options, results); logger->stopWork(); @@ -954,7 +955,7 @@ static void performOp(TunnelLogger * logger, ref store, logger->startWork(); if (!trusted) throw Error("you are not privileged to add logs"); - auto & logStore = LogStore::require(*store); + auto & logStore = require(*store); { FramedSource source(from); StringSink sink; diff --git a/src/libstore/gc-store.cc b/src/libstore/gc-store.cc deleted file mode 100644 index dc2b82166..000000000 --- a/src/libstore/gc-store.cc +++ /dev/null @@ -1,13 +0,0 @@ -#include "gc-store.hh" - -namespace nix { - -GcStore & GcStore::require(Store & store) -{ - auto * gcStore = dynamic_cast(&store); - if (!gcStore) - throw UsageError("Garbage collection not supported by store '%s'", store.getUri()); - return *gcStore; -} - -} diff --git a/src/libstore/gc-store.hh b/src/libstore/gc-store.hh index 462cc097b..b3cbbad74 100644 --- a/src/libstore/gc-store.hh +++ b/src/libstore/gc-store.hh @@ -61,6 +61,8 @@ struct GCResults struct GcStore : public virtual Store { + inline static std::string operationName = "Garbage collection"; + /* Add an indirect root, which is merely a symlink to `path' from /nix/var/nix/gcroots/auto/. `path' is supposed to be a symlink to a store path. The garbage collector will @@ -77,8 +79,6 @@ struct GcStore : public virtual Store /* Perform a garbage collection. */ virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0; - - static GcStore & require(Store & store); }; } diff --git a/src/libstore/log-store.cc b/src/libstore/log-store.cc deleted file mode 100644 index 56aec91f2..000000000 --- a/src/libstore/log-store.cc +++ /dev/null @@ -1,13 +0,0 @@ -#include "log-store.hh" - -namespace nix { - -LogStore & LogStore::require(Store & store) -{ - auto * gcStore = dynamic_cast(&store); - if (!gcStore) - throw UsageError("Build log storage and retrieval not supported by store '%s'", store.getUri()); - return *gcStore; -} - -} diff --git a/src/libstore/log-store.hh b/src/libstore/log-store.hh index ad17cbe6e..ff1b92e17 100644 --- a/src/libstore/log-store.hh +++ b/src/libstore/log-store.hh @@ -7,6 +7,8 @@ namespace nix { struct LogStore : public virtual Store { + inline static std::string operationName = "Build log storage and retrieval"; + /* Return the build log of the specified store path, if available, or null otherwise. */ virtual std::optional getBuildLog(const StorePath & path) = 0; diff --git a/src/libstore/store-cast.hh b/src/libstore/store-cast.hh new file mode 100644 index 000000000..ff62fc359 --- /dev/null +++ b/src/libstore/store-cast.hh @@ -0,0 +1,16 @@ +#pragma once + +#include "store-api.hh" + +namespace nix { + +template +T & require(Store & store) +{ + auto * castedStore = dynamic_cast(&store); + if (!castedStore) + throw UsageError("%s not supported by store '%s'", T::operationName, store.getUri()); + return *castedStore; +} + +} diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc index b61f0e640..af6f1c88c 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/nix-collect-garbage/nix-collect-garbage.cc @@ -1,4 +1,5 @@ #include "store-api.hh" +#include "store-cast.hh" #include "gc-store.hh" #include "profiles.hh" #include "shared.hh" @@ -81,7 +82,7 @@ static int main_nix_collect_garbage(int argc, char * * argv) // Run the actual garbage collector. if (!dryRun) { auto store = openStore(); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); options.action = GCOptions::gcDeleteDead; GCResults results; PrintFreed freed(true, results); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index b3f28bcc2..153b84137 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -3,6 +3,7 @@ #include "dotgraph.hh" #include "globals.hh" #include "build-result.hh" +#include "store-cast.hh" #include "gc-store.hh" #include "log-store.hh" #include "local-store.hh" @@ -430,7 +431,7 @@ static void opQuery(Strings opFlags, Strings opArgs) store->computeFSClosure( args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); Roots roots = gcStore.findRoots(false); for (auto & [target, links] : roots) if (referrers.find(target) != referrers.end()) @@ -475,7 +476,7 @@ static void opReadLog(Strings opFlags, Strings opArgs) { if (!opFlags.empty()) throw UsageError("unknown flag"); - auto & logStore = LogStore::require(*store); + auto & logStore = require(*store); RunPager pager; @@ -593,7 +594,7 @@ static void opGC(Strings opFlags, Strings opArgs) if (!opArgs.empty()) throw UsageError("no arguments expected"); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); if (printRoots) { Roots roots = gcStore.findRoots(false); @@ -632,7 +633,7 @@ static void opDelete(Strings opFlags, Strings opArgs) for (auto & i : opArgs) options.pathsToDelete.insert(store->followLinksToStorePath(i)); - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); GCResults results; PrintFreed freed(true, results); diff --git a/src/nix/store-copy-log.cc b/src/nix/store-copy-log.cc index 22b3980c0..2e288f743 100644 --- a/src/nix/store-copy-log.cc +++ b/src/nix/store-copy-log.cc @@ -1,6 +1,7 @@ #include "command.hh" #include "shared.hh" #include "store-api.hh" +#include "store-cast.hh" #include "log-store.hh" #include "sync.hh" #include "thread-pool.hh" @@ -27,10 +28,10 @@ struct CmdCopyLog : virtual CopyCommand, virtual InstallablesCommand void run(ref srcStore) override { - auto & srcLogStore = LogStore::require(*srcStore); + auto & srcLogStore = require(*srcStore); auto dstStore = getDstStore(); - auto & dstLogStore = LogStore::require(*dstStore); + auto & dstLogStore = require(*dstStore); StorePathSet drvPaths; diff --git a/src/nix/store-delete.cc b/src/nix/store-delete.cc index 0de7efaba..ca43f1530 100644 --- a/src/nix/store-delete.cc +++ b/src/nix/store-delete.cc @@ -2,6 +2,7 @@ #include "common-args.hh" #include "shared.hh" #include "store-api.hh" +#include "store-cast.hh" #include "gc-store.hh" using namespace nix; @@ -33,7 +34,7 @@ struct CmdStoreDelete : StorePathsCommand void run(ref store, std::vector && storePaths) override { - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); for (auto & path : storePaths) options.pathsToDelete.insert(path); diff --git a/src/nix/store-gc.cc b/src/nix/store-gc.cc index 515f4ffdb..8b9b5d164 100644 --- a/src/nix/store-gc.cc +++ b/src/nix/store-gc.cc @@ -2,6 +2,7 @@ #include "common-args.hh" #include "shared.hh" #include "store-api.hh" +#include "store-cast.hh" #include "gc-store.hh" using namespace nix; @@ -34,7 +35,7 @@ struct CmdStoreGC : StoreCommand, MixDryRun void run(ref store) override { - auto & gcStore = GcStore::require(*store); + auto & gcStore = require(*store); options.action = dryRun ? GCOptions::gcReturnDead : GCOptions::gcDeleteDead; GCResults results;