mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-09-29 19:30:11 +00:00
nixos-rebuild-ng: make nixosVersion key NotRequired
This commit is contained in:
@@ -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]]
|
||||
|
||||
|
||||
|
||||
@@ -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", []),
|
||||
|
||||
Reference in New Issue
Block a user