Merge pull request #15218 from obsidiansystems/read-only-per-store

libstore: make substitution use the per-store `getReadOnly` method
This commit is contained in:
John Ericson
2026-02-13 01:31:32 +00:00
committed by GitHub
7 changed files with 26 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ Goal::Co PathSubstitutionGoal::init()
co_return doneSuccess(BuildResult::Success{.status = BuildResult::Success::AlreadyValid});
}
if (settings.readOnlyMode)
if (worker.store.config.getReadOnly())
throw Error(
"cannot substitute path '%s' - no write access to the Nix store", worker.store.printStorePath(storePath));

View File

@@ -119,6 +119,11 @@ ref<Store> DummyStoreConfig::openStore() const
return openDummyStore();
}
bool DummyStoreConfig::getReadOnly() const
{
return readOnly.get() || StoreConfig::getReadOnly();
}
struct DummyStoreImpl : DummyStore
{
using Config = DummyStoreConfig;

View File

@@ -35,6 +35,8 @@ struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>,
No additional memory will be used, because no information needs to be stored.
)"};
bool getReadOnly() const override;
static const std::string name()
{
return "Dummy Store";

View File

@@ -117,6 +117,8 @@ public:
> While the filesystem the database resides on might appear to be read-only, consider whether another user or system might have write access to it.
)"};
bool getReadOnly() const override;
Setting<bool> ignoreGcDeleteFailure{
this,
false,

View File

@@ -218,6 +218,12 @@ struct StoreConfig : public StoreConfigBase, public StoreDirConfig
// Don't document the machine-specific default value
false};
/**
* Whether we're allowed to write to this store, also takes into account
* global `readOnly`'s mode setting, not just any per-store settings.
*/
virtual bool getReadOnly() const;
/**
* Open a store of the type corresponding to this configuration
* type.

View File

@@ -473,6 +473,11 @@ StoreReference LocalStoreConfig::getReference() const
};
}
bool LocalStoreConfig::getReadOnly() const
{
return readOnly.get() || StoreConfig::getReadOnly();
}
int LocalStore::getSchema()
{
int curSchema = 0;

View File

@@ -333,6 +333,11 @@ StoreReference StoreConfig::getReference() const
return {.variant = StoreReference::Auto{}};
}
bool StoreConfig::getReadOnly() const
{
return settings.readOnlyMode;
}
bool Store::PathInfoCacheValue::isKnownNow()
{
std::chrono::duration ttl = didExist() ? std::chrono::seconds(settings.ttlPositiveNarInfoCache)