tests/f2: don't set NIX_STORE_DIR unconditionally

this is only needed on macos, and only for tests that build anything. on
linux it can actually *break* stuff due to unfortunate interactions with
store url parsing, which is required to work for any remote build tests.

Change-Id: Ic6f7e090f15e129fc365d7edc56cdbc1a5686047
This commit is contained in:
eldritch horrors
2025-12-26 20:14:39 +00:00
parent 4d67200b80
commit 9ebe5acf39
3 changed files with 24 additions and 12 deletions
+9 -2
View File
@@ -136,11 +136,18 @@ class _Dirs:
nix_state_dir: Path | None
nix_conf_dir: Path | None
nix_bin_dir: Path | None
nix_store_dir: Path | None
# this one *must not* be NIX_STORE_DIR, otherwise lix will pick it up
# and misconfigure itself. the config system is unbelievable bullshit
real_store_dir: Path | None
cache_dir: Path | None
xdg_cache_home: Path | None
tmpdir: Path | None
"""used for nar caching"""
nix_store_dir: Path | None = None
"""
store dir override for building on macos *specifically*. do not
use or set this for any other purpose or many tests will break.
"""
def get_env_keys(self) -> set[str]:
return {f.name.upper() for f in dataclasses.fields(self)}
@@ -174,7 +181,7 @@ class ManagedEnv:
nix_state_dir=self._get_dir("var/nix"),
nix_conf_dir=self._get_dir("etc/nix"),
nix_bin_dir=lix_bin,
nix_store_dir=self._get_dir("nix/store"),
real_store_dir=self._get_dir("nix/store"),
cache_dir=self._get_dir("binary-cache"),
xdg_cache_home=self._get_dir("test-home/.cache"),
tmpdir=self._get_dir("tmp"),
+4 -4
View File
@@ -109,7 +109,7 @@ class Nix:
"""
if self._settings is None:
self._settings = NixSettings()
self._settings.store = f"local?root={self.env.dirs.test_root}&store=/nix/store"
self._settings.store = f"local?root={self.env.dirs.test_root}"
return self._settings
@@ -134,7 +134,7 @@ class Nix:
build == "auto" and (argv[0] == "nix-build" or argv[1:2] == ["build"])
):
settings.store = None
settings.nix_store_dir = self.env.dirs.nix_store_dir
settings.nix_store_dir = self.env.dirs.real_store_dir
settings.to_env_overlay(self.env)
return Command(argv=argv, exe=self._nix_executable, _env=self.env)
@@ -178,8 +178,8 @@ class Nix:
"""
The actual NIX_STORE_DIR this Nix command uses.
"""
assert self.env.dirs.nix_store_dir is not None, "bug in ManagedEnv"
return self.env.dirs.nix_store_dir
assert self.env.dirs.real_store_dir is not None, "bug in ManagedEnv"
return self.env.dirs.real_store_dir
def physical_store_path_for(self, path: str | Path) -> Path:
"""
+11 -6
View File
@@ -21,7 +21,7 @@ def test_env_inits_defaults(tmp_path: Path):
assert env.dirs.test_root == tmp_path
assert env.dirs.home == tmp_path / "test-home"
assert env.dirs.nix_store_dir == tmp_path / "nix/store"
assert env.dirs.real_store_dir == tmp_path / "nix/store"
def test_env_unknown_none(env: ManagedEnv):
@@ -94,11 +94,16 @@ def test_env_get_dir_works(env: ManagedEnv):
def test_env_dirs_created(env: ManagedEnv):
fields = dataclasses.asdict(env.dirs).values()
fields = dataclasses.asdict(env.dirs).items()
assert len(fields) > 1
for field in fields:
field: Path
assert field.exists()
for name, field in fields:
field: Path | None
# we never want to set NIX_STORE_DIR on linux due to unfortunate config ordering.
# creating a fresh env should always have it unset, it'll only be set when needed
if name == "nix_store_dir":
assert field is None
else:
field.exists()
def test_env_get_path_fails(env: ManagedEnv):
@@ -123,7 +128,7 @@ def test_env_to_env(tmp_path: Path):
"NIX_STATE_DIR",
"NIX_CONF_DIR",
"NIX_BIN_DIR",
"NIX_STORE_DIR",
"REAL_STORE_DIR",
"CACHE_DIR",
"XDG_CACHE_HOME",
"PATH",