From ec4c1c851be8cf8b1d7461530515ea1cae256889 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Jul 2026 20:37:48 +0000 Subject: [PATCH] test: derive nix helper build attr from flake --- app/tests/test_local_domain_loopback_nix.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/tests/test_local_domain_loopback_nix.py b/app/tests/test_local_domain_loopback_nix.py index fe79872..3b13958 100644 --- a/app/tests/test_local_domain_loopback_nix.py +++ b/app/tests/test_local_domain_loopback_nix.py @@ -16,12 +16,23 @@ Verifies that the sovran-hosts-update helper: - does NOT rely on environment.systemPackages for the helper's dependencies. """ +import re import shutil import subprocess import unittest from pathlib import Path +NIX_STRING_INDENT = 6 REPO_ROOT = Path(__file__).resolve().parents[2] +FLAKE_SOURCE = (REPO_ROOT / "flake.nix").read_text() +PRIMARY_NIXOS_CONFIGURATION = re.search( + r"nixosConfigurations\.([A-Za-z0-9_-]+)\s*=", + FLAKE_SOURCE, +).group(1) +HELPER_BUILD_ATTR = ( + f'.#nixosConfigurations.{PRIMARY_NIXOS_CONFIGURATION}.config.environment.etc.' + '"sovran-hosts-update.sh".source' +) NIX_FILE = ( REPO_ROOT / "modules" @@ -38,7 +49,9 @@ class LocalDomainLoopbackNixStructureTests(unittest.TestCase): start = self.source.index("text = ''") + len("text = ''") end = self.source.index(" '';", start) return "\n".join( - line[6:] if line.startswith(" ") else line + line[NIX_STRING_INDENT:] + if line.startswith(" " * NIX_STRING_INDENT) + else line for line in self.source[start:end].splitlines() ).lstrip("\n") @@ -158,7 +171,7 @@ class LocalDomainLoopbackNixStructureTests(unittest.TestCase): [ nix, "build", - '.#nixosConfigurations.nixos.config.environment.etc."sovran-hosts-update.sh".source', + HELPER_BUILD_ATTR, "--no-link", ], cwd=REPO_ROOT,