Skip to content

libutil: return std::filesystem::path from XDG directory helpers#15311

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:convert-end-exes
Feb 21, 2026
Merged

libutil: return std::filesystem::path from XDG directory helpers#15311
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:convert-end-exes

Conversation

@amaanq
Copy link
Member

@amaanq amaanq commented Feb 21, 2026

Motivation

getCacheDir, getConfigDir, getDataDir, getStateDir, and related functions now return std::filesystem::path and use getEnvOs for native OS string handling, letting callsites replace string concatenation with operator/ and drop the ad-hoc namespace nix::fs alias from six CLI files. expandTilde is fixed to strip both ~ and / before joining with operator/ (an absolute right-hand operand silently replaces the left-hand side), and ExecutablePath gains parseAppend for incremental PATH construction.


Add 👍 to pull requests you find important.

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

@github-actions github-actions bot added new-cli Relating to the "nix" command fetching Networking with the outside (non-Nix) world, input locking labels Feb 21, 2026
@amaanq amaanq changed the title beautify rosetta table libutil: return std::filesystem::path from XDG directory helpers Feb 21, 2026
@amaanq amaanq changed the title libutil: return std::filesystem::path from XDG directory helpers libutil: return std::filesystem::path from XDG directory helpers Feb 21, 2026
`getCacheDir`, `getConfigDir`, `getDataDir`, `getStateDir`, and related functions now return `std::filesystem::path` and use `getEnvOs` for native OS string handling, letting callsites replace string concatenation with `operator/` and drop the ad-hoc `namespace nix::fs` alias from six CLI files. `expandTilde` is fixed to strip both `~` and `/` before joining with `operator/` (an absolute right-hand operand silently replaces the left-hand side), and `ExecutablePath` gains `parseAppend` for incremental `PATH` construction.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 21, 2026
Merged via the queue into NixOS:master with commit 42f6e99 Feb 21, 2026
14 checks passed
@Ericson2314 Ericson2314 deleted the convert-end-exes branch February 21, 2026 05:11
return {store.requireStoreObjectAccessor(storePath)};
} else {
return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks();
return SourcePath{makeFSSourceAccessor(path)}.resolveSymlinks();
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 seem right

Copy link
Contributor

Choose a reason for hiding this comment

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

As in, this breaks symlinks that themselves point to an absolute path/escape the root of the accessor

Copy link
Member

Choose a reason for hiding this comment

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

Oh good point, thanks and sorry. We can add a functional test.

Comment on lines +89 to +90
auto suffix = path.size() >= 2 ? std::string(path.substr(2)) : std::string{};
return (getHome() / suffix).string();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this behaves correctly when suffix ends up being an empty string tho.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like, we could end up with an extra trailing slash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking new-cli Relating to the "nix" command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants