mirror of
https://github.com/NixOS/nix
synced 2025-06-29 02:11:15 +02:00
Add a Config class to simplify adding configuration settings
The typical use is to inherit Config and add Setting<T> members: class MyClass : private Config { Setting<int> foo{this, 123, "foo", "the number of foos to use"}; Setting<std::string> bar{this, "blabla", "bar", "the name of the bar"}; MyClass() : Config(readConfigFile("/etc/my-app.conf")) { std::cout << foo << "\n"; // will print 123 unless overriden } }; Currently, this is used by Store and its subclasses for store parameters. You now get a warning if you specify a non-existant store parameter in a store URI.
This commit is contained in:
parent
568a099c88
commit
2040240e23
16 changed files with 334 additions and 40 deletions
|
@ -6,6 +6,7 @@
|
|||
#include "lru-cache.hh"
|
||||
#include "sync.hh"
|
||||
#include "globals.hh"
|
||||
#include "config.hh"
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
|
@ -224,13 +225,17 @@ struct BuildResult
|
|||
};
|
||||
|
||||
|
||||
class Store : public std::enable_shared_from_this<Store>
|
||||
class Store : public std::enable_shared_from_this<Store>, public Config
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::string, std::string> Params;
|
||||
|
||||
const Path storeDir;
|
||||
const PathSetting storeDir_{this, false, settings.nixStore,
|
||||
"store", "path to the Nix store"};
|
||||
const Path storeDir = storeDir_;
|
||||
|
||||
const Setting<int> pathInfoCacheSize{this, 65536, "path-info-cache-size", "size of the in-memory store path information cache"};
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -585,9 +590,19 @@ protected:
|
|||
class LocalFSStore : public virtual Store
|
||||
{
|
||||
public:
|
||||
const Path rootDir;
|
||||
const Path stateDir;
|
||||
const Path logDir;
|
||||
|
||||
// FIXME: the (Store*) cast works around a bug in gcc that causes
|
||||
// it to emit the call to the Option constructor. Clang works fine
|
||||
// either way.
|
||||
const PathSetting rootDir{(Store*) this, true, "",
|
||||
"root", "directory prefixed to all other paths"};
|
||||
const PathSetting stateDir{(Store*) this, false,
|
||||
rootDir != "" ? rootDir + "/nix/var/nix" : settings.nixStateDir,
|
||||
"state", "directory where Nix will store state"};
|
||||
const PathSetting logDir{(Store*) this, false,
|
||||
rootDir != "" ? rootDir + "/nix/var/log/nix" : settings.nixLogDir,
|
||||
"log", "directory where Nix will store state"};
|
||||
|
||||
const static string drvsLogDir;
|
||||
|
||||
LocalFSStore(const Params & params);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue