diff --git a/src/libexpr/eval-settings.cc b/src/libexpr/eval-settings.cc index 8e8b6bcd9..04c619388 100644 --- a/src/libexpr/eval-settings.cc +++ b/src/libexpr/eval-settings.cc @@ -103,9 +103,9 @@ const std::string & EvalSettings::getCurrentSystem() const return evalSystem != "" ? evalSystem : settings.thisSystem.get(); } -Path getNixDefExpr() +std::filesystem::path getNixDefExpr() { - return settings.useXDGBaseDirectories ? getStateDir() + "/defexpr" : getHome() + "/.nix-defexpr"; + return settings.useXDGBaseDirectories ? getStateDir() / "defexpr" : getHome() / ".nix-defexpr"; } } // namespace nix diff --git a/src/libexpr/include/nix/expr/eval-settings.hh b/src/libexpr/include/nix/expr/eval-settings.hh index 250c2cddf..5dbef9272 100644 --- a/src/libexpr/include/nix/expr/eval-settings.hh +++ b/src/libexpr/include/nix/expr/eval-settings.hh @@ -366,6 +366,6 @@ struct EvalSettings : Config /** * Conventionally part of the default nix path in impure mode. */ -Path getNixDefExpr(); +std::filesystem::path getNixDefExpr(); } // namespace nix diff --git a/src/libutil/include/nix/util/users.hh b/src/libutil/include/nix/util/users.hh index f2c6caecf..7a556fa8b 100644 --- a/src/libutil/include/nix/util/users.hh +++ b/src/libutil/include/nix/util/users.hh @@ -1,6 +1,8 @@ #pragma once ///@file +#include + #include "nix/util/types.hh" #ifndef _WIN32 @@ -15,43 +17,43 @@ std::string getUserName(); /** * @return the given user's home directory from /etc/passwd. */ -Path getHomeOf(uid_t userId); +std::filesystem::path getHomeOf(uid_t userId); #endif /** * @return $HOME or the user's home directory from /etc/passwd. */ -Path getHome(); +std::filesystem::path getHome(); /** * @return $NIX_CACHE_HOME or $XDG_CACHE_HOME/nix or $HOME/.cache/nix. */ -Path getCacheDir(); +std::filesystem::path getCacheDir(); /** * @return $NIX_CONFIG_HOME or $XDG_CONFIG_HOME/nix or $HOME/.config/nix. */ -Path getConfigDir(); +std::filesystem::path getConfigDir(); /** * @return the directories to search for user configuration files */ -std::vector getConfigDirs(); +std::vector getConfigDirs(); /** * @return $NIX_DATA_HOME or $XDG_DATA_HOME/nix or $HOME/.local/share/nix. */ -Path getDataDir(); +std::filesystem::path getDataDir(); /** * @return $NIX_STATE_HOME or $XDG_STATE_HOME/nix or $HOME/.local/state/nix. */ -Path getStateDir(); +std::filesystem::path getStateDir(); /** * Create the Nix state directory and return the path to it. */ -Path createNixStateDir(); +std::filesystem::path createNixStateDir(); /** * Perform tilde expansion on a path, replacing tilde with the user's diff --git a/src/libutil/include/nix/util/util.hh b/src/libutil/include/nix/util/util.hh index 83419c8c9..7556663cd 100644 --- a/src/libutil/include/nix/util/util.hh +++ b/src/libutil/include/nix/util/util.hh @@ -6,6 +6,7 @@ #include "nix/util/logging.hh" #include "nix/util/strings.hh" +#include #include #include #include diff --git a/src/libutil/unix/users.cc b/src/libutil/unix/users.cc index 09b38be5e..870bbe376 100644 --- a/src/libutil/unix/users.cc +++ b/src/libutil/unix/users.cc @@ -18,7 +18,7 @@ std::string getUserName() return name; } -Path getHomeOf(uid_t userId) +std::filesystem::path getHomeOf(uid_t userId) { std::vector buf(16384); struct passwd pwbuf; @@ -28,9 +28,9 @@ Path getHomeOf(uid_t userId) return pw->pw_dir; } -Path getHome() +std::filesystem::path getHome() { - static Path homeDir = []() { + static std::filesystem::path homeDir = []() { std::optional unownedUserHomeDir = {}; auto homeDir = getEnv("HOME"); if (homeDir) { diff --git a/src/libutil/users.cc b/src/libutil/users.cc index f19a5d39c..e07b5535e 100644 --- a/src/libutil/users.cc +++ b/src/libutil/users.cc @@ -5,7 +5,7 @@ namespace nix { -Path getCacheDir() +std::filesystem::path getCacheDir() { auto dir = getEnv("NIX_CACHE_HOME"); if (dir) { @@ -13,14 +13,14 @@ Path getCacheDir() } else { auto xdgDir = getEnv("XDG_CACHE_HOME"); if (xdgDir) { - return *xdgDir + "/nix"; + return std::filesystem::path{*xdgDir} / "nix"; } else { - return getHome() + "/.cache/nix"; + return getHome() / ".cache" / "nix"; } } } -Path getConfigDir() +std::filesystem::path getConfigDir() { auto dir = getEnv("NIX_CONFIG_HOME"); if (dir) { @@ -28,26 +28,27 @@ Path getConfigDir() } else { auto xdgDir = getEnv("XDG_CONFIG_HOME"); if (xdgDir) { - return *xdgDir + "/nix"; + return std::filesystem::path{*xdgDir} / "nix"; } else { - return getHome() + "/.config/nix"; + return getHome() / ".config" / "nix"; } } } -std::vector getConfigDirs() +std::vector getConfigDirs() { - Path configHome = getConfigDir(); + std::filesystem::path configHome = getConfigDir(); auto configDirs = getEnv("XDG_CONFIG_DIRS").value_or("/etc/xdg"); - std::vector result = tokenizeString>(configDirs, ":"); - for (auto & p : result) { - p += "/nix"; + auto tokens = tokenizeString>(configDirs, ":"); + std::vector result; + result.push_back(configHome); + for (auto & token : tokens) { + result.push_back(std::filesystem::path{token} / "nix"); } - result.insert(result.begin(), configHome); return result; } -Path getDataDir() +std::filesystem::path getDataDir() { auto dir = getEnv("NIX_DATA_HOME"); if (dir) { @@ -55,14 +56,14 @@ Path getDataDir() } else { auto xdgDir = getEnv("XDG_DATA_HOME"); if (xdgDir) { - return *xdgDir + "/nix"; + return std::filesystem::path{*xdgDir} / "nix"; } else { - return getHome() + "/.local/share/nix"; + return getHome() / ".local" / "share" / "nix"; } } } -Path getStateDir() +std::filesystem::path getStateDir() { auto dir = getEnv("NIX_STATE_HOME"); if (dir) { @@ -70,16 +71,16 @@ Path getStateDir() } else { auto xdgDir = getEnv("XDG_STATE_HOME"); if (xdgDir) { - return *xdgDir + "/nix"; + return std::filesystem::path{*xdgDir} / "nix"; } else { - return getHome() + "/.local/state/nix"; + return getHome() / ".local" / "state" / "nix"; } } } -Path createNixStateDir() +std::filesystem::path createNixStateDir() { - Path dir = getStateDir(); + std::filesystem::path dir = getStateDir(); createDirs(dir); return dir; } diff --git a/src/libutil/windows/users.cc b/src/libutil/windows/users.cc index 6cc753cec..cbeadcb81 100644 --- a/src/libutil/windows/users.cc +++ b/src/libutil/windows/users.cc @@ -35,10 +35,10 @@ std::string getUserName() return name; } -Path getHome() +std::filesystem::path getHome() { - static Path homeDir = []() { - Path homeDir = getEnv("USERPROFILE").value_or("C:\\Users\\Default"); + static std::filesystem::path homeDir = []() { + std::filesystem::path homeDir = getEnv("USERPROFILE").value_or("C:\\Users\\Default"); assert(!homeDir.empty()); return canonPath(homeDir); }();