1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Create default Store::narFromPath implementation in terms of getFSAccessor

This is a good default (the methods that allow for an arbitrary choice
of source accessor are generally preferable both to implement and to
use). And it also pays its way by allowing us to delete *both* the
`DummyStore` and `LocalStore` implementations.
This commit is contained in:
John Ericson 2025-10-27 15:48:07 -04:00
parent c5515bb22e
commit dd716dc9be
8 changed files with 11 additions and 24 deletions

View file

@ -258,18 +258,6 @@ struct DummyStoreImpl : DummyStore
}); });
} }
void narFromPath(const StorePath & path, Sink & sink) override
{
bool visited = contents.cvisit(path, [&](const auto & kv) {
const auto & [info, accessor] = kv.second;
SourcePath sourcePath(accessor);
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
});
if (!visited)
throw Error("path '%s' is not valid", printStorePath(path));
}
void queryRealisationUncached( void queryRealisationUncached(
const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
{ {

View file

@ -78,7 +78,6 @@ struct LocalFSStore : virtual Store, virtual GcStore, virtual LogStore
LocalFSStore(const Config & params); LocalFSStore(const Config & params);
void narFromPath(const StorePath & path, Sink & sink) override;
ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override; ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override; std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override;

View file

@ -609,7 +609,7 @@ public:
/** /**
* Write a NAR dump of a store path. * Write a NAR dump of a store path.
*/ */
virtual void narFromPath(const StorePath & path, Sink & sink) = 0; virtual void narFromPath(const StorePath & path, Sink & sink);
/** /**
* For each path, if it's a derivation, build it. Building a * For each path, if it's a derivation, build it. Building a

View file

@ -68,7 +68,7 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
void narFromPath(const StorePath & path, Sink & sink) override void narFromPath(const StorePath & path, Sink & sink) override
{ {
LocalFSStore::narFromPath(path, sink); Store::narFromPath(path, sink);
} }
/** /**

View file

@ -112,13 +112,6 @@ std::shared_ptr<SourceAccessor> LocalFSStore::getFSAccessor(const StorePath & pa
return std::make_shared<PosixSourceAccessor>(std::move(absPath)); return std::make_shared<PosixSourceAccessor>(std::move(absPath));
} }
void LocalFSStore::narFromPath(const StorePath & path, Sink & sink)
{
if (!isValidPath(path))
throw Error("path '%s' is not valid", printStorePath(path));
dumpPath(getRealStoreDir() + std::string(printStorePath(path), storeDir.size()), sink);
}
const std::string LocalFSStore::drvsLogDir = "drvs"; const std::string LocalFSStore::drvsLogDir = "drvs";
std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path) std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path)

View file

@ -226,7 +226,7 @@ void RestrictedStore::narFromPath(const StorePath & path, Sink & sink)
{ {
if (!goal.isAllowed(path)) if (!goal.isAllowed(path))
throw InvalidPath("cannot dump unknown path '%s' in recursive Nix", printStorePath(path)); throw InvalidPath("cannot dump unknown path '%s' in recursive Nix", printStorePath(path));
LocalFSStore::narFromPath(path, sink); Store::narFromPath(path, sink);
} }
void RestrictedStore::ensurePath(const StorePath & path) void RestrictedStore::ensurePath(const StorePath & path)

View file

@ -143,7 +143,7 @@ struct MountedSSHStore : virtual SSHStore, virtual LocalFSStore
void narFromPath(const StorePath & path, Sink & sink) override void narFromPath(const StorePath & path, Sink & sink) override
{ {
return LocalFSStore::narFromPath(path, sink); return Store::narFromPath(path, sink);
} }
ref<SourceAccessor> getFSAccessor(bool requireValidPath) override ref<SourceAccessor> getFSAccessor(bool requireValidPath) override

View file

@ -300,6 +300,13 @@ ValidPathInfo Store::addToStoreSlow(
return info; return info;
} }
void Store::narFromPath(const StorePath & path, Sink & sink)
{
auto accessor = requireStoreObjectAccessor(path);
SourcePath sourcePath{accessor};
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
}
StringSet Store::Config::getDefaultSystemFeatures() StringSet Store::Config::getDefaultSystemFeatures()
{ {
auto res = settings.systemFeatures.get(); auto res = settings.systemFeatures.get();