Modularize config settings

Allow global config settings to be defined in multiple Config
classes. For example, this means that libutil can have settings and
evaluator settings can be moved out of libstore. The Config classes
are registered in a new GlobalConfig class to which config files
etc. are applied.

Relevant to https://github.com/NixOS/nix/issues/2009 in that it
removes the need for ad hoc handling of useCaseHack, which was the
underlying cause of that issue.
This commit is contained in:
Eelco Dolstra 2018-03-27 18:41:31 +02:00
parent e606cd412f
commit 737ed88f35
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
15 changed files with 195 additions and 133 deletions

View file

@ -1,16 +1,21 @@
#include "globals.hh"
#include "config.hh"
#include "primops.hh"
using namespace nix;
static BaseSetting<bool> settingSet{false, "setting-set",
struct MySettings : Config
{
Setting<bool> settingSet{this, false, "setting-set",
"Whether the plugin-defined setting was set"};
};
static RegisterSetting rs(&settingSet);
MySettings mySettings;
static GlobalConfig::Register rs(&mySettings);
static void prim_anotherNull (EvalState & state, const Pos & pos, Value ** args, Value & v)
{
if (settingSet)
if (mySettings.settingSet)
mkNull(v);
else
mkBool(v, false);