diff --git a/tools/release-host-test.py b/tools/release-host-test.py index 6fb8dce85ddea0ca18cfe7e9558a19c469f16006..76b33462ff1de2d6abd38c94c32a98200c9fb72c 100644 --- a/tools/release-host-test.py +++ b/tools/release-host-test.py @@ -42,6 +42,45 @@ class HostConfiguration(unittest.TestCase): class ActivationEnvironment(unittest.TestCase): + def test_flake_paths_are_resolved_again_after_the_release_store_moves(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary).resolve() + previous = root / release.transition.PREVIOUS + canonical = root / "snowglobe" + source = previous / "releases" / ("a" * 16) + (source / "tools").mkdir(parents=True) + (source / "tools/snowglobe.py").touch() + (source / ".snowglobe-release.json").write_text('{"version":1}') + canonical.symlink_to(previous, target_is_directory=True) + logical_source = canonical / "releases" / source.name + observed = [] + + def activate(path): + self.assertEqual(path, logical_source) + canonical.unlink() + previous.rename(canonical) + previous.symlink_to(canonical, target_is_directory=True) + + def run(argv, **kwargs): + if argv[0] in {"nix", "nixos-rebuild"}: + observed.append(argv) + output = '["snowglobe"]' if argv[0] == "nix" else '"leader"' + return subprocess.CompletedProcess(argv, 0, output) + + with patch.dict(os.environ), patch.object(release, "ROOT", canonical), patch.object(release, "STATE", root), patch.object( + release, "check_release", return_value=logical_source, + ), patch.object(release, "current_release", return_value=None), patch.object( + release, "host_digest", return_value="new", + ), patch.object(release, "jobs", return_value=set()), patch.object( + release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"), + ), patch.object(release.subprocess, "run", side_effect=run), patch.object( + release.transition, "activate", side_effect=activate, + ): + release.activate(source.name, initial=True) + self.assertIn(f"path:{source}#nixosConfigurations", observed[0]) + self.assertEqual(observed[1], ["nixos-rebuild", "dry-build", "--flake", f"path:{source}#snowglobe"]) + self.assertEqual(observed[2], ["nixos-rebuild", "switch", "--flake", f"path:{logical_source}#snowglobe"]) + def test_host_switch_refreshes_inherited_name_and_preserves_overrides(self): for before, after, inherited, expected in ( (PREVIOUS_HOST, "snowglobe", PREVIOUS_HOST, "snowglobe"), diff --git a/tools/release.py b/tools/release.py index 48af1a16674bf05a5f45d63492db85d83ff39a41..222d528253f0a7837a2b24183e356640f8cb2fbb 100644 --- a/tools/release.py +++ b/tools/release.py @@ -139,7 +139,7 @@ def jobs(path): def host_configuration(path): hostname = os.uname().nodename.split(".", 1)[0] available = json.loads(subprocess.run( - ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path}#nixosConfigurations", "--apply", "builtins.attrNames"], + ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path.resolve()}#nixosConfigurations", "--apply", "builtins.attrNames"], check=True, capture_output=True, text=True, ).stdout) return transition.host_configuration(hostname, available) @@ -161,7 +161,7 @@ def activate(release, legacy=False, initial=False): old_digest = recorded.read_text().strip() if recorded.exists() else None if old_digest != digest: configuration = host_configuration(path) - subprocess.run(["nixos-rebuild", "dry-build", "--flake", f"path:{path}#{configuration}"], check=True) + subprocess.run(["nixos-rebuild", "dry-build", "--flake", f"path:{path.resolve()}#{configuration}"], check=True) subprocess.run(["python3", str(script), "preflight"], check=True, env=environment) backup = None if current and not initial: @@ -179,7 +179,7 @@ def activate(release, legacy=False, initial=False): (ROOT / "current").symlink_to(path) hostname = os.uname().nodename.split(".", 1)[0] transition.activate(path) - subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path}#{configuration}"], check=True) + subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path.resolve()}#{configuration}"], check=True) if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname: os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0] environment = transition.environment(path)