From 93c51acfb5cdc28c4a44cc2ad86359b2b14528f0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 24 Nov 2025 14:04:50 +0100 Subject: [PATCH] Add Setting specialization Like PathSetting, this normalizes the path (without resolving symlinks). --- src/libutil/configuration.cc | 13 +++++++++++++ src/libutil/include/nix/util/config-impl.hh | 1 + src/libutil/include/nix/util/logging.hh | 4 ++-- src/libutil/logging.cc | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libutil/configuration.cc b/src/libutil/configuration.cc index 7a0ed22ea..e520a6e38 100644 --- a/src/libutil/configuration.cc +++ b/src/libutil/configuration.cc @@ -433,6 +433,18 @@ std::string BaseSetting::to_string() const [](const auto & kvpair) { return kvpair.first + "=" + kvpair.second; }); } +template<> +std::filesystem::path BaseSetting::parse(const std::string & str) const +{ + return std::filesystem::path(str).lexically_normal(); +} + +template<> +std::string BaseSetting::to_string() const +{ + return value.string(); +} + template class BaseSetting; template class BaseSetting; template class BaseSetting; @@ -445,6 +457,7 @@ template class BaseSetting; template class BaseSetting; template class BaseSetting; template class BaseSetting>; +template class BaseSetting; static Path parsePath(const AbstractSetting & s, const std::string & str) { diff --git a/src/libutil/include/nix/util/config-impl.hh b/src/libutil/include/nix/util/config-impl.hh index f407bc862..6066765c5 100644 --- a/src/libutil/include/nix/util/config-impl.hh +++ b/src/libutil/include/nix/util/config-impl.hh @@ -134,6 +134,7 @@ DECLARE_CONFIG_SERIALISER(Strings) DECLARE_CONFIG_SERIALISER(StringSet) DECLARE_CONFIG_SERIALISER(StringMap) DECLARE_CONFIG_SERIALISER(std::set) +DECLARE_CONFIG_SERIALISER(std::filesystem::path) template T BaseSetting::parse(const std::string & str) const diff --git a/src/libutil/include/nix/util/logging.hh b/src/libutil/include/nix/util/logging.hh index 500d443e6..ec107304b 100644 --- a/src/libutil/include/nix/util/logging.hh +++ b/src/libutil/include/nix/util/logging.hh @@ -54,9 +54,9 @@ struct LoggerSettings : Config expression evaluation errors. )"}; - Setting jsonLogPath{ + Setting jsonLogPath{ this, - "", + {}, "json-log-path", R"( A file or unix socket to which JSON records of Nix's log output are diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index e2f28f553..48dc9e069 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -370,7 +370,7 @@ void applyJSONLogger() if (!loggerSettings.jsonLogPath.get().empty()) { try { std::vector> 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 (...) {