mirror of
https://github.com/NixOS/nix.git
synced 2025-12-07 17:41:00 +01:00
Move /src to /subprojects
This will facilitate breaking up Nix into multiple packages for each component with Meson.
This commit is contained in:
parent
4db9487823
commit
84e2963f8e
737 changed files with 504 additions and 505 deletions
100
subprojects/libutil/users.cc
Normal file
100
subprojects/libutil/users.cc
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#include "util.hh"
|
||||
#include "users.hh"
|
||||
#include "environment-variables.hh"
|
||||
#include "file-system.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
Path getCacheDir()
|
||||
{
|
||||
auto dir = getEnv("NIX_CACHE_HOME");
|
||||
if (dir) {
|
||||
return *dir;
|
||||
} else {
|
||||
auto xdgDir = getEnv("XDG_CACHE_HOME");
|
||||
if (xdgDir) {
|
||||
return *xdgDir + "/nix";
|
||||
} else {
|
||||
return getHome() + "/.cache/nix";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Path getConfigDir()
|
||||
{
|
||||
auto dir = getEnv("NIX_CONFIG_HOME");
|
||||
if (dir) {
|
||||
return *dir;
|
||||
} else {
|
||||
auto xdgDir = getEnv("XDG_CONFIG_HOME");
|
||||
if (xdgDir) {
|
||||
return *xdgDir + "/nix";
|
||||
} else {
|
||||
return getHome() + "/.config/nix";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Path> getConfigDirs()
|
||||
{
|
||||
Path configHome = getConfigDir();
|
||||
auto configDirs = getEnv("XDG_CONFIG_DIRS").value_or("/etc/xdg");
|
||||
std::vector<Path> result = tokenizeString<std::vector<std::string>>(configDirs, ":");
|
||||
for (auto& p : result) {
|
||||
p += "/nix";
|
||||
}
|
||||
result.insert(result.begin(), configHome);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Path getDataDir()
|
||||
{
|
||||
auto dir = getEnv("NIX_DATA_HOME");
|
||||
if (dir) {
|
||||
return *dir;
|
||||
} else {
|
||||
auto xdgDir = getEnv("XDG_DATA_HOME");
|
||||
if (xdgDir) {
|
||||
return *xdgDir + "/nix";
|
||||
} else {
|
||||
return getHome() + "/.local/share/nix";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Path getStateDir()
|
||||
{
|
||||
auto dir = getEnv("NIX_STATE_HOME");
|
||||
if (dir) {
|
||||
return *dir;
|
||||
} else {
|
||||
auto xdgDir = getEnv("XDG_STATE_HOME");
|
||||
if (xdgDir) {
|
||||
return *xdgDir + "/nix";
|
||||
} else {
|
||||
return getHome() + "/.local/state/nix";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Path createNixStateDir()
|
||||
{
|
||||
Path dir = getStateDir();
|
||||
createDirs(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
std::string expandTilde(std::string_view path)
|
||||
{
|
||||
// TODO: expand ~user ?
|
||||
auto tilde = path.substr(0, 2);
|
||||
if (tilde == "~/" || tilde == "~")
|
||||
return getHome() + std::string(path.substr(1));
|
||||
else
|
||||
return std::string(path);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue