Skip to content

Commit

Permalink
Try to make Config a bit easier to use
Browse files Browse the repository at this point in the history
- Use references, not pointers, to indicate Config must be initializd.

- Wrap cast to avoid the GCC bug in a helper function, so if we need to
  move it, it's not so bad.
  • Loading branch information
Ericson2314 committed Jan 6, 2023
1 parent 3172c51 commit 8cf1148
Show file tree
Hide file tree
Showing 24 changed files with 183 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ std::string EvalSettings::resolvePseudoUrl(std::string_view url)

EvalSettings evalSettings;

static GlobalConfig::Register rEvalSettings(&evalSettings);
static GlobalConfig::Register rEvalSettings { evalSettings };


}
20 changes: 10 additions & 10 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -577,27 +577,27 @@ struct EvalSettings : Config

static std::string resolvePseudoUrl(std::string_view url);

Setting<bool> enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation",
Setting<bool> enableNativeCode{*this, false, "allow-unsafe-native-code-during-evaluation",
"Whether builtin functions that allow executing native code should be enabled."};

Setting<Strings> nixPath{
this, getDefaultNixPath(), "nix-path",
*this, getDefaultNixPath(), "nix-path",
"List of directories to be searched for `<...>` file references."};

Setting<bool> restrictEval{
this, false, "restrict-eval",
*this, false, "restrict-eval",
R"(
If set to `true`, the Nix evaluator will not allow access to any
files outside of the Nix search path (as set via the `NIX_PATH`
environment variable or the `-I` option), or to URIs outside of
`allowed-uri`. The default is `false`.
)"};

Setting<bool> pureEval{this, false, "pure-eval",
Setting<bool> pureEval{*this, false, "pure-eval",
"Whether to restrict file system and network access to files specified by cryptographic hash."};

Setting<bool> enableImportFromDerivation{
this, true, "allow-import-from-derivation",
*this, true, "allow-import-from-derivation",
R"(
By default, Nix allows you to `import` from a derivation, allowing
building at evaluation time. With this option set to false, Nix will
Expand All @@ -606,15 +606,15 @@ struct EvalSettings : Config
builds to take place.
)"};

Setting<Strings> allowedUris{this, {}, "allowed-uris",
Setting<Strings> allowedUris{*this, {}, "allowed-uris",
R"(
A list of URI prefixes to which access is allowed in restricted
evaluation mode. For example, when set to
`https://github.com/NixOS`, builtin functions such as `fetchGit` are
allowed to access `https://github.com/NixOS/patchelf.git`.
)"};

Setting<bool> traceFunctionCalls{this, false, "trace-function-calls",
Setting<bool> traceFunctionCalls{*this, false, "trace-function-calls",
R"(
If set to `true`, the Nix evaluator will trace every function call.
Nix will print a log message at the "vomit" level for every function
Expand All @@ -632,16 +632,16 @@ struct EvalSettings : Config
`flamegraph.pl`.
)"};

Setting<bool> useEvalCache{this, true, "eval-cache",
Setting<bool> useEvalCache{*this, true, "eval-cache",
"Whether to use the flake evaluation cache."};

Setting<bool> ignoreExceptionsDuringTry{this, false, "ignore-try",
Setting<bool> ignoreExceptionsDuringTry{*this, false, "ignore-try",
R"(
If set to true, ignore exceptions inside 'tryEval' calls when evaluating nix expressions in
debug mode (using the --debugger flag). By default the debugger will pause on all exceptions.
)"};

Setting<bool> traceVerbose{this, false, "trace-verbose",
Setting<bool> traceVerbose{*this, false, "trace-verbose",
"Whether `builtins.traceVerbose` should trace its first argument when evaluated."};
};

Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/fetch-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ FetchSettings::FetchSettings()

FetchSettings fetchSettings;

static GlobalConfig::Register rFetchSettings(&fetchSettings);
static GlobalConfig::Register rFetchSettings { fetchSettings };

}
14 changes: 7 additions & 7 deletions src/libfetchers/fetch-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct FetchSettings : public Config
{
FetchSettings();

Setting<StringMap> accessTokens{this, {}, "access-tokens",
Setting<StringMap> accessTokens{*this, {}, "access-tokens",
R"(
Access tokens used to access protected GitHub, GitLab, or
other locations requiring token-based authentication.
Expand Down Expand Up @@ -64,28 +64,28 @@ struct FetchSettings : public Config
value.
)"};

Setting<bool> allowDirty{this, true, "allow-dirty",
Setting<bool> allowDirty{*this, true, "allow-dirty",
"Whether to allow dirty Git/Mercurial trees."};

Setting<bool> warnDirty{this, true, "warn-dirty",
Setting<bool> warnDirty{*this, true, "warn-dirty",
"Whether to warn about dirty Git/Mercurial trees."};

Setting<std::string> flakeRegistry{this, "https://channels.nixos.org/flake-registry.json", "flake-registry",
Setting<std::string> flakeRegistry{*this, "https://channels.nixos.org/flake-registry.json", "flake-registry",
R"(
Path or URI of the global flake registry.
When empty, disables the global flake registry.
)"};


Setting<bool> useRegistries{this, true, "use-registries",
Setting<bool> useRegistries{*this, true, "use-registries",
"Whether to use flake registries to resolve flake references."};

Setting<bool> acceptFlakeConfig{this, false, "accept-flake-config",
Setting<bool> acceptFlakeConfig{*this, false, "accept-flake-config",
"Whether to accept nix configuration from a flake without prompting."};

Setting<std::string> commitLockFileSummary{
this, "", "commit-lockfile-summary",
*this, "", "commit-lockfile-summary",
R"(
The commit summary to use when committing changed flake lock files. If
empty, the summary is generated based on the action performed.
Expand Down
14 changes: 7 additions & 7 deletions src/libstore/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ struct BinaryCacheStoreConfig : virtual StoreConfig
{
using StoreConfig::StoreConfig;

const Setting<std::string> compression{(StoreConfig*) this, "xz", "compression", "NAR compression method ('xz', 'bzip2', 'gzip', 'zstd', or 'none')"};
const Setting<bool> writeNARListing{(StoreConfig*) this, false, "write-nar-listing", "whether to write a JSON file listing the files in each NAR"};
const Setting<bool> writeDebugInfo{(StoreConfig*) this, false, "index-debug-info", "whether to index DWARF debug info files by build ID"};
const Setting<Path> secretKeyFile{(StoreConfig*) this, "", "secret-key", "path to secret key used to sign the binary cache"};
const Setting<Path> localNarCache{(StoreConfig*) this, "", "local-nar-cache", "path to a local cache of NARs"};
const Setting<bool> parallelCompression{(StoreConfig*) this, false, "parallel-compression",
const Setting<std::string> compression{this->dodgeGcc80431(), "xz", "compression", "NAR compression method ('xz', 'bzip2', 'gzip', 'zstd', or 'none')"};
const Setting<bool> writeNARListing{this->dodgeGcc80431(), false, "write-nar-listing", "whether to write a JSON file listing the files in each NAR"};
const Setting<bool> writeDebugInfo{this->dodgeGcc80431(), false, "index-debug-info", "whether to index DWARF debug info files by build ID"};
const Setting<Path> secretKeyFile{this->dodgeGcc80431(), "", "secret-key", "path to secret key used to sign the binary cache"};
const Setting<Path> localNarCache{this->dodgeGcc80431(), "", "local-nar-cache", "path to a local cache of NARs"};
const Setting<bool> parallelCompression{this->dodgeGcc80431(), false, "parallel-compression",
"enable multi-threading compression for NARs, available for xz and zstd only currently"};
const Setting<int> compressionLevel{(StoreConfig*) this, -1, "compression-level",
const Setting<int> compressionLevel{this->dodgeGcc80431(), -1, "compression-level",
"specify 'preset level' of compression to be used with NARs: "
"meaning and accepted range of values depends on compression method selected, "
"other than -1 which we reserve to indicate Nix defaults should be used"};
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace nix {

FileTransferSettings fileTransferSettings;

static GlobalConfig::Register rFileTransferSettings(&fileTransferSettings);
static GlobalConfig::Register rFileTransferSettings {fileTransferSettings };

struct curlFileTransfer : public FileTransfer
{
Expand Down
12 changes: 6 additions & 6 deletions src/libstore/filetransfer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace nix {

struct FileTransferSettings : Config
{
Setting<bool> enableHttp2{this, true, "http2",
Setting<bool> enableHttp2{*this, true, "http2",
"Whether to enable HTTP/2 support."};

Setting<std::string> userAgentSuffix{this, "", "user-agent-suffix",
Setting<std::string> userAgentSuffix{*this, "", "user-agent-suffix",
"String appended to the user agent in HTTP requests."};

Setting<size_t> httpConnections{
this, 25, "http-connections",
*this, 25, "http-connections",
R"(
The maximum number of parallel TCP connections used to fetch
files from binary caches and by other downloads. It defaults
Expand All @@ -27,22 +27,22 @@ struct FileTransferSettings : Config
{"binary-caches-parallel-connections"}};

Setting<unsigned long> connectTimeout{
this, 0, "connect-timeout",
*this, 0, "connect-timeout",
R"(
The timeout (in seconds) for establishing connections in the
binary cache substituter. It corresponds to `curl`’s
`--connect-timeout` option. A value of 0 means no limit.
)"};

Setting<unsigned long> stalledDownloadTimeout{
this, 300, "stalled-download-timeout",
*this, 300, "stalled-download-timeout",
R"(
The timeout (in seconds) for receiving data from servers
during download. Nix cancels idle downloads after this
timeout's duration.
)"};

Setting<unsigned int> tries{this, 5, "download-attempts",
Setting<unsigned int> tries{*this, 5, "download-attempts",
"How often Nix will attempt to download a file before giving up."};
};

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace nix {

Settings settings;

static GlobalConfig::Register rSettings(&settings);
static GlobalConfig::Register rSettings { settings };

Settings::Settings()
: nixPrefix(NIX_PREFIX)
Expand Down
Loading

0 comments on commit 8cf1148

Please sign in to comment.