Skip to content

Conversation

@edolstra
Copy link
Member

@edolstra edolstra commented Nov 24, 2025

Motivation

Like PathSetting, this normalizes the path (without resolving symlinks).

Eventually, we should replace PathSetting by Setting<std::filesystem::path>, and OptionalPathSetting by Setting<std::optional<std::filesystem::path>>.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Like PathSetting, this normalizes the path (without resolving
symlinks).
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change!

@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 24, 2025
@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 24, 2025
template<>
std::filesystem::path BaseSetting<std::filesystem::path>::parse(const std::string & str) const
{
return std::filesystem::path(str).lexically_normal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also ensure that the path is absolute? That's what PathSetting requires currently

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes good point.

Copy link
Contributor

@xokdvium xokdvium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably ensure that the path is not absolute, as PathSetting already does.

@Ericson2314
Copy link
Member

Fixed, we can just use canonPath like before. We'll rework canonPath some other time.

@Ericson2314 Ericson2314 changed the title Add Setting<std::filesystem::path> specialization Add Setting<std::filesystem::path> specialization Nov 26, 2025
Setting<std::filesystem::path> jsonLogPath{
this,
"",
{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right tho? What's a default constructed path? Shouldn't this be an optional?

Copy link
Contributor

@xokdvium xokdvium Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below the json logger is only created when the path is not empty. Shouldn't this get the same treatment as OptionalPath when an empty string signifies std::nullopt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right Setting<Path> is just Setting<std::string>, the thing was totally busted before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of this PR is that the path can be empty. E.g. json-log-path can be unset.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the semantics of an empty path is that of a std::nullopt. Empty path doesn't make much sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the settings perspective it's the same, but my slight quip is that it would be more legible in the code if std::filesystem::path specified in the settings would have the invariant of being absolute and non-empty. Not really a blocker since it's already this way, but I think it'd be nice if we are moving to std::filesystem for this stuff.

Not exactly sure what would happen if someone accidentally tried doing any I/O with an empty path with std::filesystem and it seems nice to avoid that altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should use std::optional and work just like OptionalPathSetting. (It could just replace OptionalPathSetting.) It should use parsePath so please put that back.

@Ericson2314 Ericson2314 changed the title Add Setting<std::filesystem::path> specialization Add Setting<std::filesystem::path> and Setting<std::optional<std::filesystem::path>> specializations Nov 26, 2025
@xokdvium
Copy link
Contributor

xokdvium commented Nov 26, 2025

Modulo the CI fixes sounds good

@Ericson2314
Copy link
Member

Ah, precompiled headers strike again

@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 27, 2025
Merged via the queue into master with commit 35492fe Nov 27, 2025
20 checks passed
@Ericson2314 Ericson2314 deleted the path-setting branch November 27, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants