diff --git a/tests/functional2/testlib/fixtures/env.py b/tests/functional2/testlib/fixtures/env.py index 55740e53c..a8d8b2d66 100644 --- a/tests/functional2/testlib/fixtures/env.py +++ b/tests/functional2/testlib/fixtures/env.py @@ -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"), diff --git a/tests/functional2/testlib/fixtures/nix.py b/tests/functional2/testlib/fixtures/nix.py index 4bc8fad04..dd2c1f111 100644 --- a/tests/functional2/testlib/fixtures/nix.py +++ b/tests/functional2/testlib/fixtures/nix.py @@ -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: """ diff --git a/tests/functional2/testlib/fixtures/test_env.py b/tests/functional2/testlib/fixtures/test_env.py index 0775bdabc..192afb1a2 100644 --- a/tests/functional2/testlib/fixtures/test_env.py +++ b/tests/functional2/testlib/fixtures/test_env.py @@ -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",