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

Give DerivationBuilder a LocalStore not Store

This is just more honest, since we downcasted it to `LocalStore` in many
places. We had the downcast before because it wasn't needed in the hook
case, just the local building case, but now that `DerivationBuilder` is
separated and just does the building case, we have formalized the
boundary where the single downcast should occur.
This commit is contained in:
John Ericson 2025-08-14 10:44:13 -04:00
parent 14e355d87d
commit 4bc9ae67c7
6 changed files with 24 additions and 34 deletions

View file

@ -673,10 +673,13 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
}
};
auto * localStoreP = dynamic_cast<LocalStore *>(&worker.store);
assert(localStoreP);
/* If we have to wait and retry (see below), then `builder` will
already be created, so we don't need to create it again. */
builder = makeDerivationBuilder(
worker.store,
*localStoreP,
std::make_unique<DerivationBuildingGoalCallbacks>(*this, builder),
DerivationBuilderParams{
drvPath,

View file

@ -5,7 +5,7 @@ namespace nix {
struct ChrootDerivationBuilder : virtual DerivationBuilderImpl
{
ChrootDerivationBuilder(
Store & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
: DerivationBuilderImpl{store, std::move(miscMethods), std::move(params)}
{
}
@ -178,7 +178,7 @@ struct ChrootDerivationBuilder : virtual DerivationBuilderImpl
continue;
if (buildMode != bmCheck && status.known->isValid())
continue;
auto p = store.toRealPath(status.known->path);
auto p = store.Store::toRealPath(status.known->path);
if (pathExists(chrootRootDir + p))
std::filesystem::rename((chrootRootDir + p), p);
}

View file

@ -21,7 +21,7 @@ struct DarwinDerivationBuilder : DerivationBuilderImpl
bool useSandbox;
DarwinDerivationBuilder(
Store & store,
LocalStore & store,
std::unique_ptr<DerivationBuilderCallbacks> miscMethods,
DerivationBuilderParams params,
bool useSandbox)

View file

@ -61,14 +61,14 @@ class DerivationBuilderImpl : public DerivationBuilder, public DerivationBuilder
{
protected:
Store & store;
LocalStore & store;
std::unique_ptr<DerivationBuilderCallbacks> miscMethods;
public:
DerivationBuilderImpl(
Store & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
: DerivationBuilderParams{std::move(params)}
, store{store}
, miscMethods{std::move(miscMethods)}
@ -424,13 +424,6 @@ void handleDiffHook(
const Path DerivationBuilderImpl::homeDir = "/homeless-shelter";
static LocalStore & getLocalStore(Store & store)
{
auto p = dynamic_cast<LocalStore *>(&store);
assert(p);
return *p;
}
void DerivationBuilderImpl::killSandbox(bool getStats)
{
if (buildUser) {
@ -631,10 +624,9 @@ bool DerivationBuilderImpl::decideWhetherDiskFull()
so, we don't mark this build as a permanent failure. */
#if HAVE_STATVFS
{
auto & localStore = getLocalStore(store);
uint64_t required = 8ULL * 1024 * 1024; // FIXME: make configurable
struct statvfs st;
if (statvfs(localStore.config->realStoreDir.get().c_str(), &st) == 0
if (statvfs(store.config->realStoreDir.get().c_str(), &st) == 0
&& (uint64_t) st.f_bavail * st.f_bsize < required)
diskFull = true;
if (statvfs(tmpDir.c_str(), &st) == 0 && (uint64_t) st.f_bavail * st.f_bsize < required)
@ -712,7 +704,7 @@ void DerivationBuilderImpl::startBuilder()
Magenta(drv.platform),
concatStringsSep(", ", drvOptions.getRequiredSystemFeatures(drv)),
Magenta(settings.thisSystem),
concatStringsSep<StringSet>(", ", store.config.systemFeatures));
concatStringsSep<StringSet>(", ", store.Store::config.systemFeatures));
// since aarch64-darwin has Rosetta 2, this user can actually run x86_64-darwin on their hardware - we should
// tell them to run the command to install Darwin 2
@ -724,7 +716,7 @@ void DerivationBuilderImpl::startBuilder()
throw BuildError(msg);
}
auto buildDir = getLocalStore(store).config->getBuildDir();
auto buildDir = store.config->getBuildDir();
createDirs(buildDir);
@ -1173,7 +1165,7 @@ void DerivationBuilderImpl::startDaemon()
auto store = makeRestrictedStore(
[&] {
auto config = make_ref<LocalStore::Config>(*getLocalStore(this->store).config);
auto config = make_ref<LocalStore::Config>(*this->store.config);
config->pathInfoCacheSize = 0;
config->stateDir = "/no-such-path";
config->logDir = "/no-such-path";
@ -1839,8 +1831,6 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
}
}
auto & localStore = getLocalStore(store);
if (buildMode == bmCheck) {
if (!store.isValidPath(newInfo.path))
@ -1876,8 +1866,8 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
/* Since we verified the build, it's now ultimately trusted. */
if (!oldInfo.ultimate) {
oldInfo.ultimate = true;
localStore.signPathInfo(oldInfo);
localStore.registerValidPaths({{oldInfo.path, oldInfo}});
store.signPathInfo(oldInfo);
store.registerValidPaths({{oldInfo.path, oldInfo}});
}
continue;
@ -1891,12 +1881,12 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
debug("unreferenced input: '%1%'", store.printStorePath(i));
}
localStore.optimisePath(actualPath, NoRepair); // FIXME: combine with scanForReferences()
store.optimisePath(actualPath, NoRepair); // FIXME: combine with scanForReferences()
miscMethods->markContentsGood(newInfo.path);
newInfo.deriver = drvPath;
newInfo.ultimate = true;
localStore.signPathInfo(newInfo);
store.signPathInfo(newInfo);
finish(newInfo.path);
@ -1904,7 +1894,7 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
isn't statically known so that we can safely unlock the path before
the next iteration */
if (newInfo.ca)
localStore.registerValidPaths({{newInfo.path, newInfo}});
store.registerValidPaths({{newInfo.path, newInfo}});
infos.emplace(outputName, std::move(newInfo));
}
@ -1925,13 +1915,11 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
paths referenced by each of them. If there are cycles in the
outputs, this will fail. */
{
auto & localStore = getLocalStore(store);
ValidPathInfos infos2;
for (auto & [outputName, newInfo] : infos) {
infos2.insert_or_assign(newInfo.path, newInfo);
}
localStore.registerValidPaths(infos2);
store.registerValidPaths(infos2);
}
/* In case of a fixed-output derivation hash mismatch, throw an
@ -2164,7 +2152,7 @@ StorePath DerivationBuilderImpl::makeFallbackPath(const StorePath & path)
namespace nix {
std::unique_ptr<DerivationBuilder> makeDerivationBuilder(
Store & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
{
bool useSandbox = false;
@ -2191,8 +2179,7 @@ std::unique_ptr<DerivationBuilder> makeDerivationBuilder(
useSandbox = params.drv.type().isSandboxed() && !params.drvOptions.noChroot;
}
auto & localStore = getLocalStore(store);
if (localStore.storeDir != localStore.config->realStoreDir.get()) {
if (store.storeDir != store.config->realStoreDir.get()) {
#ifdef __linux__
useSandbox = true;
#else

View file

@ -191,7 +191,7 @@ struct ChrootLinuxDerivationBuilder : ChrootDerivationBuilder, LinuxDerivationBu
std::optional<Path> cgroup;
ChrootLinuxDerivationBuilder(
Store & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
: DerivationBuilderImpl{store, std::move(miscMethods), std::move(params)}
, ChrootDerivationBuilder{store, std::move(miscMethods), std::move(params)}
, LinuxDerivationBuilder{store, std::move(miscMethods), std::move(params)}
@ -492,7 +492,7 @@ struct ChrootLinuxDerivationBuilder : ChrootDerivationBuilder, LinuxDerivationBu
createDirs(chrootRootDir + "/dev/shm");
createDirs(chrootRootDir + "/dev/pts");
ss.push_back("/dev/full");
if (store.config.systemFeatures.get().count("kvm") && pathExists("/dev/kvm"))
if (store.Store::config.systemFeatures.get().count("kvm") && pathExists("/dev/kvm"))
ss.push_back("/dev/kvm");
ss.push_back("/dev/null");
ss.push_back("/dev/random");

View file

@ -179,6 +179,6 @@ struct DerivationBuilder : RestrictionContext
};
std::unique_ptr<DerivationBuilder> makeDerivationBuilder(
Store & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params);
LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params);
} // namespace nix