Merge "Add ApplyConfigOptions
" into main
This commit is contained in:
commit
0582999bd1
2 changed files with 54 additions and 0 deletions
53
src/libutil/apply-config-options.hh
Normal file
53
src/libutil/apply-config-options.hh
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#pragma once
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Options for applying `Config` settings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <types.hh>
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for applying `Config` settings.
|
||||||
|
*/
|
||||||
|
struct ApplyConfigOptions
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The configuration file being loaded.
|
||||||
|
*
|
||||||
|
* If set, relative paths are allowed and interpreted as relative to the
|
||||||
|
* directory of this path.
|
||||||
|
*/
|
||||||
|
std::optional<Path> path = std::nullopt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set, tilde paths (like `~/.config/repl.nix`) are allowed and the
|
||||||
|
* tilde is substituted for this directory.
|
||||||
|
*/
|
||||||
|
std::optional<Path> home = std::nullopt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the configuration being loaded from the `$NIX_CONFIG` environment
|
||||||
|
* variable?
|
||||||
|
*
|
||||||
|
* Used for formatting error messages.
|
||||||
|
*/
|
||||||
|
bool fromEnvVar = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the `relative` path field, with a reasonable default if none is
|
||||||
|
* available.
|
||||||
|
*/
|
||||||
|
std::string relativeDisplay() const {
|
||||||
|
if (path) {
|
||||||
|
return *path;
|
||||||
|
} else if (fromEnvVar) {
|
||||||
|
return "$NIX_CONFIG";
|
||||||
|
} else {
|
||||||
|
return "<unknown>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -46,6 +46,7 @@ libutil_sources = files(
|
||||||
)
|
)
|
||||||
|
|
||||||
libutil_headers = files(
|
libutil_headers = files(
|
||||||
|
'apply-config-options.hh',
|
||||||
'abstract-setting-to-json.hh',
|
'abstract-setting-to-json.hh',
|
||||||
'ansicolor.hh',
|
'ansicolor.hh',
|
||||||
'archive.hh',
|
'archive.hh',
|
||||||
|
|
Loading…
Reference in a new issue