Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NIX_STATE_HOME, NIX_DATA_HOME, NIX_CONFIG_HOME and NIX_CACHE_HOME #1

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2a77d37
Add NIX_STATE_HOME, NIX_DATA_HOME, NIX_CONFIG_HOME and NIX_CACHE_HOME
noamraph Aug 4, 2024
df36ff0
install-darwin: fix _nixbld uids for macOS sequoia
abathur Jul 3, 2024
7556742
install-darwin: move nixbld gid to match first UID
abathur Jul 3, 2024
33be935
Merge remote-tracking branch 'upstream/master' into add-nix-state-home
Aug 21, 2024
11cf29b
install-darwin: increment base UID by 1 (#15)
emilazy Aug 26, 2024
9cc550d
Don't refer to public keys as secret keys in error
alyssais Aug 31, 2024
ef1ac0d
Merge pull request #11390 from alyssais/key
edolstra Sep 2, 2024
a33cb8a
Respect max-substitution-jobs again
edolstra Sep 2, 2024
b7acd1c
"unsigned" -> size_t
edolstra Sep 2, 2024
13100ea
Fix link anchor
SuperSandro2000 Sep 2, 2024
4decd6f
add removal of ~root/.cache/nix to uninstall instructions (#11407)
jkerfs Sep 3, 2024
9a9f5ae
Merge pull request #11405 from SuperSandro2000/patch-2
roberth Sep 3, 2024
784a843
Merge pull request #11402 from DeterminateSystems/fix-max-substitutio…
edolstra Sep 3, 2024
02bb633
maintainers/upload-release.pl: Delete temporary directories when we'r…
edolstra Sep 3, 2024
1073a8e
Merge pull request #11410 from DeterminateSystems/upload-release-cleanup
edolstra Sep 3, 2024
46b3188
Move daemon process into sub-cgroup
parkerhoyes Aug 26, 2024
4c88dee
Add tests for daemon with cgroups
parkerhoyes Sep 3, 2024
62a9904
Enable cgroups delegation for systemd
parkerhoyes Sep 3, 2024
9e79061
fixup: use the real bindir for systemd unit's bindir
cole-h Sep 3, 2024
a6e6da3
Merge pull request #10919 from abathur/macos_sequoia_fixes
tomberek Sep 3, 2024
357cec9
Merge pull request #11414 from parkerhoyes/cgroups-delegation
edolstra Sep 4, 2024
46f6505
Pull fut.get() out of the lock
kjeremy Sep 4, 2024
8152c5c
Remote nullptr
kjeremy Sep 4, 2024
0348464
Simplify getRootCgroup()
parkerhoyes Sep 4, 2024
668d63d
Merge pull request #11424 from kjeremy/lix-1462
edolstra Sep 4, 2024
bd6ae2f
Use getCurrentCgroup() in getMaxCPU()
parkerhoyes Sep 4, 2024
ef3d3c5
use existing GID in sequoia migration script
abathur Sep 5, 2024
38d9d53
docs: small fixups on the default expression
fricklerhandwerk Sep 5, 2024
48249e0
docs: reword glossary entry on Nix expression
fricklerhandwerk Sep 5, 2024
17655ec
docs: explain provenance of default `nix-path` values
fricklerhandwerk Sep 5, 2024
5bfe198
Merge pull request #11433 from abathur/fix_sequoia_migration_gid
tomberek Sep 5, 2024
a1cc362
fix broken link (#11435)
fricklerhandwerk Sep 5, 2024
a81083d
Revert "Update src/libutil/url.cc"
Mic92 Sep 5, 2024
5a5a010
Revert "fix: Error on malformed URI query parameter"
Mic92 Sep 5, 2024
92be107
update instructions to build the manual
fricklerhandwerk Sep 6, 2024
bb1af06
Merge pull request #11439 from Mic92/revert-warning
edolstra Sep 6, 2024
644a034
Merge pull request #11440 from fricklerhandwerk/fix-docs-build-instru…
edolstra Sep 6, 2024
f15aef2
Merge pull request #11413 from cole-h/fixup-daemon-service
edolstra Sep 6, 2024
791f943
Merge pull request #11437 from fricklerhandwerk/default-nix-path-docs
roberth Sep 7, 2024
9ae7140
Merge pull request #11436 from fricklerhandwerk/reword-nix-expr-gloss
roberth Sep 7, 2024
9df5236
progress-bar: Only write when truly updated
roberth Aug 27, 2024
047d964
refact: Extract ProgressBar::redraw(newOutput)
roberth Sep 7, 2024
e10ea78
refact: Inline ProgressBar::draw(state, newOutput), inline local output
roberth Sep 7, 2024
c955563
fix: Avoid deadlock in ProgressBar::redraw()
roberth Sep 8, 2024
69e9256
Merge pull request #11432 from fricklerhandwerk/docs-defexpr
roberth Sep 8, 2024
5e337ee
Merge pull request #11412 from parkerhoyes/daemon-cgroup
edolstra Sep 9, 2024
4c7a6ff
Merge pull request #11380 from roberth/eco-friendly-progress-bar
edolstra Sep 9, 2024
b99c6c6
Merge remote-tracking branch 'upstream/master' into add-nix-state-home
Sep 9, 2024
ca258d3
Update env-common.md with the NIX_*_HOME envvars.
Sep 9, 2024
3136979
Update doc/manual/src/command-ref/env-common.md
noamraph Sep 11, 2024
513b5d2
Update doc/manual/src/command-ref/env-common.md
noamraph Sep 11, 2024
8b67e10
Update env-common.md
noamraph Sep 11, 2024
8d136a7
Add changlog entry
Sep 11, 2024
48ac2a2
reword release notes
fricklerhandwerk Sep 11, 2024
850d404
env-common.md: Remove "For example"
Sep 11, 2024
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
Next Next commit
Add NIX_STATE_HOME, NIX_DATA_HOME, NIX_CONFIG_HOME and NIX_CACHE_HOME
  • Loading branch information
noamraph committed Aug 18, 2024
commit 2a77d372b780a7806b5ea266aa3d996f77fc6468
44 changes: 24 additions & 20 deletions scripts/nix-profile.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then

# Set up the per-user profile.

NIX_LINK="$HOME/.nix-profile"
if [ -n "${XDG_STATE_HOME-}" ]; then
NIX_LINK_NEW="$XDG_STATE_HOME/nix/profile"
if [ -n "$NIX_STATE_HOME" ]; then
NIX_LINK="$NIX_STATE_HOME/profile"
else
NIX_LINK_NEW="$HOME/.local/state/nix/profile"
fi
if [ -e "$NIX_LINK_NEW" ]; then
if [ -t 2 ] && [ -e "$NIX_LINK" ]; then
warning="\033[1;35mwarning:\033[0m"
printf "$warning Both %s and legacy %s exist; using the former.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2
if [ "$(realpath "$NIX_LINK")" = "$(realpath "$NIX_LINK_NEW")" ]; then
printf " Since the profiles match, you can safely delete either of them.\n" 1>&2
else
# This should be an exceptionally rare occasion: the only way to get it would be to
# 1. Update to newer Nix;
# 2. Remove .nix-profile;
# 3. Set the $NIX_LINK_NEW to something other than the default user profile;
# 4. Roll back to older Nix.
# If someone did all that, they can probably figure out how to migrate the profile.
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
NIX_LINK="$HOME/.nix-profile"
if [ -n "${XDG_STATE_HOME-}" ]; then
NIX_LINK_NEW="$XDG_STATE_HOME/nix/profile"
else
NIX_LINK_NEW="$HOME/.local/state/nix/profile"
fi
if [ -e "$NIX_LINK_NEW" ]; then
if [ -t 2 ] && [ -e "$NIX_LINK" ]; then
warning="\033[1;35mwarning:\033[0m"
printf "$warning Both %s and legacy %s exist; using the former.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2
if [ "$(realpath "$NIX_LINK")" = "$(realpath "$NIX_LINK_NEW")" ]; then
printf " Since the profiles match, you can safely delete either of them.\n" 1>&2
else
# This should be an exceptionally rare occasion: the only way to get it would be to
# 1. Update to newer Nix;
# 2. Remove .nix-profile;
# 3. Set the $NIX_LINK_NEW to something other than the default user profile;
# 4. Roll back to older Nix.
# If someone did all that, they can probably figure out how to migrate the profile.
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
fi
fi
NIX_LINK="$NIX_LINK_NEW"
fi
NIX_LINK="$NIX_LINK_NEW"
fi

# Set up environment.
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ NixRepl::NixRepl(const LookupPath & lookupPath, nix::ref<Store> store, ref<EvalS
, debugTraceIndex(0)
, getValues(getValues)
, staticEnv(new StaticEnv(nullptr, state->staticBaseEnv.get()))
, interacter(make_unique<ReadlineLikeInteracter>(getDataDir() + "/nix/repl-history"))
, interacter(make_unique<ReadlineLikeInteracter>(getDataDir() + "/repl-history"))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct AttrDb
{
auto state(_state->lock());

Path cacheDir = getCacheDir() + "/nix/eval-cache-v5";
Path cacheDir = getCacheDir() + "/eval-cache-v5";
createDirs(cacheDir);

Path dbPath = cacheDir + "/" + fingerprint.to_string(HashFormat::Base16, false) + ".sqlite";
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const std::string & EvalSettings::getCurrentSystem() const
Path getNixDefExpr()
{
return settings.useXDGBaseDirectories
? getStateDir() + "/nix/defexpr"
? getStateDir() + "/defexpr"
: getHome() + "/.nix-defexpr";
}

Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct CacheImpl : Cache
{
auto state(_state.lock());

auto dbPath = getCacheDir() + "/nix/fetcher-cache-v2.sqlite";
auto dbPath = getCacheDir() + "/fetcher-cache-v2.sqlite";
createDirs(dirOf(dbPath));

state->db = SQLite(dbPath);
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ std::vector<std::tuple<GitRepoImpl::Submodule, Hash>> GitRepoImpl::getSubmodules

ref<GitRepo> getTarballCache()
{
static auto repoDir = std::filesystem::path(getCacheDir()) / "nix" / "tarball-cache";
static auto repoDir = std::filesystem::path(getCacheDir()) / "tarball-cache";

return GitRepo::openRepo(repoDir, true, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool isCacheFileWithinTtl(time_t now, const struct stat & st)
Path getCachePath(std::string_view key, bool shallow)
{
return getCacheDir()
+ "/nix/gitv3/"
+ "/gitv3/"
+ hashString(HashAlgorithm::SHA256, key).to_string(HashFormat::Nix32, false)
+ (shallow ? "-shallow" : "");
}
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ struct MercurialInputScheme : InputScheme
return makeResult(res->value, res->storePath);
}

Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashAlgorithm::SHA256, actualUrl).to_string(HashFormat::Nix32, false));
Path cacheDir = fmt("%s/hg/%s", getCacheDir(), hashString(HashAlgorithm::SHA256, actualUrl).to_string(HashFormat::Nix32, false));

/* If this is a commit hash that we already have, we don't
have to pull again. */
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static std::shared_ptr<Registry> getSystemRegistry(const Settings & settings)

Path getUserRegistryPath()
{
return getConfigDir() + "/nix/registry.json";
return getConfigDir() + "/registry.json";
}

std::shared_ptr<Registry> getUserRegistry(const Settings & settings)
Expand Down Expand Up @@ -159,7 +159,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, re
if (!hasPrefix(path, "/")) {
auto storePath = downloadFile(store, path, "flake-registry.json").storePath;
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json");
store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json");
path = store->toRealPath(storePath);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libflake/flake/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef std::map<std::string, std::map<std::string, bool>> TrustedList;

Path trustedListPath()
{
return getDataDir() + "/nix/trusted-settings.json";
return getDataDir() + "/trusted-settings.json";
}

static TrustedList readTrustedList()
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ std::vector<Path> getUserConfigFiles()
std::vector<Path> files;
auto dirs = getConfigDirs();
for (auto & dir : dirs) {
files.insert(files.end(), dir + "/nix/nix.conf");
files.insert(files.end(), dir + "/nix.conf");
}
return files;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache

Sync<State> _state;

NarInfoDiskCacheImpl(Path dbPath = getCacheDir() + "/nix/binary-cache-v6.sqlite")
NarInfoDiskCacheImpl(Path dbPath = getCacheDir() + "/binary-cache-v6.sqlite")
{
auto state(_state.lock());

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ ref<Store> openStore(StoreReference && storeURI)
/* If /nix doesn't exist, there is no daemon socket, and
we're not root, then automatically set up a chroot
store in ~/.local/share/nix/root. */
auto chrootStore = getDataDir() + "/nix/root";
auto chrootStore = getDataDir() + "/root";
if (!pathExists(chrootStore)) {
try {
createDirs(chrootStore);
Expand Down
57 changes: 48 additions & 9 deletions src/libutil/users.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,81 @@ namespace nix {

Path getCacheDir()
{
auto cacheDir = getEnv("XDG_CACHE_HOME");
return cacheDir ? *cacheDir : getHome() + "/.cache";
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 configDir = getEnv("XDG_CONFIG_HOME");
return configDir ? *configDir : getHome() + "/.config";
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 dataDir = getEnv("XDG_DATA_HOME");
return dataDir ? *dataDir : getHome() + "/.local/share";
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 stateDir = getEnv("XDG_STATE_HOME");
return stateDir ? *stateDir : getHome() + "/.local/state";
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() + "/nix";
Path dir = getStateDir();
createDirs(dir);
return dir;
}
Expand Down
8 changes: 4 additions & 4 deletions src/libutil/users.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Path getHomeOf(uid_t userId);
Path getHome();

/**
* @return $XDG_CACHE_HOME or $HOME/.cache.
* @return $NIX_CACHE_HOME or $XDG_CACHE_HOME/nix or $HOME/.cache/nix.
*/
Path getCacheDir();

/**
* @return $XDG_CONFIG_HOME or $HOME/.config.
* @return $NIX_CONFIG_HOME or $XDG_CONFIG_HOME/nix or $HOME/.config/nix.
*/
Path getConfigDir();

Expand All @@ -39,12 +39,12 @@ Path getConfigDir();
std::vector<Path> getConfigDirs();

/**
* @return $XDG_DATA_HOME or $HOME/.local/share.
* @return $NIX_DATA_HOME or $XDG_DATA_HOME/nix or $HOME/.local/share/nix.
*/
Path getDataDir();

/**
* @return $XDG_STATE_HOME or $HOME/.local/state.
* @return $NIX_STATE_HOME or $XDG_STATE_HOME/nix or $HOME/.local/state/nix.
*/
Path getStateDir();

Expand Down
4 changes: 4 additions & 0 deletions tests/functional/common/vars-and-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ fi # ! isTestOnNixOS

unset NIX_PATH
export HOME=$TEST_HOME
unset NIX_STATE_HOME
unset NIX_DATA_HOME
unset NIX_CONFIG_HOME
unset NIX_CACHE_HOME
unset XDG_STATE_HOME
unset XDG_DATA_HOME
unset XDG_CONFIG_HOME
Expand Down
Loading