Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libstore-tests/local-overlay-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ TEST(LocalOverlayStore, constructConfig_rootQueryParam)
},
};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir.get(), std::optional<AbsolutePath>{"/foo/bar"});
}

TEST(LocalOverlayStore, constructConfig_rootPath)
{
LocalOverlayStoreConfig config{"/foo/bar", {}};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir.get(), std::optional<AbsolutePath>{"/foo/bar"});
}

} // namespace nix
4 changes: 2 additions & 2 deletions src/libstore-tests/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ TEST(LocalStore, constructConfig_rootQueryParam)
},
};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir.get(), std::optional<AbsolutePath>{"/foo/bar"});
}

TEST(LocalStore, constructConfig_rootPath)
{
LocalStoreConfig config{"/foo/bar", {}};

EXPECT_EQ(config.rootDir.get(), std::optional{"/foo/bar"});
EXPECT_EQ(config.rootDir.get(), std::optional<AbsolutePath>{"/foo/bar"});
}

TEST(LocalStore, constructConfig_to_string)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ FileTransferSettings::FileTransferSettings()
{
auto sslOverride = getEnv("NIX_SSL_CERT_FILE").value_or(getEnv("SSL_CERT_FILE").value_or(""));
if (sslOverride != "")
caFile = sslOverride;
caFile = std::optional<AbsolutePath>{sslOverride};
}

FileTransferSettings fileTransferSettings;
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/include/nix/store/local-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public:
* Get the diff hook path if run-diff-hook is enabled.
* @return Pointer to path if enabled, nullptr otherwise.
*/
const std::filesystem::path * getDiffHook() const
const AbsolutePath * getDiffHook() const
{
if (!runDiffHook.get()) {
return nullptr;
Expand Down
99 changes: 92 additions & 7 deletions src/libutil/include/nix/util/configuration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,73 @@ protected:
* For `Setting<AbsolutePath>`. `parse()` calls `canonPath`,
* rejecting empty and relative paths.
*/
struct AbsolutePath : std::filesystem::path
struct AbsolutePath
Copy link
Contributor

@xokdvium xokdvium Feb 27, 2026

Choose a reason for hiding this comment

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

Can be done using private inheritance, no? Less churny code to write, just using path::operator== and stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm I tried this, and it looks like we'd still have churn because we can't just do using path::operator== and friends because they are defined as non-member friend functions

{
using path::path;
using path::operator=;
std::filesystem::path path;

AbsolutePath(const std::filesystem::path & p)
: path(p)
AbsolutePath(std::filesystem::path p)
: path(std::move(p))
{
}

AbsolutePath(std::filesystem::path && p)
: path(std::move(p))
AbsolutePath(const char * s)
: path(s)
{
}

operator const std::filesystem::path &() const
{
return path;
}

std::string string() const
{
return path.string();
}

const auto & native() const
{
return path.native();
}

const char * c_str() const
{
return path.c_str();
}

bool empty() const
{
return path.empty();
}

std::filesystem::path operator/(const std::filesystem::path & rhs) const
{
return path / rhs;
}

bool operator==(const AbsolutePath & rhs) const
{
return path == rhs.path;
}

bool operator==(const std::filesystem::path & rhs) const
{
return path == rhs;
}

bool operator==(const std::string & rhs) const
{
return path == rhs;
}

auto operator<=>(const AbsolutePath & rhs) const
{
return path <=> rhs.path;
}

friend std::ostream & operator<<(std::ostream & os, const AbsolutePath & p)
{
return os << p.path.string();
}
};

Expand Down Expand Up @@ -405,6 +459,37 @@ public:
}
};

template<>
class Setting<AbsolutePath> : public BaseSetting<AbsolutePath>
{
public:
using BaseSetting<AbsolutePath>::BaseSetting;
using BaseSetting<AbsolutePath>::operator=;

Setting(
Config * options,
const AbsolutePath & def,
const std::string & name,
const std::string & description,
const StringSet & aliases = {},
const bool documentDefault = true,
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
: BaseSetting<AbsolutePath>(def, documentDefault, name, description, aliases, std::move(experimentalFeature))
{
options->addSetting(this);
}

void operator=(const AbsolutePath & v)
{
this->assign(v);
}

operator const std::filesystem::path &() const
{
return this->value.path;
}
};

template<>
void BaseSetting<std::set<std::filesystem::path>>::appendOrSet(std::set<std::filesystem::path> newValue, bool append);

Expand Down
Loading