1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 01:09:37 +01:00

Relegate toRealPath to LocalFSStore

Fix #14480

This method is not well-defined for arbitrary stores, which do not have
a notion of a "real path" -- it is only well-defined for local file
systems stores, which do have exactly that notion, and so it is moved to
that sub-interface instead.

Some call-sites had to be fixed up for this, but in all cases the
changes are positive. Using `getFSSourceAccessor` allows for more other
stores to work properly. `nix-channel` was straight-up wrong in the case
of redirected local stores. And the building logic with remote building
and a non-local store is also fixed, properly gating some deletions on
store type.

Co-authored-by: Robert Hensing <robert@roberthensing.nl>
This commit is contained in:
John Ericson 2025-11-05 10:03:49 -05:00
parent 948c89b367
commit 099af7578f
12 changed files with 63 additions and 55 deletions

View file

@ -286,7 +286,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
PathSet lockFiles;
/* FIXME: Should lock something like the drv itself so we don't build same
CA drv concurrently */
if (dynamic_cast<LocalStore *>(&worker.store)) {
if (auto * localStore = dynamic_cast<LocalStore *>(&worker.store)) {
/* If we aren't a local store, we might need to use the local store as
a build remote, but that would cause a deadlock. */
/* FIXME: Make it so we can use ourselves as a build remote even if we
@ -296,9 +296,9 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
*/
for (auto & i : drv->outputsAndOptPaths(worker.store)) {
if (i.second.second)
lockFiles.insert(worker.store.Store::toRealPath(*i.second.second));
lockFiles.insert(localStore->toRealPath(*i.second.second));
else
lockFiles.insert(worker.store.Store::toRealPath(drvPath) + "." + i.first);
lockFiles.insert(localStore->toRealPath(drvPath) + "." + i.first);
}
}
@ -331,12 +331,14 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
/* If any of the outputs already exist but are not valid, delete
them. */
for (auto & [_, status] : initialOutputs) {
if (!status.known || status.known->isValid())
continue;
auto storePath = status.known->path;
debug("removing invalid path '%s'", worker.store.printStorePath(status.known->path));
deletePath(worker.store.Store::toRealPath(storePath));
if (auto * localStore = dynamic_cast<LocalFSStore *>(&worker.store)) {
for (auto & [_, status] : initialOutputs) {
if (!status.known || status.known->isValid())
continue;
auto storePath = status.known->path;
debug("removing invalid path '%s'", worker.store.printStorePath(status.known->path));
deletePath(localStore->toRealPath(storePath));
}
}
/* Don't do a remote build if the derivation has the attribute

View file

@ -896,7 +896,7 @@ static void performOp(
auto path = WorkerProto::Serialise<StorePath>::read(*store, rconn);
logger->startWork();
logger->stopWork();
dumpPath(store->toRealPath(path), conn.to);
store->narFromPath(path, conn.to);
break;
}

View file

@ -102,7 +102,12 @@ struct LocalFSStore : virtual Store, virtual GcStore, virtual LogStore
return config.realStoreDir;
}
Path toRealPath(const Path & storePath) override
Path toRealPath(const StorePath & storePath)
{
return toRealPath(printStorePath(storePath));
}
Path toRealPath(const Path & storePath)
{
assert(isInStore(storePath));
return getRealStoreDir() + "/" + std::string(storePath, storeDir.size() + 1);

View file

@ -895,16 +895,6 @@ public:
*/
virtual std::optional<TrustedFlag> isTrustedClient() = 0;
virtual Path toRealPath(const Path & storePath)
{
return storePath;
}
Path toRealPath(const StorePath & storePath)
{
return toRealPath(printStorePath(storePath));
}
/**
* Synchronises the options of the client with those of the daemon
* (a no-op when theres no daemon)

View file

@ -246,7 +246,7 @@ void LocalOverlayStore::optimiseStore()
if (lowerStore->isValidPath(path)) {
uint64_t bytesFreed = 0;
// Deduplicate store path
deleteStorePath(Store::toRealPath(path), bytesFreed);
deleteStorePath(toRealPath(path), bytesFreed);
}
done++;
act.progress(done, paths.size());

View file

@ -1063,7 +1063,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, RepairF
PathLocks outputLock;
auto realPath = Store::toRealPath(info.path);
auto realPath = toRealPath(info.path);
/* Lock the output path. But don't lock if we're being called
from a build hook (whose parent process already acquired a
@ -1262,7 +1262,7 @@ StorePath LocalStore::addToStoreFromDump(
/* The first check above is an optimisation to prevent
unnecessary lock acquisition. */
auto realPath = Store::toRealPath(dstPath);
auto realPath = toRealPath(dstPath);
PathLocks outputLock({realPath});
@ -1413,7 +1413,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
auto hashSink = HashSink(info->narHash.algo);
dumpPath(Store::toRealPath(i), hashSink);
dumpPath(toRealPath(i), hashSink);
auto current = hashSink.finish();
if (info->narHash != nullHash && info->narHash != current.hash) {

View file

@ -58,7 +58,7 @@ struct ChrootDerivationBuilder : virtual DerivationBuilderImpl
environment using bind-mounts. We put it in the Nix store
so that the build outputs can be moved efficiently from the
chroot to their final location. */
auto chrootParentDir = store.Store::toRealPath(drvPath) + ".chroot";
auto chrootParentDir = store.toRealPath(drvPath) + ".chroot";
deletePath(chrootParentDir);
/* Clean up the chroot directory automatically. */
@ -171,7 +171,7 @@ struct ChrootDerivationBuilder : virtual DerivationBuilderImpl
continue;
if (buildMode != bmCheck && status.known->isValid())
continue;
auto p = store.Store::toRealPath(status.known->path);
auto p = store.toRealPath(status.known->path);
if (pathExists(chrootRootDir + p))
std::filesystem::rename((chrootRootDir + p), p);
}
@ -185,7 +185,7 @@ struct ChrootDerivationBuilder : virtual DerivationBuilderImpl
debug("materialising '%s' in the sandbox", store.printStorePath(path));
Path source = store.Store::toRealPath(path);
Path source = store.toRealPath(path);
Path target = chrootRootDir + store.printStorePath(path);
if (pathExists(target)) {

View file

@ -1887,7 +1887,7 @@ void DerivationBuilderImpl::cleanupBuild(bool force)
if (force) {
/* Delete unused redirected outputs (when doing hash rewriting). */
for (auto & i : redirectedOutputs)
deletePath(store.Store::toRealPath(i.second));
deletePath(store.toRealPath(i.second));
}
if (topTmpDir != "") {