From 0bcaffa640e9fe5adc4dc57c20b8f88289ccc35f Mon Sep 17 00:00:00 2001 From: "Commentator2.0" Date: Fri, 5 Dec 2025 12:15:57 +0100 Subject: [PATCH] functional2: add a `hash_path` shortcut to Nix Co-authored-by: Qyriad Change-Id: If0b9213d264b60e687ceb2d4d232d23f6a6a6964 --- tests/functional2/testlib/fixtures/nix.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/functional2/testlib/fixtures/nix.py b/tests/functional2/testlib/fixtures/nix.py index 3158af6b3..e9285223d 100644 --- a/tests/functional2/testlib/fixtures/nix.py +++ b/tests/functional2/testlib/fixtures/nix.py @@ -188,6 +188,17 @@ class Nix: """ return Path(str(path).replace("/nix/store", self.store_dir.as_posix())) + def hash_path(self, store_path: str | Path, *args: str) -> str: + """ + Shortcut to use `nix hash path {store_path}`, converting "virtual" store paths returned + from Nix to their physical system paths including the test root. + + :param store_path: store path of the derivation or entry to hash + """ + actual_path = self.physical_store_path_for(store_path).as_posix() + res = self.nix(["hash", "path", actual_path, *args], flake=True).run().ok() + return res.stdout_plain + @pytest.fixture def nix(tmp_path: Path, env: ManagedEnv) -> Generator[Nix, Any, None]: