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

libstore: Deduplicate LocalFSStoreConfig::rootDir initializers

Co-authored-by: John Ericson <John.Ericson@Obsidian.Systems>
This commit is contained in:
Sergei Zimmerman 2025-09-28 18:38:57 +03:00
parent 3a64d3c0da
commit 0866ba0b4a
No known key found for this signature in database
2 changed files with 24 additions and 8 deletions

View file

@ -9,6 +9,18 @@ namespace nix {
struct LocalFSStoreConfig : virtual StoreConfig struct LocalFSStoreConfig : virtual StoreConfig
{ {
private:
static OptionalPathSetting makeRootDirSetting(LocalFSStoreConfig & self, std::optional<Path> defaultValue)
{
return {
&self,
std::move(defaultValue),
"root",
"Directory prefixed to all other paths.",
};
}
public:
using StoreConfig::StoreConfig; using StoreConfig::StoreConfig;
/** /**
@ -20,7 +32,7 @@ struct LocalFSStoreConfig : virtual StoreConfig
*/ */
LocalFSStoreConfig(PathView path, const Params & params); LocalFSStoreConfig(PathView path, const Params & params);
OptionalPathSetting rootDir{this, std::nullopt, "root", "Directory prefixed to all other paths."}; OptionalPathSetting rootDir = makeRootDirSetting(*this, std::nullopt);
private: private:

View file

@ -20,13 +20,17 @@ Path LocalFSStoreConfig::getDefaultLogDir()
LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params) LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params)
: StoreConfig(params) : StoreConfig(params)
// Default `?root` from `rootDir` if non set /* Default `?root` from `rootDir` if non set
// FIXME don't duplicate description once we don't have root setting * NOTE: We would like to just do rootDir.set(...), which would take care of
, rootDir{ * all normalization and error checking for us. Unfortunately we cannot do
this, * that because of the complicated initialization order of other fields with
!rootDir.empty() && params.count("root") == 0 ? (std::optional{canonPath(rootDir)}) : std::nullopt, * the virtual class hierarchy of nix store configs, and the design of the
"root", * settings system. As such, we have no choice but to redefine the field and
"Directory prefixed to all other paths."} * manually repeat the same normalization logic.
*/
, rootDir{makeRootDirSetting(
*this,
!rootDir.empty() && params.count("root") == 0 ? std::optional<Path>{canonPath(rootDir)} : std::nullopt)}
{ {
} }