nixos-rebuild-ng: make nixosVersion key NotRequired

This commit is contained in:
Thiago Kenji Okada
2026-09-28 09:43:06 +01:00
parent b19cbd07b1
commit 896eba9b0d
2 changed files with 4 additions and 7 deletions

View File

@@ -171,12 +171,10 @@ class FlakeMetadataJson(TypedDict):
class NixOSVersionJson(TypedDict):
nixosVersion: str
# Those keys are only set in nixos-version when it exists
# Keys are NotRequired here so we need to parse them safely
nixosVersion: NotRequired[str]
configurationRevision: NotRequired[str]
kernelVersion: NotRequired[str]
# The reason this key are NotRequired even when they're always set in
# nixos-version is because older generations may not have them yet
specialisations: NotRequired[list[str]]

View File

@@ -511,7 +511,7 @@ def list_generations(profile: Profile) -> list[GenerationJson]:
profile.path.parent / f"{profile.path.name}-{generation.id}-link"
)
j: NixOSVersionJson
j: NixOSVersionJson = {}
try:
result = run_wrapper(
[generation_path / "sw/bin/nixos-version", "--json"],
@@ -520,12 +520,11 @@ def list_generations(profile: Profile) -> list[GenerationJson]:
j = json.loads(result)
except (OSError, CalledProcessError) as ex:
logger.debug("could not get configuration revision: %s", ex)
j = {"nixosVersion": "Unknown"}
return GenerationJson(
generation=generation.id,
date=generation.timestamp,
nixosVersion=j["nixosVersion"],
nixosVersion=j.get("nixosVersion", "Unknown"),
kernelVersion=j.get("kernelVersion", "Unknown"),
configurationRevision=j.get("configurationRevision", "Unknown"),
specialisations=j.get("specialisations", []),