test: derive nix helper build attr from flake

This commit is contained in:
copilot-swe-agent[bot]
2026-07-16 20:37:48 +00:00
committed by GitHub
parent 38f49e9161
commit ec4c1c851b
+15 -2
View File
@@ -16,12 +16,23 @@ Verifies that the sovran-hosts-update helper:
- does NOT rely on environment.systemPackages for the helper's dependencies. - does NOT rely on environment.systemPackages for the helper's dependencies.
""" """
import re
import shutil import shutil
import subprocess import subprocess
import unittest import unittest
from pathlib import Path from pathlib import Path
NIX_STRING_INDENT = 6
REPO_ROOT = Path(__file__).resolve().parents[2] 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 = ( NIX_FILE = (
REPO_ROOT REPO_ROOT
/ "modules" / "modules"
@@ -38,7 +49,9 @@ class LocalDomainLoopbackNixStructureTests(unittest.TestCase):
start = self.source.index("text = ''") + len("text = ''") start = self.source.index("text = ''") + len("text = ''")
end = self.source.index(" '';", start) end = self.source.index(" '';", start)
return "\n".join( 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() for line in self.source[start:end].splitlines()
).lstrip("\n") ).lstrip("\n")
@@ -158,7 +171,7 @@ class LocalDomainLoopbackNixStructureTests(unittest.TestCase):
[ [
nix, nix,
"build", "build",
'.#nixosConfigurations.nixos.config.environment.etc."sovran-hosts-update.sh".source', HELPER_BUILD_ATTR,
"--no-link", "--no-link",
], ],
cwd=REPO_ROOT, cwd=REPO_ROOT,