test: derive nix helper build attr from flake
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user