8#include <nlohmann/json_fwd.hpp>
53 StringMap unknownSettings;
55 AbstractConfig(StringMap initials = {});
63 virtual bool set(
const std::string &
name,
const std::string &
value) = 0;
68 std::string description;
76 virtual void getSettings(std::map<std::string, SettingInfo> &
res,
bool overriddenOnly =
false) = 0;
83 void applyConfig(
const std::string & contents,
const std::string & path =
"<unknown>");
119 virtual ~AbstractConfig() =
default;
137class Config :
public AbstractConfig
149 using Settings = std::map<std::string, SettingData>;
157 Config(StringMap initials = {});
159 bool set(
const std::string &
name,
const std::string &
value)
override;
163 void getSettings(std::map<std::string, SettingInfo> &
res,
bool overriddenOnly =
false)
override;
167 nlohmann::json
toJSON()
override;
180 const std::string name;
181 const std::string description;
182 const std::set<std::string> aliases;
186 bool overridden =
false;
188 std::optional<ExperimentalFeature> experimentalFeature;
193 const std::string & name,
194 const std::string & description,
195 const std::set<std::string> & aliases,
196 std::optional<ExperimentalFeature> experimentalFeature = std::nullopt);
198 virtual ~AbstractSetting();
200 virtual void set(
const std::string &
value,
bool append =
false) = 0;
208 virtual std::string to_string()
const = 0;
212 virtual std::map<std::string, nlohmann::json> toJSONObject()
const;
214 virtual void convertToArg(
Args &
args,
const std::string & category);
216 bool isOverridden()
const;
223class BaseSetting :
public AbstractSetting
228 const T defaultValue;
229 const bool documentDefault;
236 virtual T
parse(
const std::string &
str)
const;
250 BaseSetting(
const T & def,
251 const bool documentDefault,
252 const std::string & name,
253 const std::string & description,
254 const std::set<std::string> & aliases = {},
255 std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
259 , documentDefault(documentDefault)
262 operator const T &()
const {
return value; }
263 operator T &() {
return value; }
264 const T & get()
const {
return value; }
265 T & get() {
return value; }
267 bool operator ==(
const U & v2)
const {
return value == v2; }
269 bool operator !=(
const U & v2)
const {
return value != v2; }
271 void operator =(
const U & v) { assign(v); }
272 virtual void assign(
const T & v) { value = v; }
274 void setDefault(
const U & v) {
if (!overridden) value = v; }
282 void set(
const std::string &
str,
bool append =
false)
override final;
296 virtual void override(
const T & v)
302 std::string to_string()
const override;
304 void convertToArg(
Args &
args,
const std::string & category)
override;
306 std::map<std::string, nlohmann::json> toJSONObject()
const override;
312 return str << static_cast<const T &>(opt);
316bool operator ==(
const T & v1,
const BaseSetting<T> & v2) {
return v1 ==
static_cast<const T &
>(v2); }
319class Setting :
public BaseSetting<T>
324 const std::string & name,
325 const std::string & description,
326 const std::set<std::string> & aliases = {},
327 const bool documentDefault =
true,
328 std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
329 : BaseSetting<T>(def, documentDefault, name, description, aliases, std::move(experimentalFeature))
331 options->addSetting(
this);
334 void operator =(
const T & v) { this->assign(v); }
344class PathSetting :
public BaseSetting<Path>
348 PathSetting(
Config * options,
350 const std::string & name,
351 const std::string & description,
352 const std::set<std::string> & aliases = {});
356 Path operator +(
const char *
p)
const {
return value +
p; }
358 void operator =(
const Path & v) { this->assign(v); }
366class OptionalPathSetting :
public BaseSetting<std::optional<Path>>
370 OptionalPathSetting(
Config * options,
371 const std::optional<Path> & def,
372 const std::string & name,
373 const std::string & description,
374 const std::set<std::string> & aliases = {});
376 std::optional<Path>
parse(
const std::string &
str)
const override;
378 void operator =(
const std::optional<Path> & v);
385 this, {},
"experimental-features",
387 Experimental features that are enabled.
392 experimental-features = nix-command flakes
395 The following experimental features are available:
397 {{#include experimental-features-shortlist.md}}
399 Experimental features are [further documented in the manual](@docroot@/development/experimental-features.md).
417 bool isEnabled(
const std::optional<ExperimentalFeature> &)
const;
423 void require(
const std::optional<ExperimentalFeature> &)
const;
virtual std::string toKeyValue()=0
void warnUnknownSettings()
Definition config.cc:73
void reapplyUnknownSettings()
Definition config.cc:79
virtual bool set(const std::string &name, const std::string &value)=0
virtual void getSettings(std::map< std::string, SettingInfo > &res, bool overriddenOnly=false)=0
virtual nlohmann::json toJSON()=0
void applyConfig(const std::string &contents, const std::string &path="<unknown>")
Definition config.cc:163
virtual void resetOverridden()=0
virtual void convertToArgs(Args &args, const std::string &category)=0
virtual bool isAppendable()=0
bool isAppendable() override final
Definition config-impl.hh:44
virtual T parse(const std::string &str) const
Definition config-impl.hh:118
void set(const std::string &str, bool append=false) override final
Definition config-impl.hh:66
virtual void appendOrSet(T newValue, bool append)
Definition config-impl.hh:55
void resetOverridden() override
Definition config.cc:188
void getSettings(std::map< std::string, SettingInfo > &res, bool overriddenOnly=false) override
Definition config.cc:87
friend class AbstractSetting
Definition config.hh:139
std::string toKeyValue() override
Definition config.cc:203
nlohmann::json toJSON() override
Definition config.cc:194
bool set(const std::string &name, const std::string &value) override
Definition config.cc:21
void convertToArgs(Args &args, const std::string &category) override
Definition config.cc:212
std::optional< Path > parse(const std::string &str) const override
Definition config.cc:454
Path parse(const std::string &str) const override
Definition config.cc:437
ExperimentalFeature
Definition experimental-features.hh:19
friend class AbstractSetting
Definition lexer.l:1888
std::ostream & str
Definition lexer.l:1728
Strings res
Definition lexer.l:2566
std::shared_ptr< T > p
Definition lexer.l:1269
virtual nlohmann::json toJSON()=0
const std::string_view & name
Definition lexer.l:1709
virtual bool set(const std::string &name, const std::string &value)=0
const T & value
Definition lexer.l:492
std::vector< Expr * > args
Definition lexer.l:6126
Definition globals.cc:262
void require(const ExperimentalFeature &) const
Definition config.cc:473
bool isEnabled(const ExperimentalFeature &) const
Definition config.cc:467
std::string Path
Definition types.hh:22