1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +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:
Eelco Dolstra 2017-04-13 15:55:38 +02:00
parent 568a099c88
commit 2040240e23
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
16 changed files with 334 additions and 40 deletions

View file

@ -241,8 +241,8 @@ Path Store::computeStorePathForText(const string & name, const string & s,
Store::Store(const Params & params)
: storeDir(get(params, "store", settings.nixStore))
, state({std::stoi(get(params, "path-info-cache-size", "65536"))})
: Config(params)
, state({(size_t) pathInfoCacheSize})
{
}
@ -718,7 +718,10 @@ ref<Store> openStore(const std::string & uri, const Store::Params & params)
{
for (auto fun : *RegisterStoreImplementation::implementations) {
auto store = fun(uri, params);
if (store) return ref<Store>(store);
if (store) {
store->warnUnused();
return ref<Store>(store);
}
}
throw Error(format("don't know how to open Nix store %s") % uri);