authoravatarclover caruso<git@paperclover.net>2026-10-16 23:06:07-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-21 02:52:29-07:00
log16755e176f00faeed64d1cf82053129722dd69f7
treebab53d432fc41fa86fce1496a300399fefdcdb3b
parent0786e0d038ecc3beecd8b582a082e679bd86f88b
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Resolve release flake paths across namespace activation

Assisted-by: gpt-6.1-sol

2 files changed, 42 insertions(+), 3 deletions(-)

tools/release-host-test.py+39
...@@ -42,6 +42,45 @@ class HostConfiguration(unittest.TestCase):...@@ -42,6 +42,45 @@ class HostConfiguration(unittest.TestCase):
4242
4343
44class ActivationEnvironment(unittest.TestCase):44class ActivationEnvironment(unittest.TestCase):
45 def test_flake_paths_are_resolved_again_after_the_release_store_moves(self):
46 with tempfile.TemporaryDirectory() as temporary:
47 root = Path(temporary).resolve()
48 previous = root / release.transition.PREVIOUS
49 canonical = root / "snowglobe"
50 source = previous / "releases" / ("a" * 16)
51 (source / "tools").mkdir(parents=True)
52 (source / "tools/snowglobe.py").touch()
53 (source / ".snowglobe-release.json").write_text('{"version":1}')
54 canonical.symlink_to(previous, target_is_directory=True)
55 logical_source = canonical / "releases" / source.name
56 observed = []
57
58 def activate(path):
59 self.assertEqual(path, logical_source)
60 canonical.unlink()
61 previous.rename(canonical)
62 previous.symlink_to(canonical, target_is_directory=True)
63
64 def run(argv, **kwargs):
65 if argv[0] in {"nix", "nixos-rebuild"}:
66 observed.append(argv)
67 output = '["snowglobe"]' if argv[0] == "nix" else '"leader"'
68 return subprocess.CompletedProcess(argv, 0, output)
69
70 with patch.dict(os.environ), patch.object(release, "ROOT", canonical), patch.object(release, "STATE", root), patch.object(
71 release, "check_release", return_value=logical_source,
72 ), patch.object(release, "current_release", return_value=None), patch.object(
73 release, "host_digest", return_value="new",
74 ), patch.object(release, "jobs", return_value=set()), patch.object(
75 release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"),
76 ), patch.object(release.subprocess, "run", side_effect=run), patch.object(
77 release.transition, "activate", side_effect=activate,
78 ):
79 release.activate(source.name, initial=True)
80 self.assertIn(f"path:{source}#nixosConfigurations", observed[0])
81 self.assertEqual(observed[1], ["nixos-rebuild", "dry-build", "--flake", f"path:{source}#snowglobe"])
82 self.assertEqual(observed[2], ["nixos-rebuild", "switch", "--flake", f"path:{logical_source}#snowglobe"])
83
45 def test_host_switch_refreshes_inherited_name_and_preserves_overrides(self):84 def test_host_switch_refreshes_inherited_name_and_preserves_overrides(self):
46 for before, after, inherited, expected in (85 for before, after, inherited, expected in (
47 (PREVIOUS_HOST, "snowglobe", PREVIOUS_HOST, "snowglobe"),86 (PREVIOUS_HOST, "snowglobe", PREVIOUS_HOST, "snowglobe"),
tools/release.py+3-3
...@@ -139,7 +139,7 @@ def jobs(path):...@@ -139,7 +139,7 @@ def jobs(path):
139def host_configuration(path):139def host_configuration(path):
140 hostname = os.uname().nodename.split(".", 1)[0]140 hostname = os.uname().nodename.split(".", 1)[0]
141 available = json.loads(subprocess.run(141 available = json.loads(subprocess.run(
142 ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path}#nixosConfigurations", "--apply", "builtins.attrNames"],142 ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path.resolve()}#nixosConfigurations", "--apply", "builtins.attrNames"],
143 check=True, capture_output=True, text=True,143 check=True, capture_output=True, text=True,
144 ).stdout)144 ).stdout)
145 return transition.host_configuration(hostname, available)145 return transition.host_configuration(hostname, available)
...@@ -161,7 +161,7 @@ def activate(release, legacy=False, initial=False):...@@ -161,7 +161,7 @@ def activate(release, legacy=False, initial=False):
161 old_digest = recorded.read_text().strip() if recorded.exists() else None161 old_digest = recorded.read_text().strip() if recorded.exists() else None
162 if old_digest != digest:162 if old_digest != digest:
163 configuration = host_configuration(path)163 configuration = host_configuration(path)
164 subprocess.run(["nixos-rebuild", "dry-build", "--flake", f"path:{path}#{configuration}"], check=True)164 subprocess.run(["nixos-rebuild", "dry-build", "--flake", f"path:{path.resolve()}#{configuration}"], check=True)
165 subprocess.run(["python3", str(script), "preflight"], check=True, env=environment)165 subprocess.run(["python3", str(script), "preflight"], check=True, env=environment)
166 backup = None166 backup = None
167 if current and not initial:167 if current and not initial:
...@@ -179,7 +179,7 @@ def activate(release, legacy=False, initial=False):...@@ -179,7 +179,7 @@ def activate(release, legacy=False, initial=False):
179 (ROOT / "current").symlink_to(path)179 (ROOT / "current").symlink_to(path)
180 hostname = os.uname().nodename.split(".", 1)[0]180 hostname = os.uname().nodename.split(".", 1)[0]
181 transition.activate(path)181 transition.activate(path)
182 subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path}#{configuration}"], check=True)182 subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path.resolve()}#{configuration}"], check=True)
183 if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname:183 if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname:
184 os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0]184 os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0]
185 environment = transition.environment(path)185 environment = transition.environment(path)