1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-28 21:21:00 +01:00

Add Setting<std::filesystem::path> specialization

Like PathSetting, this normalizes the path (without resolving
symlinks).
This commit is contained in:
Eelco Dolstra 2025-11-24 14:04:50 +01:00
parent 487c6b6c46
commit 93c51acfb5
4 changed files with 17 additions and 3 deletions

View file

@ -433,6 +433,18 @@ std::string BaseSetting<StringMap>::to_string() const
[](const auto & kvpair) { return kvpair.first + "=" + kvpair.second; });
}
template<>
std::filesystem::path BaseSetting<std::filesystem::path>::parse(const std::string & str) const
{
return std::filesystem::path(str).lexically_normal();
}
template<>
std::string BaseSetting<std::filesystem::path>::to_string() const
{
return value.string();
}
template class BaseSetting<int>;
template class BaseSetting<unsigned int>;
template class BaseSetting<long>;
@ -445,6 +457,7 @@ template class BaseSetting<Strings>;
template class BaseSetting<StringSet>;
template class BaseSetting<StringMap>;
template class BaseSetting<std::set<ExperimentalFeature>>;
template class BaseSetting<std::filesystem::path>;
static Path parsePath(const AbstractSetting & s, const std::string & str)
{

View file

@ -134,6 +134,7 @@ DECLARE_CONFIG_SERIALISER(Strings)
DECLARE_CONFIG_SERIALISER(StringSet)
DECLARE_CONFIG_SERIALISER(StringMap)
DECLARE_CONFIG_SERIALISER(std::set<ExperimentalFeature>)
DECLARE_CONFIG_SERIALISER(std::filesystem::path)
template<typename T>
T BaseSetting<T>::parse(const std::string & str) const

View file

@ -54,9 +54,9 @@ struct LoggerSettings : Config
expression evaluation errors.
)"};
Setting<Path> jsonLogPath{
Setting<std::filesystem::path> jsonLogPath{
this,
"",
{},
"json-log-path",
R"(
A file or unix socket to which JSON records of Nix's log output are

View file

@ -370,7 +370,7 @@ void applyJSONLogger()
if (!loggerSettings.jsonLogPath.get().empty()) {
try {
std::vector<std::unique_ptr<Logger>> loggers;
loggers.push_back(makeJSONLogger(std::filesystem::path(loggerSettings.jsonLogPath.get()), false));
loggers.push_back(makeJSONLogger(loggerSettings.jsonLogPath.get(), false));
try {
logger = makeTeeLogger(std::move(logger), std::move(loggers));
} catch (...) {